Class: Semrush::Analytics
Overview
Analytics Class
Most of these methods take a hash parameter that may contain the following keys : There is no db filter for analytics api but you can use :display_filter to filter the results,
example: :display_filter => "+|country||us" will only return results from the US.
See developer.semrush.com/api/v3/analytics/basic-docs/
-
:api_key (ex: :api_key => ‘gt97s6d4a6w’)
-
:limit (ex: :limit => 2000)
-
:offset (ex: :offset => 5)
-
:export_columns (ex: :export_columns => “Dn,Rk”)
Constant Summary collapse
- ANALYTIC_TYPES =
[:backlinks_refdomains]
- REQUEST_TYPES =
[:root_domain, :domain, :url]
Class Method Summary collapse
-
.backlinks_comparison(targets, target_types, params = {}) ⇒ Object
Compare your and your competitors’ backlink profiles and link-building progress.
-
.backlinks_refdomains(domain, params = {}) ⇒ Object
Get lists domains pointing to the queried domain, root domain, or URL.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Analytics
constructor
A new instance of Analytics.
Methods inherited from Base
Constructor Details
#initialize(params = {}) ⇒ Analytics
Returns a new instance of Analytics.
15 16 17 18 19 |
# File 'lib/semrush/analytics.rb', line 15 def initialize params = {} @parameters = params @target_types = REQUEST_TYPES @api_report_url = API_ANALYTICS_URL end |
Class Method Details
.backlinks_comparison(targets, target_types, params = {}) ⇒ Object
Compare your and your competitors’ backlink profiles and link-building progress.
-
:api_key (ex: :api_key => ‘gt97s6d4a6w’)
-
:targets (ex: :targets => [“domain1.com”, “domain2.com”]) Array of domains to compare
-
:target_types (ex: :target_type => [“root_domain”, “root_domain”]) Array to match with corresponding targets index
-
:export_columns (ex: :export_columns => “”), available columns: “target,target_type,ascore,backlinks_num,domains_num,ips_num,follows_num,nofollows_num,texts_num,images_num,forms_num,frames_num”
-
Return array of data
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/semrush/analytics.rb', line 47 def self.backlinks_comparison(targets, target_types, params = {}) target_types.each do |target_type| raise Exception::BadArgument.new(self, "One of `target_types` is not valid: #{target_type}") unless REQUEST_TYPES.include?(target_type.to_sym) end raise Exception::BadArgument.new(self, "`targets` and `target_types` must be the same size") unless targets.size == target_types.size export_columns = params.delete(:export_columns).presence || "target,target_type,ascore,backlinks_num,domains_num,ips_num,follows_num,nofollows_num,texts_num,images_num,forms_num,frames_num" # Have to add target and target_type to params to cleaup API_ANALYTICS_URL (in #request v.blank? check) self.new(params.merge(:report_type => :backlinks_comparison, :targets => targets, :target_types => target_types, :export_columns => export_columns, )) .request end |
.backlinks_refdomains(domain, params = {}) ⇒ Object
Get lists domains pointing to the queried domain, root domain, or URL.
-
:api_key (ex: :api_key => ‘gt97s6d4a6w’)
-
:limit (ex: :limit => “”)
-
:offset (ex: :offset => “”)
-
:target_type (ex: :target_type => “”) One of ‘REQUEST_TYPES`
-
:export_columns (ex: :export_columns => “”)
-
:display_filter one or many of “zone, country, ip, newdomain, lostdomain, category”
See: developer.semrush.com/api/v3/analytics/backlinks/#reffering_domains
29 30 31 32 33 34 35 36 |
# File 'lib/semrush/analytics.rb', line 29 def self.backlinks_refdomains(domain, params = {}) export_columns = params.delete(:export_columns).presence || "domain_ascore,domain,backlinks_num,ip,country,first_seen,last_seen" self.new(params.merge(:report_type => :backlinks_refdomains, :target => domain, :export_columns => export_columns)) .request end |