Module: Rubaidh::GoogleAnalyticsViewHelper

Defined in:
lib/rubaidh/view_helpers.rb

Overview

Collection of methods similar to the ones in ActionView::Helpers::UrlHelper, with the addition of outbound link tracking. See the Google Analytics help at www.google.com/support/googleanalytics/bin/answer.py?answer=55527 for more information on outbound link tracking.

Instance Method Summary collapse

Instance Method Details

Creates a link tag of the given name using a URL created by the set of options, with outbound link tracking under track_path in Google Analytics. The html_options will accept a hash of attributes for the link tag.

Raises:



10
11
12
13
14
# File 'lib/rubaidh/view_helpers.rb', line 10

def link_to_tracked(name, track_path = "/", options = {}, html_options = {})
  raise AnalyticsError.new("You must set Rubaidh::GoogleAnalytics.defer_load = false to use outbound link tracking") if GoogleAnalytics.defer_load == true
  html_options.merge!({:onclick => tracking_call(track_path)})
  link_to name, options, html_options
end

Creates a link tag of the given name using a URL created by the set of options if condition is true, with outbound link tracking under track_path in Google Analytics. The html_options will accept a hash of attributes for the link tag.

Raises:



19
20
21
22
23
# File 'lib/rubaidh/view_helpers.rb', line 19

def link_to_tracked_if(condition, name, track_path = "/", options = {}, html_options = {}, &block)
  raise AnalyticsError.new("You must set Rubaidh::GoogleAnalytics.defer_load = false to use outbound link tracking") if GoogleAnalytics.defer_load == true
  html_options.merge!({:onclick => tracking_call(track_path)})
  link_to_unless !condition, name, options, html_options, &block
end

Creates a link tag of the given name using a URL created by the set of options unless condition is true, with outbound link tracking under track_path in Google Analytics. The html_options will accept a hash of attributes for the link tag.

Raises:



28
29
30
31
32
# File 'lib/rubaidh/view_helpers.rb', line 28

def link_to_tracked_unless(condition, name, track_path = "/", options = {}, html_options = {}, &block)
  raise AnalyticsError.new("You must set Rubaidh::GoogleAnalytics.defer_load = false to use outbound link tracking") if GoogleAnalytics.defer_load == true
  html_options.merge!({:onclick => tracking_call(track_path)})
  link_to_unless condition, name, options, html_options, &block
end

Creates a link tag of the given name using a URL created by the set of options unless the current request URI is the same as the link’s, with outbound link tracking under track_path in Google Analytics. If the request URI is the same as the link URI, only the name is returned, or the block is yielded, if one exists. The html_options will accept a hash of attributes for the link tag.

Raises:



39
40
41
42
43
# File 'lib/rubaidh/view_helpers.rb', line 39

def link_to_tracked_unless_current(name, track_path = "/", options = {}, html_options = {}, &block)
  raise AnalyticsError.new("You must set Rubaidh::GoogleAnalytics.defer_load = false to use outbound link tracking") if GoogleAnalytics.defer_load == true
  html_options.merge!({:onclick =>tracking_call(track_path)})
  link_to_unless current_page?(options), name, options, html_options, &block
end