Created
February 24, 2012 15:27
-
-
Save mickm/1901631 to your computer and use it in GitHub Desktop.
Pull top site search terms and top search engine terms from GA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
GA_USER = '[email protected]' | |
GA_PASS = 'secrets!' | |
GA_PROPERTY = 'UA-8411317-51' | |
require 'rubygems' | |
require 'garb' | |
class SiteSearchTerms | |
extend Garb::Model | |
metrics :search_uniques | |
dimensions :search_keyword | |
end | |
class SearchEngineSearchTerms | |
extend Garb::Model | |
metrics :visits | |
dimensions :keyword | |
end | |
Garb::Session.login(GA_USER, GA_PASS) | |
profile = Garb::Management::Profile.all.detect do |profile| | |
profile.web_property_id == GA_PROPERTY | |
end | |
puts "Site search box top 10" | |
puts | |
results = profile.site_search_terms(sort: :search_uniques.desc, limit: 10) | |
results.each do |result| | |
puts "#{result.search_uniques} #{result.search_keyword}" | |
end | |
puts | |
puts "Search engine search box top 10" | |
puts | |
# Search engine search box | |
results = profile.search_engine_search_terms(sort: :visits.desc, limit: 10) | |
results.each do |result| | |
puts "#{result.visits} #{result.keyword}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment