Class: Gabbara::Gabba
- Inherits:
-
Object
- Object
- Gabbara::Gabba
- Defined in:
- lib/gabbara/gabba.rb
Constant Summary collapse
- GOOGLE_HOST =
"www.google-analytics.com"
- BEACON_PATH =
"/__utm.gif"
- USER_AGENT =
"Gabbara #{VERSION} Agent"
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
-
#utmac ⇒ Object
Returns the value of attribute utmac.
-
#utmcc ⇒ Object
Returns the value of attribute utmcc.
-
#utmcs ⇒ Object
Returns the value of attribute utmcs.
-
#utmhid ⇒ Object
Returns the value of attribute utmhid.
-
#utmhn ⇒ Object
Returns the value of attribute utmhn.
-
#utmip ⇒ Object
Returns the value of attribute utmip.
-
#utmn ⇒ Object
Returns the value of attribute utmn.
-
#utmp ⇒ Object
Returns the value of attribute utmp.
-
#utmr ⇒ Object
Returns the value of attribute utmr.
-
#utmul ⇒ Object
Returns the value of attribute utmul.
-
#utmwv ⇒ Object
Returns the value of attribute utmwv.
Instance Method Summary collapse
-
#event(*args) ⇒ Object
parameters: category, action, label = nil, value = nil, :utmvid => visitor_id.
-
#initialize(ga_acct, *args) ⇒ Gabba
constructor
create with: ga_acct, domain or ga_acct, :request => request.
-
#page_view(title, *args) ⇒ Object
parameters: title, page, :utmvid => visitor_id or title, :utmvid => visitor_id if page is obmitted, it is taken from the request.
- #request=(request) ⇒ Object
Constructor Details
#initialize(ga_acct, *args) ⇒ Gabba
create with:
ga_acct, domain
or
ga_acct, :request => request
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gabbara/gabba.rb', line 36 def initialize(ga_acct, *args) @utmwv = "4.4sh" # GA version @utmcs = "UTF-8" # charset @utmul = "en-us" # language @utmn = rand(8999999999) + 1000000000 @user_agent = Gabba::USER_AGENT @utmac = ga_acct opts = args. @utmhn = args.shift opts.each {|key, value| self.send("#{key}=", value) } end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
18 19 20 |
# File 'lib/gabbara/gabba.rb', line 18 def logger @logger end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
18 19 20 |
# File 'lib/gabbara/gabba.rb', line 18 def user_agent @user_agent end |
#utmac ⇒ Object
Returns the value of attribute utmac.
18 19 20 |
# File 'lib/gabbara/gabba.rb', line 18 def utmac @utmac end |
#utmcc ⇒ Object
Returns the value of attribute utmcc.
18 19 20 |
# File 'lib/gabbara/gabba.rb', line 18 def utmcc @utmcc end |
#utmcs ⇒ Object
Returns the value of attribute utmcs.
18 19 20 |
# File 'lib/gabbara/gabba.rb', line 18 def utmcs @utmcs end |
#utmhid ⇒ Object
Returns the value of attribute utmhid.
18 19 20 |
# File 'lib/gabbara/gabba.rb', line 18 def utmhid @utmhid end |
#utmhn ⇒ Object
Returns the value of attribute utmhn.
18 19 20 |
# File 'lib/gabbara/gabba.rb', line 18 def utmhn @utmhn end |
#utmip ⇒ Object
Returns the value of attribute utmip.
18 19 20 |
# File 'lib/gabbara/gabba.rb', line 18 def utmip @utmip end |
#utmn ⇒ Object
Returns the value of attribute utmn.
18 19 20 |
# File 'lib/gabbara/gabba.rb', line 18 def utmn @utmn end |
#utmp ⇒ Object
Returns the value of attribute utmp.
18 19 20 |
# File 'lib/gabbara/gabba.rb', line 18 def utmp @utmp end |
#utmr ⇒ Object
Returns the value of attribute utmr.
18 19 20 |
# File 'lib/gabbara/gabba.rb', line 18 def utmr @utmr end |
#utmul ⇒ Object
Returns the value of attribute utmul.
18 19 20 |
# File 'lib/gabbara/gabba.rb', line 18 def utmul @utmul end |
#utmwv ⇒ Object
Returns the value of attribute utmwv.
18 19 20 |
# File 'lib/gabbara/gabba.rb', line 18 def utmwv @utmwv end |
Instance Method Details
#event(*args) ⇒ Object
parameters:
category, action, label = nil, value = nil, :utmvid => visitor_id
73 74 75 76 77 78 79 |
# File 'lib/gabbara/gabba.rb', line 73 def event(*args) check_account_params opts = args. opts[:utmt] = 'event' opts[:utme] = event_data(*args) hey(opts) end |
#page_view(title, *args) ⇒ Object
parameters:
title, page, :utmvid => visitor_id
or
title, :utmvid => visitor_id
if page is obmitted, it is taken from the request
63 64 65 66 67 68 69 |
# File 'lib/gabbara/gabba.rb', line 63 def page_view(title, *args) check_account_params opts = args. opts[:utmdt] = title opts[:utmp] = args.shift || @utmp hey(opts) end |
#request=(request) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/gabbara/gabba.rb', line 49 def request=(request) @user_agent = request.env["HTTP_USER_AGENT"] || Gabba::USER_AGENT @utmhn ||= request.env["SERVER_NAME"] || "" @utmr = request.params['utmr'].blank? ? (request.env['HTTP_REFERER'].blank? ? "-" : request.env['HTTP_REFERER']) : request.params[:utmr] @utmp = request.params['utmp'].blank? ? (request.env['REQUEST_URI'] || "") : request.params['utmp'] # the last octect of the IP address is removed to anonymize the user. @utmip = IPAddr.new(request.env["REMOTE_ADDR"]).mask(24).to_s end |