Skip to content

Instantly share code, notes, and snippets.

@mickm
Created February 24, 2012 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mickm/1901631 to your computer and use it in GitHub Desktop.
Save mickm/1901631 to your computer and use it in GitHub Desktop.
Pull top site search terms and top search engine terms from GA
#!/usr/bin/env ruby
GA_USER = 'foo@example.com'
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