Class: Analytical::Modules::GoogleOptimizer

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/analytical/modules/google_optimizer.rb

Instance Attribute Summary

Attributes included from Base

#command_store, #initialized, #options, #tracking_command_location

Instance Method Summary collapse

Methods included from Base

#init_location, #init_location?, #process_queued_commands, #protocol, #queue

Constructor Details

#initialize(options = {}) ⇒ GoogleOptimizer

Returns a new instance of GoogleOptimizer.



6
7
8
9
# File 'lib/analytical/modules/google_optimizer.rb', line 6

def initialize(options={})
  super
  @tracking_command_location = :head_prepend
end

Instance Method Details

#conversion(*args) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/analytical/modules/google_optimizer.rb', line 43

def conversion(*args)
  js = <<-HTML
  <!-- Analytical Init:  Google Website Optimizer Conversion Script -->
  <script type="text/javascript">
  if(typeof(_gat)!='object')document.write('<sc'+'ript src="http'+
  (document.location.protocol=='https:'?'s://ssl':'://www')+
  '.google-analytics.com/ga.js"></sc'+'ript>')</script>
  <script type="text/javascript">
  try {
    var gwoTracker=_gat._getTracker("#{options[:]}");
    gwoTracker._trackPageview("/#{options[:key]}/goal");
    }catch(err){}</script>
  <!-- End of Google Website Optimizer Conversion Script -->
  HTML
  js
end

#init_javascript(location) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/analytical/modules/google_optimizer.rb', line 11

def init_javascript(location)
  init_location(location) do
    js = <<-HTML
    <!-- Analytical Init:  Google Website Optimizer Control Script -->
		<script>
		function utmx_section(){}function utmx(){}
		(function(){var k='#{options[:key]}',d=document,l=d.location,c=d.cookie;function f(n){
		if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.indexOf(';',i);return c.substring(i+n.
		length+1,j<0?c.length:j)}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;
		d.write('<sc'+'ript src="'+
		'http'+(l.protocol=='https:'?'s://ssl':'://www')+'.google-analytics.com'
		+'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='
		+new Date().valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+
		'" type="text/javascript" charset="utf-8"></sc'+'ript>')})();
		</script>
		<!-- End of Google Website Optimizer Control Script -->
		<!-- Analytical Init: Google Website Optimizer Tracking Script -->
    <script type="text/javascript">
    if(typeof(_gat)!='object')document.write('<sc'+'ript src="http'+
    (document.location.protocol=='https:'?'s://ssl':'://www')+
    '.google-analytics.com/ga.js"></sc'+'ript>')</script>
    <script type="text/javascript">
    try {
      var gwoTracker=_gat._getTracker("#{options[:]}");
      gwoTracker._trackPageview("/#{options[:key]}/test");
      }catch(err){}</script>
    <!-- End of Google Website Optimizer Tracking Script -->
    HTML
    js
  end
end