Class: AnalyticsGoo::GoogleAnalyticsAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/analytics_goo/google_analytics_adapter.rb

Constant Summary collapse

GA_DOMAIN =
"www.google-analytics.com"
GA_IMAGE =
"__utm.gif"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ac) ⇒ GoogleAnalyticsAdapter

utmdt

Page title, which is a URL-encoded string.  utmdt=analytics%20page%20test


47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 47

def initialize(ac)
  # sets the environment that this should be run in
  @analytics_id = ac[:analytics_id]
  @domain = ac[:domain]
  @env = ac[:environment]
  @noop = ac[:noop] || false
  @page_title  = ac[:page_title] || ""
  @referrer = ac[:referrer] || "-"
  @remote_address = ac[:remote_address]
  @user_agent = ac[:user_agent] || ""
  @http_accept_language = ac[:http_accept_language] || ""
end

Instance Attribute Details

#analytics_idObject

Returns the value of attribute analytics_id.



43
44
45
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 43

def analytics_id
  @analytics_id
end

#domainObject

Returns the value of attribute domain.



43
44
45
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 43

def domain
  @domain
end

#envObject

Returns the value of attribute env.



43
44
45
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 43

def env
  @env
end

#http_accept_languageObject

Returns the value of attribute http_accept_language.



43
44
45
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 43

def http_accept_language
  @http_accept_language
end

#noopObject

Returns the value of attribute noop.



43
44
45
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 43

def noop
  @noop
end

#page_titleObject

Returns the value of attribute page_title.



43
44
45
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 43

def page_title
  @page_title
end

#referrerObject

Returns the value of attribute referrer.



43
44
45
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 43

def referrer
  @referrer
end

#remote_addressObject

Returns the value of attribute remote_address.



43
44
45
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 43

def remote_address
  @remote_address
end

#user_agentObject

Returns the value of attribute user_agent.



43
44
45
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 43

def user_agent
  @user_agent
end

Instance Method Details

#track_page_view(path) ⇒ Object

send a request to get the image from google



172
173
174
175
176
177
178
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 172

def track_page_view(path)
  res = ""
  unless @noop == true
    res = track_it(path)
  end
  res
end

#urchin_url(ssl = false) ⇒ Object



63
64
65
66
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 63

def urchin_url(ssl = false)
  protocol = (ssl == true) ? "https":"http"
  "#{protocol}://#{GA_DOMAIN}/#{GA_IMAGE}"
end

#utmacObject

utmac Account String. Appears on all requests. utmac=UA-2202604-2



69
70
71
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 69

def utmac
  self.analytics_id
end

#utmccObject

utmcc

Cookie values. This request parameter sends all the cookies requested from the page.
utmcc=__utma%3D117243.1695285.22%3B%2B __utmz%3D117945243.1202416366.21.10. utmcsr%3Db%7C utmccn%3D(referral)%7C utmcmd%3Dreferral%7C utmcct%3D%252Fissue%3B%2B


163
164
165
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 163

def utmcc
  "__utma%3D999.999.999.999.999.1%3B"
end

#utmcnObject

utmcn Starts a new campaign session. Either utmcn or utmcr is present on any given request. Changes the campaign tracking data; but does not start a new session

utmcn=1


149
150
151
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 149

def utmcn
  "1"
end

#utmcrObject

utmcr

Indicates a repeat campaign visit. This is set when any subsequent clicks occur on the same link. Either utmcn or utmcr is present on any given request.
utmcr=1


156
157
158
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 156

def utmcr
  "1"
end

#utmcsObject

utmcs

Language encoding for the browser. Some browsers don't set this, in which case it is set to "-"
utmcs=ISO-8859-1


82
83
84
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 82

def utmcs
  "UTF-8"
end

#utmdtObject



167
168
169
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 167

def utmdt
  self.page_title
end

#utmhnObject

utmhn

Host Name, which is a URL-encoded string.   utmhn=x343.gmodules.com


75
76
77
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 75

def utmhn
  self.domain
end

#utmipObject

utmip Remote IP address



136
137
138
139
140
141
142
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 136

def utmip
  return '' if self.remote_address.blank?
  # Capture the first three octects of the IP address and replace the forth
  # with 0, e.g. 124.455.3.123 becomes 124.455.3.0
  ip = self.remote_address.to_s.gsub!(/([^.]+\.[^.]+\.[^.]+\.)[^.]+/,"\\1") + "0"
  ip
end

#utmjeObject

utmje

Indicates if browser is Java-enabled. 1 is true.  utmje=1


88
89
90
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 88

def utmje
  "1"
end

#utmnObject

utmn

Unique ID generated for each GIF request to prevent caching of the GIF image.   utmn=1142651215


94
95
96
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 94

def utmn
  ActiveSupport::SecureRandom.random_number(9999999999).to_s
end

#utmrObject

utmr

Referral, complete URL.   utmr=http://www.example.com/aboutUs/index.php?var=selected


130
131
132
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 130

def utmr
  self.referrer
end

#utmscObject

utmsc

Screen color depth  utmsc=24-bit


100
101
102
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 100

def utmsc
  "0-bit"
end

#utmsrObject

utmsr

Screen resolution   utmsr=2400x1920&


106
107
108
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 106

def utmsr
  "0x0"
end

#utmulObject

utmul

Browser language.   utmul=pt-br


112
113
114
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 112

def utmul
  "en-us"
end

#utmwvObject

utmwv

Tracking code version   utmwv=1


118
119
120
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 118

def utmwv
  "4.4sj"
end