Class: Satellite::Adapters::GoogleAnalytics
- Defined in:
- lib/satellite/adapters/google_analytics.rb
Defined Under Namespace
Classes: Utme
Class Attribute Summary collapse
-
.account_id ⇒ Object
Returns the value of attribute account_id.
Instance Attribute Summary collapse
-
#accept_language ⇒ Object
Returns the value of attribute accept_language.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(params, use_ssl = false) ⇒ GoogleAnalytics
constructor
A new instance of GoogleAnalytics.
- #set_custom_variable(index, name, value, scope = nil) ⇒ Object
- #track ⇒ Object
- #track_event(category, action, label = nil, value = nil) ⇒ Object
- #track_page_view(path = nil) ⇒ Object
- #tracking_url ⇒ Object
- #unset_custom_variable(index) ⇒ Object
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_id ⇒ Object
Returns the value of attribute account_id.
64 65 66 |
# File 'lib/satellite/adapters/google_analytics.rb', line 64 def account_id @account_id end |
Instance Attribute Details
#accept_language ⇒ Object
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 |
#debug ⇒ Object
Returns the value of attribute debug.
5 6 7 |
# File 'lib/satellite/adapters/google_analytics.rb', line 5 def debug @debug end |
#user_agent ⇒ Object
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 |
#track ⇒ Object
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_url ⇒ Object
29 30 31 |
# File 'lib/satellite/adapters/google_analytics.rb', line 29 def tracking_url utm_location + "?" + @utm_params.to_query end |