urchin_tracking_module 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +65 -0
- data/Guardfile +11 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/lib/urchin_tracking_module/version.rb +3 -0
- data/lib/urchin_tracking_module.rb +91 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/urchin_tracking_module_spec.rb +74 -0
- data/urchin_tracking_module.gemspec +23 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e3c243cb81d5e5a138bd70ae987d62c4bb6e577b
|
4
|
+
data.tar.gz: 12297e38face069f651f34ab7242b6908e8e9ca9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b333ab5a7088bbc1c373570bf6caf1a105c9dd7edc1827a0148b95ad6e0a1d59bd4af742d792e43868d09a2ca84d72abb449598feb498bb134bebecbcc575a22
|
7
|
+
data.tar.gz: 05d8a8a0c5c3e3be0c61c9c2e6065e5c63a684bcca392e868d9481c62965d76c2aa252af400cd230fd4600d3eb58d179b80091220252789d9dd7839c1f87ba5b
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
urchin_tracking_module
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
urchin_tracking_module (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
active_support (3.0.0)
|
10
|
+
activesupport (= 3.0.0)
|
11
|
+
activesupport (3.0.0)
|
12
|
+
coderay (1.0.9)
|
13
|
+
diff-lcs (1.2.4)
|
14
|
+
ffi (1.9.0)
|
15
|
+
formatador (0.2.4)
|
16
|
+
guard (1.8.3)
|
17
|
+
formatador (>= 0.2.4)
|
18
|
+
listen (~> 1.3)
|
19
|
+
lumberjack (>= 1.0.2)
|
20
|
+
pry (>= 0.9.10)
|
21
|
+
thor (>= 0.14.6)
|
22
|
+
guard-bundler (0.1.3)
|
23
|
+
bundler (>= 1.0.0)
|
24
|
+
guard (>= 0.2.2)
|
25
|
+
guard-rspec (3.0.3)
|
26
|
+
guard (>= 1.8)
|
27
|
+
rspec (~> 2.13)
|
28
|
+
listen (1.3.1)
|
29
|
+
rb-fsevent (>= 0.9.3)
|
30
|
+
rb-inotify (>= 0.9)
|
31
|
+
rb-kqueue (>= 0.2)
|
32
|
+
lumberjack (1.0.4)
|
33
|
+
method_source (0.8.2)
|
34
|
+
pry (0.9.12.2)
|
35
|
+
coderay (~> 1.0.5)
|
36
|
+
method_source (~> 0.8)
|
37
|
+
slop (~> 3.4)
|
38
|
+
rake (10.1.0)
|
39
|
+
rb-fsevent (0.9.3)
|
40
|
+
rb-inotify (0.9.2)
|
41
|
+
ffi (>= 0.5.0)
|
42
|
+
rb-kqueue (0.2.0)
|
43
|
+
ffi (>= 0.5.0)
|
44
|
+
rspec (2.14.1)
|
45
|
+
rspec-core (~> 2.14.0)
|
46
|
+
rspec-expectations (~> 2.14.0)
|
47
|
+
rspec-mocks (~> 2.14.0)
|
48
|
+
rspec-core (2.14.5)
|
49
|
+
rspec-expectations (2.14.2)
|
50
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
51
|
+
rspec-mocks (2.14.3)
|
52
|
+
slop (3.4.6)
|
53
|
+
thor (0.18.1)
|
54
|
+
|
55
|
+
PLATFORMS
|
56
|
+
ruby
|
57
|
+
|
58
|
+
DEPENDENCIES
|
59
|
+
active_support
|
60
|
+
bundler (~> 1.3)
|
61
|
+
guard-bundler
|
62
|
+
guard-rspec
|
63
|
+
rake
|
64
|
+
rspec
|
65
|
+
urchin_tracking_module!
|
data/Guardfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
guard 'bundler' do
|
2
|
+
watch('Gemfile')
|
3
|
+
# Uncomment next line if Gemfile contain `gemspec' command
|
4
|
+
# watch(/^.+\.gemspec/)
|
5
|
+
end
|
6
|
+
|
7
|
+
guard :rspec do
|
8
|
+
watch(%r{^spec/.+_spec\.rb$})
|
9
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
10
|
+
watch('spec/spec_helper.rb') { "spec" }
|
11
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Urchin Tracking Module
|
2
|
+
|
3
|
+
Add google analytics params to your URLs.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'utm'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install utm
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
require 'utm'
|
22
|
+
|
23
|
+
UTM("http://example.com/#/welcome",
|
24
|
+
utm_source: "newsletter_de",
|
25
|
+
utm_medium: "email",
|
26
|
+
utm_term: "fashion+leather",
|
27
|
+
utm_content: "Could be the subject line of your email",
|
28
|
+
utm_campaign: "winter_2013" )
|
29
|
+
=> "http://example.com/?utm_source=newsletter_de&utm_medium=email&utm_term=fashion+leather&utm_content=Could+be+the+subject+line+of+your+email&utm_campaign=winter_2013#/welcome"
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Your thought's/improvements are welcome :)
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
40
|
+
|
41
|
+
## TODOs
|
42
|
+
|
43
|
+
* remove dependency to Rails
|
44
|
+
* remove bonusbox specific `src` param or make this kind of
|
45
|
+
additions configurable.
|
46
|
+
* `Utm.configure {|c| c[:utm_source] => nil }` would generate
|
47
|
+
invalid params. It should pick up defaults instead.
|
48
|
+
* `Utm.configure {|c| c[:utm_source] => 'my_app' }` could have a
|
49
|
+
configuration object instead of a hash, to become
|
50
|
+
`Utm.configure {|c| c.utm_source = 'my_app' }`
|
51
|
+
|
52
|
+
## Code status
|
53
|
+
|
54
|
+
* [![Build Status](https://api.travis-ci.org/bonusboxme/urchin_tracking_module.png)](https://travis-ci.org/bonusboxme/urchin_tracking_module)
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
This `urchin_tracking_module` project is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'urchin_tracking_module/version'
|
2
|
+
require 'singleton'
|
3
|
+
require 'active_support/core_ext/hash/slice'
|
4
|
+
|
5
|
+
def UTM(url, params={})
|
6
|
+
Utm.new(url).tracking(params)
|
7
|
+
end
|
8
|
+
|
9
|
+
class UrchinTrackingModule
|
10
|
+
TRACKING_PARAMETERS = %i(utm_source utm_medium utm_term utm_content utm_campaign)
|
11
|
+
|
12
|
+
def initialize(url)
|
13
|
+
@url = url
|
14
|
+
end
|
15
|
+
|
16
|
+
def tracking(params=defaults)
|
17
|
+
filtered_params(params).inject(@url) do |url,(name,value)|
|
18
|
+
url = add_param(url, "#{name}", value)
|
19
|
+
url = add_param(url, "src", value) if name == :utm_source
|
20
|
+
url
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def defaults
|
25
|
+
Utm::Defaults.config
|
26
|
+
end
|
27
|
+
private :defaults
|
28
|
+
|
29
|
+
def filtered_params(params)
|
30
|
+
defaults.merge(params.slice(*TRACKING_PARAMETERS))
|
31
|
+
end
|
32
|
+
private :filtered_params
|
33
|
+
|
34
|
+
def add_param(url, param_name, param_value)
|
35
|
+
uri = URI(url)
|
36
|
+
params = url_params(uri).merge(param_name => param_value)
|
37
|
+
uri.query = URI.encode_www_form(params)
|
38
|
+
uri.to_s
|
39
|
+
end
|
40
|
+
private :add_param
|
41
|
+
|
42
|
+
def url_params(uri)
|
43
|
+
# conversion to hash e.g. to get rid of duplicate src params
|
44
|
+
params = URI.decode_www_form(uri.query || [])
|
45
|
+
params.inject(Hash.new) { |h,(k,v)| h.merge(k => v) }
|
46
|
+
end
|
47
|
+
private :url_params
|
48
|
+
|
49
|
+
def self.configure(&block)
|
50
|
+
Defaults.configure(&block)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.source
|
54
|
+
Defaults.config[:utm_source]
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.medium
|
58
|
+
Defaults.config[:utm_medium]
|
59
|
+
end
|
60
|
+
|
61
|
+
class Defaults
|
62
|
+
include Singleton
|
63
|
+
attr_accessor :defaults
|
64
|
+
|
65
|
+
def self.configure(&block)
|
66
|
+
instance.configure(&block)
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.config
|
70
|
+
instance.defaults
|
71
|
+
end
|
72
|
+
|
73
|
+
def initialize
|
74
|
+
self.defaults = { utm_source: default_source, utm_medium: default_medium }
|
75
|
+
end
|
76
|
+
|
77
|
+
def configure
|
78
|
+
yield self.defaults
|
79
|
+
end
|
80
|
+
|
81
|
+
def default_source
|
82
|
+
Rails.application.class.parent_name
|
83
|
+
end
|
84
|
+
private :default_source
|
85
|
+
|
86
|
+
def default_medium
|
87
|
+
'mail'
|
88
|
+
end
|
89
|
+
private :default_medium
|
90
|
+
end
|
91
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Dir["./support/**/*.rb"].each { |f| require f }
|
2
|
+
|
3
|
+
unless defined?(Rails)
|
4
|
+
module Rails
|
5
|
+
class Application
|
6
|
+
def self.parent_name; "urchin_tracking_module" end
|
7
|
+
end
|
8
|
+
def self.application; Application.new end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.order = "random"
|
14
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Urchin Tracking Module
|
2
|
+
require 'urchin_tracking_module'
|
3
|
+
require 'uri'
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
describe UrchinTrackingModule do
|
7
|
+
Utm = UrchinTrackingModule
|
8
|
+
let(:params) {{}}
|
9
|
+
let(:url) { 'http://example.com?src=fba_blooming/#/shops' }
|
10
|
+
subject { Utm.new(url) }
|
11
|
+
|
12
|
+
context 'basic tracking' do
|
13
|
+
let(:params) {{
|
14
|
+
utm_source: 'transactional_emails',
|
15
|
+
utm_medium: 'email',
|
16
|
+
utm_term: 'electronics',
|
17
|
+
utm_content: 'variant_guy',
|
18
|
+
utm_campaign: 'xmas_2013' }}
|
19
|
+
|
20
|
+
Utm::TRACKING_PARAMETERS.each do |tracking_param|
|
21
|
+
it "tracks #{tracking_param}" do
|
22
|
+
uri = subject.tracking(params)
|
23
|
+
expect(uri).to match(/#{tracking_param}=#{params[tracking_param]}/)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '.configure' do
|
29
|
+
EXAMPLE_CONFIG = {
|
30
|
+
utm_source: 'b2b_application',
|
31
|
+
utm_medium: 'banner300',
|
32
|
+
utm_term: 'fashion',
|
33
|
+
utm_content: 'luxury_goods',
|
34
|
+
utm_campaign: 'spring_2014'
|
35
|
+
}
|
36
|
+
|
37
|
+
EXAMPLE_CONFIG.each do |(name,value)|
|
38
|
+
it "configures #{name}" do
|
39
|
+
Utm.configure { |utm| utm[name]= value }
|
40
|
+
expect(subject.tracking).to match(/#{name}=#{value}/)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'configures src' do
|
45
|
+
# checking for side effects and overrides
|
46
|
+
Utm.configure { |utm| utm[:utm_source]= 'funnel_source_for_bi' }
|
47
|
+
expect(subject.tracking).to match(/src=funnel_source_for_bi/)
|
48
|
+
expect(UTM(url, utm_source: 'pewpew')).to match(/src=pewpew/)
|
49
|
+
expect(UTM(url, utm_source: 'pewpew')).to match(/utm_source=pewpew/)
|
50
|
+
expect(subject.tracking).not_to match(/src=fba_blooming/)
|
51
|
+
expect(subject.tracking).to match(/utm_source=funnel_source_for_bi/)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'configures Utm.source' do
|
56
|
+
Utm.configure { |utm| utm[:utm_source]= EXAMPLE_CONFIG[:utm_source] }
|
57
|
+
expect(Utm.source).to eq EXAMPLE_CONFIG[:utm_source]
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'configures Utm.medium' do
|
61
|
+
Utm.configure { |utm| utm[:utm_medium]= EXAMPLE_CONFIG[:utm_medium] }
|
62
|
+
expect(Utm.medium).to eq EXAMPLE_CONFIG[:utm_medium]
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'UTM helper' do
|
66
|
+
let(:utm) { double }
|
67
|
+
|
68
|
+
it 'invokes Utm' do
|
69
|
+
Utm.should_receive(:new).with(url).and_return(utm)
|
70
|
+
utm.should_receive(:tracking).with(params)
|
71
|
+
UTM(url,params)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'urchin_tracking_module/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "urchin_tracking_module"
|
8
|
+
spec.version = UrchinTrackingModule::VERSION
|
9
|
+
spec.authors = ["Jan Riethmayer"]
|
10
|
+
spec.email = ["jan@riethmayer.de"]
|
11
|
+
spec.description = %q{Add google analytics urchin tracking module params to your URL.}
|
12
|
+
spec.summary = %q{utm params for your URL.}
|
13
|
+
spec.homepage = "http://github.com/bonusboxme/urchin_tracking_module"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: urchin_tracking_module
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan Riethmayer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Add google analytics urchin tracking module params to your URL.
|
42
|
+
email:
|
43
|
+
- jan@riethmayer.de
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .ruby-gemset
|
50
|
+
- .ruby-version
|
51
|
+
- .travis.yml
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- Guardfile
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- lib/urchin_tracking_module.rb
|
58
|
+
- lib/urchin_tracking_module/version.rb
|
59
|
+
- spec/spec_helper.rb
|
60
|
+
- spec/urchin_tracking_module_spec.rb
|
61
|
+
- urchin_tracking_module.gemspec
|
62
|
+
homepage: http://github.com/bonusboxme/urchin_tracking_module
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.0.3
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: utm params for your URL.
|
86
|
+
test_files:
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
- spec/urchin_tracking_module_spec.rb
|
89
|
+
has_rdoc:
|