Skip to content
This repository

Set the @utma instance variable if gabba generates it #11

Merged
merged 1 commit into from about 2 years ago

2 participants

Jonathan Taylor Ron Evans
Jonathan Taylor

This way if gabba generates the utma value we can persist it in some way so that we don't get every page hit appearing to be a new visitor.

In my own code (using rails) I do the following.

  def update_google_analytics_page_hit
    if Rails.env.production? && request.get?
      gabba = Gabba::Gabba.new("MY-UA", "MY-DOMAIN")
      gabba.identify_user(cookies[:__utma]) 
      gabba.page_view("TITLE", request.fullpath)
      cookies['__utma'] ||= gabba.utma
    end  
  end
Ron Evans deadprogram merged commit acff152 into from
Ron Evans
Owner

Thanks for the patch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 20, 2012
Jonathan Taylor Set the utma instance variable so that we can pull it out later to pe…
…rsist it in the users cookie
bb75c81
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 3 additions and 4 deletions. Show diff stats Hide diff stats

  1. +3 4 lib/gabba/gabba.rb
7 lib/gabba/gabba.rb
@@ -22,7 +22,7 @@ class Gabba
22 22
23 23 ESCAPES = %w{ ' ! * ) }
24 24
25   - attr_accessor :utmwv, :utmn, :utmhn, :utmcs, :utmul, :utmdt, :utmp, :utmac, :utmt, :utmcc, :user_agent
  25 + attr_accessor :utmwv, :utmn, :utmhn, :utmcs, :utmul, :utmdt, :utmp, :utmac, :utmt, :utmcc, :user_agent, :utma
26 26
27 27 # Public: Initialize Gabba Google Analytics Tracking Object.
28 28 #
@@ -295,9 +295,8 @@ def identify_user(utma)
295 295
296 296 # create magical cookie params used by GA for its own nefarious purposes
297 297 def cookie_params(utma1 = random_id, utma2 = rand(1147483647) + 1000000000, today = Time.now)
298   - utma = @utma
299   - utma ||= "1.#{utma1}00145214523.#{utma2}.#{today.to_i}.#{today.to_i}.15"
300   - "__utma=#{utma};+__utmz=1.#{today.to_i}.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);"
  298 + @utma ||= "1.#{utma1}00145214523.#{utma2}.#{today.to_i}.#{today.to_i}.15"
  299 + "__utma=#{@utma};+__utmz=1.#{today.to_i}.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);"
301 300 end
302 301
303 302 # sanity check that we have needed params to even call GA

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.