Class: Gabbara::Gabba

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.extract_options!
  @utmhn = args.shift
  opts.each {|key, value| self.send("#{key}=", value) }
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



18
19
20
# File 'lib/gabbara/gabba.rb', line 18

def logger
  @logger
end

#user_agentObject

Returns the value of attribute user_agent.



18
19
20
# File 'lib/gabbara/gabba.rb', line 18

def user_agent
  @user_agent
end

#utmacObject

Returns the value of attribute utmac.



18
19
20
# File 'lib/gabbara/gabba.rb', line 18

def utmac
  @utmac
end

#utmccObject

Returns the value of attribute utmcc.



18
19
20
# File 'lib/gabbara/gabba.rb', line 18

def utmcc
  @utmcc
end

#utmcsObject

Returns the value of attribute utmcs.



18
19
20
# File 'lib/gabbara/gabba.rb', line 18

def utmcs
  @utmcs
end

#utmhidObject

Returns the value of attribute utmhid.



18
19
20
# File 'lib/gabbara/gabba.rb', line 18

def utmhid
  @utmhid
end

#utmhnObject

Returns the value of attribute utmhn.



18
19
20
# File 'lib/gabbara/gabba.rb', line 18

def utmhn
  @utmhn
end

#utmipObject

Returns the value of attribute utmip.



18
19
20
# File 'lib/gabbara/gabba.rb', line 18

def utmip
  @utmip
end

#utmnObject

Returns the value of attribute utmn.



18
19
20
# File 'lib/gabbara/gabba.rb', line 18

def utmn
  @utmn
end

#utmpObject

Returns the value of attribute utmp.



18
19
20
# File 'lib/gabbara/gabba.rb', line 18

def utmp
  @utmp
end

#utmrObject

Returns the value of attribute utmr.



18
19
20
# File 'lib/gabbara/gabba.rb', line 18

def utmr
  @utmr
end

#utmulObject

Returns the value of attribute utmul.



18
19
20
# File 'lib/gabbara/gabba.rb', line 18

def utmul
  @utmul
end

#utmwvObject

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)
  
  opts = args.extract_options!
  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)
  
  opts = args.extract_options!
  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