split-analytics 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c137bdda5d58e5be423f480171b8db9a33ca43b
4
- data.tar.gz: c2a14e14b278cccfd05b8173439eb30c1d45be2c
3
+ metadata.gz: ae9c0830e8d0f8a173d397c71c090971e1584cf2
4
+ data.tar.gz: 3fff2e89f8c222d0973d2c24ec6070c452ef9277
5
5
  SHA512:
6
- metadata.gz: 75686f802c2e7089d5fa8b0653c7a063c90cf3cfb9058d58fcff56a981a3d0c26eb58bd0a84d7fd15601b7c4711ccc33991b8fbd1a18a63d80f933eaddece03c
7
- data.tar.gz: d0a2ed6631741fc21ba09282f92524060e27cf98a0581dbe2b005d61e18a6ee7c82971c8ff7c3e117f09e6c8e53fc096a73acf4a04de6b3fc7e532d222d6ba29
6
+ metadata.gz: aa31c9bd3443748b92677377ca8f29e6868f1b78c51e7a4677ac2375e06412c83a76f94f496aba0a94d06f820d3fd6dc166240774923b2f33b862a425f9a3d60
7
+ data.tar.gz: 2f4bd0c27bfdd1cc8141ba93b77d38ee254e8c8b4ff0c065da6848149115fb24ed89607807cf7b4029df9b71b2193d01a2cefaaeed6c2374939120170919773a
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+
5
+ services:
6
+ - redis-server
7
+ cache: bundler
8
+ sudo: false
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Andrew Nesbitt
1
+ Copyright (c) 2015 Andrew Nesbitt
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -107,4 +107,4 @@ Tests can be ran with `rake spec`
107
107
 
108
108
  ## Copyright
109
109
 
110
- Copyright (c) 2013 Andrew Nesbitt. See LICENSE for details.
110
+ Copyright (c) 2015 Andrew Nesbitt. See LICENSE for details.
@@ -1,8 +1,8 @@
1
- require "split/helper"
1
+ require 'split/helper'
2
2
 
3
3
  module Split
4
4
  module Analytics
5
- def tracking_code(options={})
5
+ def tracking_code(options = {})
6
6
  # needs more options: http://code.google.com/apis/analytics/docs/gaJS/gaJSApi.html
7
7
  account = options.delete(:account)
8
8
  tracker_url = options.delete(:tracker_url)
@@ -26,15 +26,15 @@ module Split
26
26
  })();
27
27
  </script>
28
28
  EOF
29
- code = raw(code)if defined?(raw)
29
+ code = raw(code) if defined?(raw)
30
30
  code
31
31
  end
32
32
 
33
33
  def custom_variables
34
- return nil if session[:split].nil?
34
+ return nil if ab_user.nil?
35
35
  arr = []
36
- session[:split].each_with_index do |h,i|
37
- arr << "_gaq.push(['_setCustomVar', #{i+1}, '#{h[0]}', '#{h[1]}', 1]);"
36
+ ab_user.each_with_index do |h, i|
37
+ arr << "_gaq.push(['_setCustomVar', #{i + 1}, '#{h[0]}', '#{h[1]}', 1]);"
38
38
  end
39
39
  arr.reverse[0..4].reverse.join("\n")
40
40
  end
@@ -44,7 +44,7 @@ module Split
44
44
  def insert_tracker_methods(tracker_methods)
45
45
  return nil if tracker_methods.nil?
46
46
  arr = []
47
- tracker_methods.each do |k,v|
47
+ tracker_methods.each do |k, v|
48
48
  if v.class == String && v.empty?
49
49
  # No argument tracker method
50
50
  arr << "_gaq.push(['" + "_" + "#{k}']);"
@@ -52,17 +52,17 @@ module Split
52
52
  case v
53
53
  when String
54
54
  # String argument tracker method
55
- arr << "_gaq.push(['" + "_" + "#{k}', '#{v}']);"
55
+ arr << "_gaq.push(['" + '_' + "#{k}', '#{v}']);"
56
56
  when TrueClass
57
57
  # Boolean argument tracker method
58
- arr << "_gaq.push(['" + "_" + "#{k}', #{v}]);"
58
+ arr << "_gaq.push(['" + '_' + "#{k}', #{v}]);"
59
59
  when FalseClass
60
60
  # Boolean argument tracker method
