Class: Satellite::Adapters::GoogleAnalytics

Inherits:
Object
  • Object
show all
Defined in:
lib/satellite/adapters/google_analytics.rb

Defined Under Namespace

Classes: Utme

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, use_ssl = false) ⇒ GoogleAnalytics

Returns a new instance of GoogleAnalytics.



7
8
9
10
# File 'lib/satellite/adapters/google_analytics.rb', line 7

def initialize(params, use_ssl=false)
  @utm_params = extend_with_default_params(params)
  self.utm_location = (use_ssl ? 'https://ssl' : 'http://www') + UTM_GIF_LOCATION
end

Class Attribute Details

.account_idObject

Returns the value of attribute account_id.



64
65
66
# File 'lib/satellite/adapters/google_analytics.rb', line 64

def 
  @account_id
end

Instance Attribute Details

#accept_languageObject

Returns the value of attribute accept_language.



5
6
7
# File 'lib/satellite/adapters/google_analytics.rb', line 5

def accept_language
  @accept_language
end

#debugObject

Returns the value of attribute debug.



5
6
7
# File 'lib/satellite/adapters/google_analytics.rb', line 5

def debug
  @debug
end

#user_agentObject

Returns the value of attribute user_agent.



5
6
7
# File 'lib/satellite/adapters/google_analytics.rb', line 5

def user_agent
  @user_agent
end

Instance Method Details

#[](key) ⇒ Object



59
60
61
# File 'lib/satellite/adapters/google_analytics.rb', line 59

def [](key)
  @utm_params[key]
end

#[]=(key, value) ⇒ Object



54
55
56
57
# File 'lib/satellite/adapters/google_analytics.rb', line 54

def []=(key, value)
  value = Utme.parse(value) if key.to_s == 'utme'
  @utm_params[key] = value
end

#set_custom_variable(index, name, value, scope = nil) ⇒ Object



44
45
46
47
# File 'lib/satellite/adapters/google_analytics.rb', line 44

def set_custom_variable(index, name, value, scope=nil)
  self[:utme] = Utme.new if self[:utme].nil?
  self[:utme].set_custom_variable(index, name, value, scope)
end

#trackObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/satellite/adapters/google_analytics.rb', line 12

def track
  utm_url = tracking_url

  #if (debug == true)
    puts "--------sending request to GA-----------------------"
    puts @utm_params.inspect
    puts utm_url
  #end

  # actually send request
  open(utm_url, { "User-Agent" => 'Satellite/0.2.1', "Accept-Language" => self[:utmul] || 'de' })

  # reset events / custom variables here so they won't be reused in later requests
  self[:utme] = Utme.new
  true
end

#track_event(category, action, label = nil, value = nil) ⇒ Object



33
34
35
36
37
# File 'lib/satellite/adapters/google_analytics.rb', line 33

def track_event(category, action, label=nil, value=nil)
  self[:utme] = Utme.new if self[:utme].nil?
  self[:utme].set_event(category, action, label, value)
  track
end

#track_page_view(path = nil) ⇒ Object



39
40
41
42
# File 'lib/satellite/adapters/google_analytics.rb', line 39

def track_page_view(path=nil)
  self[:utmp] = path if path
  track
end

#tracking_urlObject



29
30
31
# File 'lib/satellite/adapters/google_analytics.rb', line 29

def tracking_url
  utm_location + "?" + @utm_params.to_query
end

#unset_custom_variable(index) ⇒ Object



49
50
51
52
# File 'lib/satellite/adapters/google_analytics.rb', line 49

def unset_custom_variable(index)
  self[:utme] = Utme.new if self[:utme].nil?
  self[:utme].unset_custom_variable(index)
end