Sha256: 03b11bd26524a905dc860a16c25e97a3180233155ade99c3da1c22f05ddc155b

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

require 'spec_helper'

describe Split::Analytics do
  include Split::Helper
  it "should generate valid analytics javascript" do
    tracking_code = tracking_code(:account => 'UA-12345-6')
    tracking_code.should eql("        <script type=\"text/javascript\">\n          var _gaq = _gaq || [];\n          _gaq.push(['_setAccount', 'UA-12345-6']);\n          \n          _gaq.push(['_trackPageview']);\n\n          (function() {\n            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n          })();\n        </script>\n")
  end

  it "should add custom variables for every test the user is involved in" do
    first_alt = ab_test('link_colour', 'red', 'blue')
    second_alt = ab_test('link_text', 'Join', 'Signup')

    session[:split].should eql({'link_colour' => first_alt,'link_text' => second_alt})

    tracking_code = tracking_code(:account => 'UA-12345-6')
    tracking_code.should eql("        <script type=\"text/javascript\">\n          var _gaq = _gaq || [];\n          _gaq.push(['_setAccount', 'UA-12345-6']);\n          _gaq.push(['_setCustomVar', 1, 'link_colour', '#{first_alt}', 1]);\n_gaq.push(['_setCustomVar', 1, 'link_text', '#{second_alt}', 1]);\n          _gaq.push(['_trackPageview']);\n\n          (function() {\n            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n          })();\n        </script>\n")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
split-analytics-0.2.2 spec/analytics_spec.rb