61
- arr << "_gaq.push(['" + "_" + "#{k}', #{v}]);"
61
+ arr << "_gaq.push(['" + '_' + "#{k}', #{v}]);"
62
62
  when Array
63
63
  # Array argument tracker method
64
64
  values = v.map { |value| "'#{value}'" }.join(', ')
65
- arr << "_gaq.push(['" + "_" + "#{k}', #{values}]);"
65
+ arr << "_gaq.push(['" + '_' + "#{k}', #{values}]);"
66
66
  end
67
67
  end
68
68
  end
@@ -80,4 +80,4 @@ if defined?(Rails)
80
80
  ActionController::Base.send :include, Split::Analytics
81
81
  ActionController::Base.helper Split::Analytics
82
82
  end
83
- end
83
+ end
@@ -1,5 +1,5 @@
1
1
  module Split
2
2
  module Analytics
3
- VERSION = "0.4.0"
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
@@ -2,33 +2,30 @@ require 'spec_helper'
2
2
 
3
3
  describe Split::Analytics do
4
4
  include Split::Helper
5
- it "should generate valid analytics javascript" do
6
- tracking_code = tracking_code(:account => 'UA-12345-6')
7
- tracking_code.should eql(" <script type=\"text/javascript\">\n var _gaq = _gaq || [];\n _gaq.push(['_setAccount', 'UA-12345-6']);\n \n \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")
5
+ it 'should generate valid analytics javascript' do
6
+ tracking_code = tracking_code(account: 'UA-12345-6')
7
+ expect(tracking_code).to eql(" <script type=\"text/javascript\">\n var _gaq = _gaq || [];\n _gaq.push(['_setAccount', 'UA-12345-6']);\n \n \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")
8
8
  end
9
9
 
10
- it "should generate valid analytics javascript with arbitrary tracker object methods" do
10
+ it 'should generate valid analytics javascript with arbitrary tracker object methods' do
11
11
  tracker_methods = {
12
- :setDomainName => "example.com", # String argument
13
- :setAllowLinker => true, # Boolean argument
14
- :clearOrganic => "" # No argument
12
+ setDomainName: 'example.com', # String argument
13
+ setAllowLinker: true, # Boolean argument
14
+ clearOrganic: '' # No argument
15
15
  }
16
16
  tracking_code = tracking_code(:account => 'UA-12345-6', :tracker_methods => tracker_methods)
17
- tracking_code.should eql(" <script type=\"text/javascript\">\n var _gaq = _gaq || [];\n _gaq.push(['_setAccount', 'UA-12345-6']);\n _gaq.push(['_setDomainName', 'example.com']);\n_gaq.push(['_setAllowLinker', true]);\n_gaq.push(['_clearOrganic']);\n \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")
17
+ expect(tracking_code).to eql(" <script type=\"text/javascript\">\n var _gaq = _gaq || [];\n _gaq.push(['_setAccount', 'UA-12345-6']);\n _gaq.push(['_setDomainName', 'example.com']);\n_gaq.push(['_setAllowLinker', true]);\n_gaq.push(['_clearOrganic']);\n \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")
18
18
  end
19
19
 
20
- it "should add custom variables for every test the user is involved in" do
20
+ it 'should add custom variables for every test the user is involved in' do
21
21
  first_alt = ab_test('link_colour', 'red', 'blue')
22
- second_alt = ab_test('link_text', 'Join', 'Signup')
23
22
 
24
- session[:split].should eql({'link_colour' => first_alt,'link_text' => second_alt})
25
-
26
- tracking_code = tracking_code(:account => 'UA-12345-6')
27
- 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', 2, 'link_text', '#{second_alt}', 1]);\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.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")
23
+ tracking_code = tracking_code(account: 'UA-12345-6')
24
+ expect(tracking_code).to eql(" <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")
28
25
  end
29
26
 
30
- it "uses doubleclick as tracker url" do
31
- tracking_code = tracking_code(:account => 'UA-12345-6', :tracker_url => 'stats.g.doubleclick.net/dc.js', :ssl_tracker_url => 'stats.g.doubleclick.net/dc.js')
32
- tracking_code.should eql(" <script type=\"text/javascript\">\n var _gaq = _gaq || [];\n _gaq.push(['_setAccount', 'UA-12345-6']);\n \n \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://stats.g.doubleclick.net/dc.js' : 'http://stats.g.doubleclick.net/dc.js');\n var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n })();\n </script>\n")
27
+ it 'uses doubleclick as tracker url' do
28
+ tracking_code = tracking_code(account: 'UA-12345-6', tracker_url: 'stats.g.doubleclick.net/dc.js', :ssl_tracker_url => 'stats.g.doubleclick.net/dc.js')
29
+ expect(tracking_code).to eql(" <script type=\"text/javascript\">\n var _gaq = _gaq || [];\n _gaq.push(['_setAccount', 'UA-12345-6']);\n \n \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://stats.g.doubleclick.net/dc.js' : 'http://stats.g.doubleclick.net/dc.js');\n var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n })();\n </script>\n")
33
30
  end
