Skip to content

Commit 06191c0

Browse files
authored
Merge pull request #34 from splitrb/fix-split-integration
Make split-analytics work with the latest split version
2 parents bf0eb0d + e899407 commit 06191c0

4 files changed

Lines changed: 38 additions & 12 deletions

File tree

lib/split/analytics.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ def tracking_code(options = {})
3131
end
3232

3333
def custom_variables
34-
return nil if session.nil?
34+
return nil if ab_user.nil?
3535
arr = []
3636

37-
session.each_with_index do |h, i|
37+
ab_user.active_experiments.each_with_index do |h, i|
3838
arr << "_gaq.push([\"_setCustomVar\", #{i + 1}, \"#{h[0]}\", \"#{h[1]}\", 1]);"
3939
end
4040
arr.reverse[0..4].reverse.join("\n")

spec/analytics_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020
it 'should add custom variables for every test the user is involved in' do
2121
first_alt = ab_test('link_colour', 'red', 'blue')
22-
23-
expect(session).to eql({'link_colour' => first_alt})
22+
expect(ab_user.active_experiments).to eql({'link_colour' => first_alt})
2423

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

spec/spec_helper.rb

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,41 @@
55
require 'split/analytics'
66
require 'ostruct'
77

8-
def session
9-
@ab_user ||= {}
10-
end
8+
require "fakeredis"
119

12-
RSpec.configure do |config|
13-
config.order = 'random'
14-
config.before(:each) do
10+
G_fakeredis = Redis.new
11+
12+
module GlobalSharedContext
13+
extend RSpec::SharedContext
14+
let(:ab_user){ Split::User.new(double(session: {})) }
15+
16+
before(:each) do
1517
Split.configuration = Split::Configuration.new
18+
Split.redis = G_fakeredis
1619
Split.redis.flushall
17-
@ab_user = {}
20+
@ab_user = ab_user
21+
params = nil
1822
end
1923
end
24+
25+
RSpec.configure do |config|
26+
config.order = 'random'
27+
config.include GlobalSharedContext
28+
end
29+
30+
def session
31+
@session ||= {}
32+
end
33+
34+
def params
35+
@params ||= {}
36+
end
37+
38+
def request(ua = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; de-de) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27')
39+
@request ||= begin
40+
r = OpenStruct.new
41+
r.user_agent = ua
42+
r.ip = '192.168.1.1'
43+
r
44+
end
45+
end

split-analytics.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ Gem::Specification.new do |gem|
1616
gem.require_paths = ['lib']
1717
gem.version = Split::Analytics::VERSION
1818

19-
gem.add_dependency('split', '>= 1.0.0')
19+
gem.add_dependency('split', '>= 3.0.0')
2020

2121
gem.add_development_dependency('rspec', '~> 3.1')
2222
gem.add_development_dependency('rake', '~> 12.3')
23+
gem.add_development_dependency('fakeredis', '~> 0.7')
2324
end

0 commit comments

Comments
 (0)