split-analytics 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/Readme.mdown +63 -9
- data/lib/split/analytics.rb +38 -3
- data/lib/split/analytics/version.rb +1 -1
- data/spec/analytics_spec.rb +17 -2
- data/spec/spec_helper.rb +1 -1
- data/split-analytics.gemspec +3 -2
- metadata +48 -71
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1c137bdda5d58e5be423f480171b8db9a33ca43b
|
4
|
+
data.tar.gz: c2a14e14b278cccfd05b8173439eb30c1d45be2c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75686f802c2e7089d5fa8b0653c7a063c90cf3cfb9058d58fcff56a981a3d0c26eb58bd0a84d7fd15601b7c4711ccc33991b8fbd1a18a63d80f933eaddece03c
|
7
|
+
data.tar.gz: d0a2ed6631741fc21ba09282f92524060e27cf98a0581dbe2b005d61e18a6ee7c82971c8ff7c3e117f09e6c8e53fc096a73acf4a04de6b3fc7e532d222d6ba29
|
data/LICENSE
CHANGED
data/Readme.mdown
CHANGED
@@ -10,29 +10,83 @@ The split gem and its dependencies.
|
|
10
10
|
|
11
11
|
If you are using bundler add split to your Gemfile:
|
12
12
|
|
13
|
-
|
13
|
+
```ruby
|
14
|
+
gem 'split-analytics', :require => 'split/analytics'
|
15
|
+
```
|
14
16
|
|
15
17
|
Then run:
|
16
18
|
|
17
|
-
|
19
|
+
```bash
|
20
|
+
bundle install
|
21
|
+
```
|
18
22
|
|
19
23
|
Otherwise install the gem:
|
20
24
|
|
21
|
-
|
25
|
+
```bash
|
26
|
+
gem install split-analytics
|
27
|
+
```
|
22
28
|
|
23
29
|
and require it in your project:
|
24
30
|
|
25
|
-
|
31
|
+
```ruby
|
32
|
+
require 'split/analytics'
|
33
|
+
```
|
26
34
|
|
27
35
|
## Usage
|
28
36
|
|
29
37
|
Use in your application layout template
|
30
38
|
|
31
|
-
|
32
|
-
<%= tracking_code(:account => 'UA-12345-6') %>
|
39
|
+
erb example:
|
33
40
|
|
34
|
-
|
35
|
-
|
41
|
+
```erb
|
42
|
+
<%= tracking_code(:account => 'UA-12345-6') %>
|
43
|
+
```
|
44
|
+
|
45
|
+
haml example:
|
46
|
+
|
47
|
+
```haml
|
48
|
+
= tracking_code(:account => 'UA-12345-6')
|
49
|
+
```
|
50
|
+
|
51
|
+
### With Tracking Methods
|
52
|
+
|
53
|
+
See [Google Analytics Tracking Methods](https://developers.google.com/analytics/devguides/collection/gajs/methods/) for available options.
|
54
|
+
|
55
|
+
```
|
56
|
+
tracker_methods = {
|
57
|
+
:setDomainName => "example.com", # String argument
|
58
|
+
:setAllowLinker => true, # Boolean argument
|
59
|
+
:require => ['inpage_linkid', '//www.google-analytics.com/plugins/ga/inpage_linkid.js'] # Array argument (will be splattered)
|
60
|
+
:clearOrganic => "" # No argument
|
61
|
+
}
|
62
|
+
```
|
63
|
+
|
64
|
+
erb example:
|
65
|
+
|
66
|
+
```erb
|
67
|
+
<%= tracking_code(:account => 'UA-12345-6', :tracker_methods => tracker_methods) %>
|
68
|
+
```
|
69
|
+
|
70
|
+
haml example:
|
71
|
+
|
72
|
+
```haml
|
73
|
+
= tracking_code(:account => 'UA-12345-6', :tracker_methods => tracker_methods)
|
74
|
+
```
|
75
|
+
### Other Tracking URLs
|
76
|
+
|
77
|
+
You can use other Tracking URLs with the option tracker_url and ssl_tracker_url.
|
78
|
+
|
79
|
+
erb example:
|
80
|
+
|
81
|
+
```erb
|
82
|
+
<%= tracking_code(:account => 'UA-12345-6', :tracker_url => 'stats.g.doubleclick.net/dc.js', :ssl_tracker_url => 'stats.g.doubleclick.net/dc.js') %>
|
83
|
+
```
|
84
|
+
|
85
|
+
haml example:
|
86
|
+
|
87
|
+
```haml
|
88
|
+
= tracking_code(:account => 'UA-12345-6', :tracker_url => 'stats.g.doubleclick.net/dc.js', :ssl_tracker_url => 'stats.g.doubleclick.net/dc.js')
|
89
|
+
```
|
36
90
|
|
37
91
|
## Development
|
38
92
|
|
@@ -53,4 +107,4 @@ Tests can be ran with `rake spec`
|
|
53
107
|
|
54
108
|
## Copyright
|
55
109
|
|
56
|
-
Copyright (c)
|
110
|
+
Copyright (c) 2013 Andrew Nesbitt. See LICENSE for details.
|
data/lib/split/analytics.rb
CHANGED
@@ -5,18 +5,23 @@ module Split
|
|
5
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
|
+
tracker_url = options.delete(:tracker_url)
|
9
|
+
ssl_tracker_url = options.delete(:ssl_tracker_url)
|
10
|
+
tracker_methods = options.delete(:tracker_methods)
|
11
|
+
|
12
|
+
tracker_url = 'http://' + (tracker_url || 'www.google-analytics.com/ga.js')
|
13
|
+
ssl_tracker_url = 'https://' + (ssl_tracker_url || 'ssl.google-analytics.com/ga.js')
|
8
14
|
|
9
15
|
code = <<-EOF
|
10
16
|
<script type="text/javascript">
|
11
17
|
var _gaq = _gaq || [];
|
12
18
|
_gaq.push(['_setAccount', '#{account}']);
|
19
|
+
#{insert_tracker_methods(tracker_methods)}
|
13
20
|
#{custom_variables}
|
14
21
|
_gaq.push(['_trackPageview']);
|
15
|
-
_gaq.push(['_trackPageLoadTime']);
|
16
|
-
|
17
22
|
(function() {
|
18
23
|
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
19
|
-
ga.src = ('https:' == document.location.protocol ? '
|
24
|
+
ga.src = ('https:' == document.location.protocol ? '#{ssl_tracker_url}' : '#{tracker_url}');
|
20
25
|
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
21
26
|
})();
|
22
27
|
</script>
|
@@ -33,6 +38,36 @@ module Split
|
|
33
38
|
end
|
34
39
|
arr.reverse[0..4].reverse.join("\n")
|
35
40
|
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def insert_tracker_methods(tracker_methods)
|
45
|
+
return nil if tracker_methods.nil?
|
46
|
+
arr = []
|
47
|
+
tracker_methods.each do |k,v|
|
48
|
+
if v.class == String && v.empty?
|
49
|
+
# No argument tracker method
|
50
|
+
arr << "_gaq.push(['" + "_" + "#{k}']);"
|
51
|
+
else
|
52
|
+
case v
|
53
|
+
when String
|
54
|
+
# String argument tracker method
|
55
|
+
arr << "_gaq.push(['" + "_" + "#{k}', '#{v}']);"
|
56
|
+
when TrueClass
|
57
|
+
# Boolean argument tracker method
|
58
|
+
arr << "_gaq.push(['" + "_" + "#{k}', #{v}]);"
|
59
|
+
when FalseClass
|
60
|
+
# Boolean argument tracker method
|
61
|
+
arr << "_gaq.push(['" + "_" + "#{k}', #{v}]);"
|
62
|
+
when Array
|
63
|
+
# Array argument tracker method
|
64
|
+
values = v.map { |value| "'#{value}'" }.join(', ')
|
65
|
+
arr << "_gaq.push(['" + "_" + "#{k}', #{values}]);"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
arr.join("\n")
|
70
|
+
end
|
36
71
|
end
|
37
72
|
end
|
38
73
|
|
data/spec/analytics_spec.rb
CHANGED
@@ -4,7 +4,17 @@ describe Split::Analytics do
|
|
4
4
|
include Split::Helper
|
5
5
|
it "should generate valid analytics javascript" do
|
6
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
|
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")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should generate valid analytics javascript with arbitrary tracker object methods" do
|
11
|
+
tracker_methods = {
|
12
|
+
:setDomainName => "example.com", # String argument
|
13
|
+
:setAllowLinker => true, # Boolean argument
|
14
|
+
:clearOrganic => "" # No argument
|
15
|
+
}
|
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")
|
8
18
|
end
|
9
19
|
|
10
20
|
it "should add custom variables for every test the user is involved in" do
|
@@ -14,6 +24,11 @@ describe Split::Analytics do
|
|
14
24
|
session[:split].should eql({'link_colour' => first_alt,'link_text' => second_alt})
|
15
25
|
|
16
26
|
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', 2, 'link_text', '#{second_alt}', 1]);\n
|
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")
|
28
|
+
end
|
29
|
+
|
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")
|
18
33
|
end
|
19
34
|
end
|
data/spec/spec_helper.rb
CHANGED
data/split-analytics.gemspec
CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.email = ["andrewnez@gmail.com"]
|
8
8
|
gem.summary = %q{Split extension to push test data to google analytics}
|
9
9
|
gem.homepage = "https://github.com/andrew/split-analytics"
|
10
|
+
gem.license = 'MIT'
|
10
11
|
|
11
12
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
13
|
gem.files = `git ls-files`.split("\n")
|
@@ -15,8 +16,8 @@ Gem::Specification.new do |gem|
|
|
15
16
|
gem.require_paths = ['lib']
|
16
17
|
gem.version = Split::Analytics::VERSION
|
17
18
|
|
18
|
-
gem.add_dependency(%q<split>, ["
|
19
|
+
gem.add_dependency(%q<split>, [">= 0.3.0"])
|
19
20
|
|
20
21
|
# Development Dependencies
|
21
|
-
gem.add_development_dependency(%q<rspec>, ["~> 2.
|
22
|
+
gem.add_development_dependency(%q<rspec>, ["~> 2.14"])
|
22
23
|
end
|
metadata
CHANGED
@@ -1,63 +1,50 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: split-analytics
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 0
|
10
|
-
version: 0.3.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Andrew Nesbitt
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-03-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
22
14
|
name: split
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 13
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 3
|
33
|
-
version: "0.3"
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.0
|
34
20
|
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: rspec
|
38
21
|
prerelease: false
|
39
|
-
|
40
|
-
|
41
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
42
31
|
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
|
45
|
-
segments:
|
46
|
-
- 2
|
47
|
-
- 6
|
48
|
-
version: "2.6"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.14'
|
49
34
|
type: :development
|
50
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.14'
|
51
41
|
description:
|
52
|
-
email:
|
42
|
+
email:
|
53
43
|
- andrewnez@gmail.com
|
54
44
|
executables: []
|
55
|
-
|
56
45
|
extensions: []
|
57
|
-
|
58
46
|
extra_rdoc_files: []
|
59
|
-
|
60
|
-
files:
|
47
|
+
files:
|
61
48
|
- .gitignore
|
62
49
|
- Gemfile
|
63
50
|
- LICENSE
|
@@ -68,40 +55,30 @@ files:
|
|
68
55
|
- spec/analytics_spec.rb
|
69
56
|
- spec/spec_helper.rb
|
70
57
|
- split-analytics.gemspec
|
71
|
-
has_rdoc: true
|
72
58
|
homepage: https://github.com/andrew/split-analytics
|
73
|
-
licenses:
|
74
|
-
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
75
62
|
post_install_message:
|
76
63
|
rdoc_options: []
|
77
|
-
|
78
|
-
require_paths:
|
64
|
+
require_paths:
|
79
65
|
- lib
|
80
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
none: false
|
91
|
-
requirements:
|
92
|
-
- - ">="
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
hash: 3
|
95
|
-
segments:
|
96
|
-
- 0
|
97
|
-
version: "0"
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
98
76
|
requirements: []
|
99
|
-
|
100
77
|
rubyforge_project:
|
101
|
-
rubygems_version:
|
78
|
+
rubygems_version: 2.0.3
|
102
79
|
signing_key:
|
103
|
-
specification_version:
|
80
|
+
specification_version: 4
|
104
81
|
summary: Split extension to push test data to google analytics
|
105
|
-
test_files:
|
82
|
+
test_files:
|
106
83
|
- spec/analytics_spec.rb
|
107
84
|
- spec/spec_helper.rb
|