Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated gemspec

  • Loading branch information...
commit 0237b08d70cb02adb43f47f3e490764fbe7de811 1 parent b2e92f8
Maik Vlcek authored
Showing with 32 additions and 26 deletions.
  1. +1 −0  .gitignore
  2. +1 −1  ga_tracker.gemspec
  3. +30 −25 lib/ga_tracker.rb
View
1  .gitignore
@@ -1 +1,2 @@
.idea/
+*.gem
View
2  ga_tracker.gemspec
@@ -6,6 +6,6 @@ Gem::Specification.new do |s|
s.description = "Allows you to do server-side tracking for Google Analytics either using the given class or as a controller mix-in."
s.authors = ["Maik Vlcek"]
s.email = 'maik@mediavrog.net'
- s.files = ["lib/ga_tracker.rb"]
+ s.files = ['lib/ga_tracker.rb', 'lib/ga_tracker/utme.rb']
s.homepage = 'https://github.com/mediavrog/ga_tracker'
end
View
55 lib/ga_tracker.rb
@@ -2,44 +2,45 @@
require 'digest'
require 'open-uri'
-require 'ga_tracker/utme'
-
class GATracker
- attr_accessor :request, :params
+ attr_accessor :params, :request, :visitor_id
def initialize(request, params, use_ssl=false)
- @request = request.dup
- @params = params.dup
- @utm_location = (use_ssl ? 'https://ssl' : 'http://www') + UTM_GIF_LOCATION
+ self.request = request.dup
+ self.params = params.dup
+ self.utm_location = (use_ssl ? 'https://ssl' : 'http://www') + UTM_GIF_LOCATION
+ self.utm_params = utm_query_params
end
def set_custom_var(index, name, value, scope=nil)
# update a custom var parameter
+ utm_params[:utme].set_custom_variable(index, name, value, scope)
end
def track_event(category, action, label=nil, value=nil)
- @utm_params = utm_query_params
-
- # add/modify event parameter
-
+ # update a custom var parameter
+ utm_params[:utme].set_event(category, action, label, value)
# make google request
- request_google @utm_params
+ request_google utm_params
end
def track_page_view(path=nil)
- @utm_params = utm_query_params
-
- request_google @utm_params
+ request_google utm_params
end
protected
+ attr_accessor :utm_location, :utm_params
+
# Generate a visitor id for this hit.
# If there is a visitor id in the cookie, use that, otherwise
# use the guid if we have one, otherwise use a random number.
def get_visitor_id(guid, account, user_agent, cookie)
+ # if there was a visitor id set manually, use it
+ return visitor_id unless (visitor_id.nil? || visitor_id.empty?)
+
# If there is a value in the cookie, don't change it.
return cookie unless (cookie.nil? || cookie.empty?)
@@ -60,14 +61,15 @@ def get_visitor_id(guid, account, user_agent, cookie)
private
- # Tracker version.
- VERSION = "4.4sh"
+ # seems to be the current version
+ # just search for 'utmwv' in http://www.google-analytics.com/ga.js
+ VERSION = "5.1.5"
COOKIE_NAME = "__utmmobile"
COOKIE_PATH = "/"
# Two years in seconds.
COOKIE_PERSISTENCE = 63072000
- UTM_GIF_LOCATION = "google-analytics.com/__utm.gif"
+ UTM_GIF_LOCATION = ".google-analytics.com/__utm.gif"
# The last octect of the IP address is removed to anonymize the user.
def get_ip(remote_address)
@@ -79,7 +81,7 @@ def get_ip(remote_address)
end
def utm_query_params
- timestamp = Time.now.utc.strftime("%H%M%S").to_i
+ #timestamp = Time.now.utc.strftime("%H%M%S").to_i
domain_name = (request.env["SERVER_NAME"].nil? || request.env["SERVER_NAME"].blank?) ? "" : request.env["SERVER_NAME"]
@@ -98,18 +100,19 @@ def utm_query_params
user_agent = (request.env["HTTP_USER_AGENT"].nil? || request.env["HTTP_USER_AGENT"].empty?) ? "" : request.env["HTTP_USER_AGENT"]
# Try and get visitor cookie from the request.
- cookie = cookies[COOKIE_NAME]
+ cookie = nil #cookies[COOKIE_NAME]
visitor_id = get_visitor_id(request.env["HTTP_X_DCMGUID"], account, user_agent, cookie)
# Always try and add the cookie to the response.
- request.cookies[COOKIE_NAME] = { :value => visitor_id, :expires => COOKIE_PERSISTENCE.to_i + timestamp, :path => COOKIE_PATH }
+ #request.cookies[COOKIE_NAME] = { :value => visitor_id, :expires => COOKIE_PERSISTENCE.to_i + timestamp, :path => COOKIE_PATH }
# Construct the gif hit url params
{
:utmwv => VERSION,
:utmn => rand(0x7fffffff).to_s,
:utmhn => CGI.escape(domain_name),
+ :utme => UTME.new,
:utmr => CGI.escape(document_referer),
:utmp => CGI.escape(document_path),
:utmac => account,
@@ -126,10 +129,12 @@ def utm_query_params
def request_google(params)
utm_url = @utm_location + "?" + params.to_query
- #puts "--------sending request to GA-----------------------"
- #puts utmurl
- open(utm_url, "User-Agent" => request.env["HTTP_USER_AGENT"],
- "Header" => ("Accepts-Language: " + request.env["HTTP_ACCEPT_LANGUAGE"]))
+ puts "--------sending request to GA-----------------------"
+ puts utm_url
+ #open(utm_url, "User-Agent" => request.env["HTTP_USER_AGENT"],
+ # "Header" => ("Accepts-Language: " + request.env["HTTP_ACCEPT_LANGUAGE"]))
end
-end
+end
+
+require 'ga_tracker/utme'
Please sign in to comment.
Something went wrong with that request. Please try again.