google analytics snippets

Using Garb to get unique pageviews per page from Google Analytics

Tagged ruby, google analytics, garb  Languages ruby
require 'rubygems'
require 'garb'

CA_CERT_FILE = "cacert.pem"

username = ""
password = ""
profile = "UA-xxx"

Garb::Session.login(username, password, :secure => true)

class Report
  extend Garb::Resource

  metrics :unique_pageviews
  dimensions :page_path
  sort :unique_pageviews.desc
  
  filters do
    contains(:page_path, '/xxx')
  end
end

profile = Garb::Profile.first(profile)
options = {
  :start_date => (Date.today - 365*5),
  :end_date => Date.today
}
result = Report.results(profile, options)

result.each do |r|
  print "#{r.page_path} #{r.unique_pageviews}"
end

Problems with _gaq.push and _trackEvent?

Tagged google analytics, _gaq, _trackevent  Languages javascript

Problems with _gaq.push and _trackEvent?

  1. Check JavaScript/Firebug console for errors.
  2. Check that all values are in supported format, e.g. the value parameter must be an integer
  3. Use the queue to postpone or perform actions in sequence:
_gaq.push(['_trackEvent',...])
_gaq.push(function() {
      document.location = 'http://google.com'
})