split-analytics 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ task :default => :spec
data/Readme.mdown ADDED
@@ -0,0 +1,56 @@
1
+ # Split::Analytics
2
+
3
+ An extension to [Split](http://github.com/andrew/split) to push test data to google analytics.
4
+
5
+ ## Requirements
6
+
7
+ The split gem and its dependencies.
8
+
9
+ ## Setup
10
+
11
+ If you are using bundler add split to your Gemfile:
12
+
13
+ gem 'split-analytics', :require => 'split/analytics'
14
+
15
+ Then run:
16
+
17
+ bundle install
18
+
19
+ Otherwise install the gem:
20
+
21
+ gem install split-analytics
22
+
23
+ and require it in your project:
24
+
25
+ require 'split/analytics'
26
+
27
+ ## Usage
28
+
29
+ Use in your application layout template
30
+
31
+ # erb
32
+ <%= tracking_code(:account => 'UA-12345-6') %>
33
+
34
+ # haml
35
+ = tracking_code(:account => 'UA-12345-6')
36
+
37
+ ## Development
38
+
39
+ Source hosted at [GitHub](http://github.com/andrew/split-analytics).
40
+ Report Issues/Feature requests on [GitHub Issues](http://github.com/andrew/split-analytics/issues).
41
+
42
+ Tests can be ran with `rake spec`
43
+
44
+ ### Note on Patches/Pull Requests
45
+
46
+ * Fork the project.
47
+ * Make your feature addition or bug fix.
48
+ * Add tests for it. This is important so I don't break it in a
49
+ future version unintentionally.
50
+ * Commit, do not mess with rakefile, version, or history.
51
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
52
+ * Send me a pull request. Bonus points for topic branches.
53
+
54
+ ## Copyright
55
+
56
+ Copyright (c) 2011 Andrew Nesbitt. See LICENSE for details.
@@ -0,0 +1,5 @@
1
+ module Split
2
+ module Analytics
3
+ VERSION = "0.2.2"
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ require "split/helper"
2
+
3
+ module Split
4
+ module Analytics
5
+ def tracking_code(options={})
6
+ # needs more options: http://code.google.com/apis/analytics/docs/gaJS/gaJSApi.html
7
+ account = options.delete(:account)
8
+
9
+ <<-EOF
10
+ <script type="text/javascript">
11
+ var _gaq = _gaq || [];
12
+ _gaq.push(['_setAccount', '#{account}']);
13
+ #{custom_variables}
14
+ _gaq.push(['_trackPageview']);
15
+
16
+ (function() {
17
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
18
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
19
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
20
+ })();
21
+ </script>
22
+ EOF
23
+ end
24
+
25
+ def custom_variables
26
+ return nil if session[:split].nil?
27
+ session[:split].map do |k,v|
28
+ "_gaq.push(['_setCustomVar', 1, '#{k}', '#{v}', 1]);"
29
+ end.join("\n")
30
+ end
31
+ end
32
+ end
33
+
34
+ module Split::Helper
35
+ include Split::Analytics
36
+ end
37
+
38
+ # mix Spilt::Analytics into Split::Helpers
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Split::Analytics do
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 _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")
8
+ end
9
+
10
+ it "should add custom variables for every test the user is involved in" do
11
+ first_alt = ab_test('link_colour', 'red', 'blue')
12
+ second_alt = ab_test('link_text', 'Join', 'Signup')
13
+
14
+ session[:split].should eql({'link_colour' => first_alt,'link_text' => second_alt})
15
+
16
+ tracking_code = tracking_code(:account => 'UA-12345-6')
17
+ 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")
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'split'
4
+ require 'split/helper'
5
+ require 'split/analytics'
6
+ require 'ostruct'
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
21
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "split/analytics/version"
4
+
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"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "split-analytics"
15
+ gem.require_paths = ['lib']
16
+ gem.version = Split::Analytics::VERSION
17
+
18
+ gem.add_dependency(%q<split>, ["~> 0.2.2"])
19
+
20
+ # Development Dependencies
21
+ gem.add_development_dependency(%q<rspec>, ["~> 2.6"])
22
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: split-analytics
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 2
10
+ version: 0.2.2
11
+ platform: ruby
12
+ authors:
13
+ - Andrew Nesbitt
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-21 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: split
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 19
30
+ segments:
31
+ - 0
32
+ - 2
33
+ - 2
34
+ version: 0.2.2
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 15
46
+ segments:
47
+ - 2
48
+ - 6
49
+ version: "2.6"
50
+ type: :development
51
+ version_requirements: *id002
52
+ description:
53
+ email:
54
+ - andrewnez@gmail.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - Rakefile
65
+ - Readme.mdown
66
+ - lib/split/analytics.rb
67
+ - lib/split/analytics/version.rb
68
+ - spec/analytics_spec.rb
69
+ - spec/spec_helper.rb
70
+ - split-analytics.gemspec
71
+ has_rdoc: true
72
+ homepage: https://github.com/andrew/split-analytics
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options: []
77
+
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ requirements: []
99
+
100
+ rubyforge_project:
101
+ rubygems_version: 1.3.7
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Split extension to push test data to google analytics
105
+ test_files:
106
+ - spec/analytics_spec.rb
107
+ - spec/spec_helper.rb