34
31
  end
data/spec/spec_helper.rb CHANGED
@@ -5,17 +5,11 @@ require 'split/helper'
5
5
  require 'split/analytics'
6
6
  require 'ostruct'
7
7
 
8
- def session
9
- @session ||= {}
10
- end
11
-
12
- def params
13
- @params ||= {}
14
- end
15
-
16
- 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')
17
- r = OpenStruct.new
18
- r.user_agent = ua
19
- r.ip = '192.168.1.1'
20
- @request ||= r
8
+ RSpec.configure do |config|
9
+ config.order = 'random'
10
+ config.before(:each) do
11
+ Split.configuration = Split::Configuration.new
12
+ Split.redis.flushall
13
+ @ab_user = {}
14
+ end
21
15
  end
@@ -1,23 +1,23 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "split/analytics/version"
2
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
+ require 'split/analytics/version'
4
4
 
5
5
  Gem::Specification.new do |gem|
6
- gem.authors = ["Andrew Nesbitt"]
7
- gem.email = ["andrewnez@gmail.com"]
8
- gem.summary = %q{Split extension to push test data to google analytics}
9
- gem.homepage = "https://github.com/andrew/split-analytics"
6
+ gem.authors = ['Andrew Nesbitt']
7
+ gem.email = ['andrewnez@gmail.com']
8
+ gem.summary = 'Split extension to push test data to google analytics'
9
+ gem.homepage = 'https://github.com/andrew/split-analytics'
10
10
  gem.license = 'MIT'
11
11
 
12
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
13
13
  gem.files = `git ls-files`.split("\n")
14
14
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
- gem.name = "split-analytics"
15
+ gem.name = 'split-analytics'
16
16
  gem.require_paths = ['lib']
17
17
  gem.version = Split::Analytics::VERSION
18
18
 
19
- gem.add_dependency(%q<split>, [">= 0.3.0"])
19
+ gem.add_dependency('split', '>= 1.0.0')
20
20
 
21
- # Development Dependencies
22
- gem.add_development_dependency(%q<rspec>, ["~> 2.14"])
21
+ gem.add_development_dependency('rspec', '~> 3.1')
22
+ gem.add_development_dependency('rake', '~> 10.4')
23
23
  end
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: split-analytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-20 00:00:00.000000000 Z
11
+ date: 2015-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: split
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.0
19
+ version: 1.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.3.0
26
+ version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.14'
33
+ version: '3.1'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.14'
40
+ version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.4'
41
55
  description:
42
56
  email:
43
57
  - andrewnez@gmail.com
@@ -45,11 +59,12 @@ executables: []
45
59
  extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
48
- - .gitignore
62
+ - ".gitignore"
63
+ - ".travis.yml"
49
64
  - Gemfile
50
65
  - LICENSE
51
66
  - Rakefile
52
- - Readme.mdown
67
+ - Readme.md
53
68
  - lib/split/analytics.rb
54
69
  - lib/split/analytics/version.rb
55
70
  - spec/analytics_spec.rb
@@ -65,17 +80,17 @@ require_paths:
65
80
  - lib
66
81
  required_ruby_version: !ruby/object:Gem::Requirement
67
82
  requirements:
68
- - - '>='
83
+ - - ">="
69
84
  - !ruby/object:Gem::Version
70
85
  version: '0'
71
86
  required_rubygems_version: !ruby/object:Gem::Requirement
72
87
  requirements:
73
- - - '>='
88
+ - - ">="
74
89
  - !ruby/object:Gem::Version
75
90
  version: '0'
76
91
  requirements: []
77
92
  rubyforge_project:
78
- rubygems_version: 2.0.3
93
+ rubygems_version: 2.4.5
79
94
  signing_key:
80
95
  specification_version: 4
81
96
  summary: Split extension to push test data to google analytics