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

Returns a new instance of GoogleAnalyticsAdapter.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 72

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] || ''
  @campaign =  ac[:campaign] || ''
  @source = ac[:source] || ''
  @medium = ac[:medium] || ''
  @term = ac[:term] || ''
  @content = ac[:content] || ''
  @language_encoding = ac[:language_encoding] || 'UTF-8'
  @java_enabled = ac[:java_enabled] || '1'
  @screen_color_depth = ac[:screen_color_depth] || '0-bit'
  @screen_resolution = ac[:screen_resolution] || '0x0'
  @browser_language = ac[:browser_language] || 'en-us'
  @tracking_code_version = ac[:tracking_code_version] || '4.4sj'
  @new_campaign_session = ac[:new_campaign_session] || '1'
  @repeat_campaign_visit = ac[:repeat_campaign_visit] || '1'
  @cookie_values = ac[:cookie_values] || '__utma%3D999.999.999.999.999.1%3B'
end

Instance Attribute Details

#analytics_idObject

Returns the value of attribute analytics_id.



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

def analytics_id
  @analytics_id
end

#browser_languageObject

Returns the value of attribute browser_language.



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

def browser_language
  @browser_language
end

#campaignObject

Returns the value of attribute campaign.



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

def campaign
  @campaign
end

#contentObject

Returns the value of attribute content.



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

def content
  @content
end

Returns the value of attribute cookie_values.



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

def cookie_values
  @cookie_values
end

#domainObject

Returns the value of attribute domain.



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

def domain
  @domain
end

#envObject

Returns the value of attribute env.



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

def env
  @env
end

#http_accept_languageObject

Returns the value of attribute http_accept_language.



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

def http_accept_language
  @http_accept_language
end

#java_enabledObject

Returns the value of attribute java_enabled.



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

def java_enabled
  @java_enabled
end

#language_encodingObject

Returns the value of attribute language_encoding.



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

def language_encoding
  @language_encoding
end

#mediumObject

Returns the value of attribute medium.



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

def medium
  @medium
end

#new_campaign_sessionObject

Returns the value of attribute new_campaign_session.



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

def new_campaign_session
  @new_campaign_session
end

#noopObject

Returns the value of attribute noop.



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

def noop
  @noop
end

#page_titleObject

Returns the value of attribute page_title.



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

def page_title
  @page_title
end

#referrerObject

Returns the value of attribute referrer.



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

def referrer
  @referrer
end

#remote_addressObject

Returns the value of attribute remote_address.



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

def remote_address
  @remote_address
end

#repeat_campaign_visitObject

Returns the value of attribute repeat_campaign_visit.



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

def repeat_campaign_visit
  @repeat_campaign_visit
end

#screen_color_depthObject

Returns the value of attribute screen_color_depth.



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

def screen_color_depth
  @screen_color_depth
end

#screen_resolutionObject

Returns the value of attribute screen_resolution.



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

def screen_resolution
  @screen_resolution
end

#sourceObject

Returns the value of attribute source.



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

def source
  @source
end

#termObject

Returns the value of attribute term.



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

def term
  @term
end

#tracking_code_versionObject

Returns the value of attribute tracking_code_version.



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

def tracking_code_version
  @tracking_code_version
end

#user_agentObject

Returns the value of attribute user_agent.



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

def user_agent
  @user_agent
end

Instance Method Details

#track_page_view(path) ⇒ Object

send a request to get the image from google



231
232
233
234
235
236
237
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 231

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

#urchin_url(ssl = false) ⇒ Object



102
103
104
105
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 102

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

#utm_campaignObject



209
210
211
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 209

def utm_campaign
  self.campaign
end

#utm_contentObject



226
227
228
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 226

def utm_content
  self.content
end

#utm_mediumObject



218
219
220
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 218

def utm_medium
  self.medium
end

#utm_sourceObject



213
214
215
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 213

def utm_source
  self.source
end

#utm_termObject



222
223
224
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 222

def utm_term
  self.term
end

#utmacObject

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



108
109
110
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 108

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


201
202
203
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 201

def utmcc
  self.cookie_values
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


187
188
189
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 187

def utmcn
  self.new_campaign_session
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


194
195
196
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 194

def utmcr
  self.repeat_campaign_visit
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


121
122
123
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 121

def utmcs
  self.language_encoding
end

#utmdtObject



205
206
207
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 205

def utmdt
  self.page_title
end

#utmhnObject

utmhn

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


114
115
116
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 114

def utmhn
  self.domain
end

#utmipObject

utmip Remote IP address



175
176
177
178
179
180
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 175

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
  self.remote_address.to_s.gsub(/([^.]+\.[^.]+\.[^.]+\.)[^.]+/,"\\1") + "0"
end

#utmjeObject

utmje

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


127
128
129
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 127

def utmje
  self.java_enabled
end

#utmnObject

utmn

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


133
134
135
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 133

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


169
170
171
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 169

def utmr
  self.referrer
end

#utmscObject

utmsc

Screen color depth  utmsc=24-bit


139
140
141
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 139

def utmsc
  self.screen_color_depth
end

#utmsrObject

utmsr

Screen resolution   utmsr=2400x1920&


145
146
147
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 145

def utmsr
  self.screen_resolution
end

#utmulObject

utmul

Browser language.   utmul=pt-br


151
152
153
# File 'lib/analytics_goo/google_analytics_adapter.rb', line 151

def utmul
  self.browser_language
end

#utmwvObject

utmwv

Tracking code version   utmwv=1


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

def utmwv
  self.tracking_code_version
end