event_tracker 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 +4 -4
- data/CHANGELOG.md +6 -0
- data/event_tracker.gemspec +2 -2
- data/lib/event_tracker.rb +35 -61
- data/lib/event_tracker/integration.rb +16 -0
- data/lib/event_tracker/integration/base.rb +13 -0
- data/lib/event_tracker/{google_analytics.rb → integration/google_analytics.rb} +1 -5
- data/lib/event_tracker/{kissmetrics.rb → integration/kissmetrics.rb} +3 -7
- data/lib/event_tracker/{mixpanel.rb → integration/mixpanel.rb} +8 -12
- data/lib/event_tracker/version.rb +1 -1
- data/spec/event_tracker_spec.rb +5 -5
- data/spec/spec_helper.rb +0 -1
- metadata +25 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14869ca74719eb114deaf73ce4da6edd9685a7d8
|
4
|
+
data.tar.gz: 81d3f06adccf5a96fa3860382169c2cbd92db7d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5882e8505b278c934871e46e55516a36d3fc5b05bc45248b7462c6911f2f61b6c35d3644af7db114014f59563c013f31dc28ec52b7f3886e9fd3d86e0b60e784
|
7
|
+
data.tar.gz: 9c496b64dc3aae6c73bdbd8e034f57ac1fdd5ba95a0161f3cd62ac042ef209e43ac02a73bf51ecc574cf9a4ee5c49d10810a4207d19c1d8bcaf8b76d243ed24f
|
data/CHANGELOG.md
ADDED
data/event_tracker.gemspec
CHANGED
@@ -16,6 +16,6 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = EventTracker::VERSION
|
17
17
|
|
18
18
|
gem.add_dependency 'rails', '>= 3.0'
|
19
|
-
gem.add_development_dependency '
|
20
|
-
gem.add_development_dependency '
|
19
|
+
gem.add_development_dependency 'capybara', '>= 2.1'
|
20
|
+
gem.add_development_dependency 'rspec-rails'
|
21
21
|
end
|
data/lib/event_tracker.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require "event_tracker/version"
|
2
|
-
require "event_tracker/
|
3
|
-
require "event_tracker/
|
4
|
-
require "event_tracker/
|
2
|
+
require "event_tracker/integration"
|
3
|
+
require "event_tracker/integration/base"
|
4
|
+
require "event_tracker/integration/mixpanel"
|
5
|
+
require "event_tracker/integration/kissmetrics"
|
6
|
+
require "event_tracker/integration/google_analytics"
|
5
7
|
|
6
8
|
module EventTracker
|
7
9
|
module HelperMethods
|
@@ -35,38 +37,8 @@ module EventTracker
|
|
35
37
|
end
|
36
38
|
|
37
39
|
module ActionControllerExtension
|
38
|
-
def mixpanel_tracker
|
39
|
-
@mixpanel_tracker ||= begin
|
40
|
-
mixpanel_key = Rails.application.config.event_tracker.mixpanel_key
|
41
|
-
EventTracker::Mixpanel.new(mixpanel_key) if mixpanel_key
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def kissmetrics_tracker
|
46
|
-
@kissmetrics_tracker ||= begin
|
47
|
-
kissmetrics_key = Rails.application.config.event_tracker.kissmetrics_key
|
48
|
-
EventTracker::Kissmetrics.new(kissmetrics_key) if kissmetrics_key
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def google_analytics_tracker
|
53
|
-
@google_analytics_tracker ||= begin
|
54
|
-
google_analytics_key = Rails.application.config.event_tracker.google_analytics_key
|
55
|
-
EventTracker::GoogleAnalytics.new(google_analytics_key) if google_analytics_key
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def event_trackers
|
60
|
-
@event_trackers ||= begin
|
61
|
-
trackers = []
|
62
|
-
trackers << mixpanel_tracker if mixpanel_tracker
|
63
|
-
trackers << kissmetrics_tracker if kissmetrics_tracker
|
64
|
-
trackers << google_analytics_tracker if google_analytics_tracker
|
65
|
-
trackers
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
40
|
def append_event_tracking_tags
|
41
|
+
event_trackers = EventTracker::Integration.configured
|
70
42
|
yield
|
71
43
|
return if event_trackers.empty?
|
72
44
|
|
@@ -79,40 +51,42 @@ module EventTracker
|
|
79
51
|
return unless body_insert_at
|
80
52
|
|
81
53
|
a = []
|
82
|
-
|
83
|
-
|
84
|
-
elsif distinct_id = respond_to?(:mixpanel_distinct_id, true) && mixpanel_distinct_id
|
85
|
-
a << mixpanel_tracker.identify(distinct_id)
|
86
|
-
end
|
87
|
-
|
88
|
-
if name_tag = respond_to?(:mixpanel_name_tag, true) && mixpanel_name_tag
|
89
|
-
a << mixpanel_tracker.name_tag(name_tag)
|
90
|
-
end
|
54
|
+
registered_properties = session.delete(:registered_properties)
|
55
|
+
event_tracker_queue = session.delete(:event_tracker_queue)
|
91
56
|
|
92
|
-
|
93
|
-
|
94
|
-
|
57
|
+
event_trackers.each do |tracker|
|
58
|
+
if tracker.is_a?(EventTracker::Integration::Mixpanel)
|
59
|
+
if mixpanel_alias = session.delete(:mixpanel_alias)
|
60
|
+
a << tracker.alias(mixpanel_alias)
|
61
|
+
elsif distinct_id = respond_to?(:mixpanel_distinct_id, true) && mixpanel_distinct_id
|
62
|
+
a << tracker.identify(distinct_id)
|
63
|
+
end
|
95
64
|
|
96
|
-
|
97
|
-
|
98
|
-
|
65
|
+
if name_tag = respond_to?(:mixpanel_name_tag, true) && mixpanel_name_tag
|
66
|
+
a << tracker.name_tag(name_tag)
|
67
|
+
end
|
99
68
|
|
100
|
-
|
101
|
-
|
102
|
-
|
69
|
+
if (config = session.delete(:mixpanel_set_config)).present?
|
70
|
+
a << tracker.set_config(config)
|
71
|
+
end
|
103
72
|
|
104
|
-
|
105
|
-
|
106
|
-
|
73
|
+
if (people = session.delete(:mixpanel_people_set)).present?
|
74
|
+
a << tracker.people_set(people)
|
75
|
+
end
|
107
76
|
|
108
|
-
|
109
|
-
|
110
|
-
|
77
|
+
if (people = session.delete(:mixpanel_people_set_once)).present?
|
78
|
+
a << tracker.people_set_once(people)
|
79
|
+
end
|
111
80
|
|
112
|
-
|
113
|
-
|
81
|
+
if (people = session.delete(:mixpanel_people_increment)).present?
|
82
|
+
a << tracker.people_increment(people)
|
83
|
+
end
|
84
|
+
elsif tracker.is_a?(EventTracker::Integration::Kissmetrics)
|
85
|
+
if identity = respond_to?(:kissmetrics_identity, true) && kissmetrics_identity
|
86
|
+
a << tracker.identify(identity)
|
87
|
+
end
|
88
|
+
end
|
114
89
|
|
115
|
-
event_trackers.each do |tracker|
|
116
90
|
a << tracker.register(registered_properties) if registered_properties.present? && tracker.respond_to?(:register)
|
117
91
|
|
118
92
|
if event_tracker_queue.present?
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module EventTracker::Integration
|
2
|
+
def self.configured
|
3
|
+
@configured ||= begin
|
4
|
+
trackers = []
|
5
|
+
integrations = [Mixpanel, Kissmetrics, GoogleAnalytics ]
|
6
|
+
integrations.each do |integration|
|
7
|
+
key_string = "#{integration.to_s.demodulize.underscore}_key"
|
8
|
+
key = Rails.application.config.event_tracker[key_string]
|
9
|
+
if key
|
10
|
+
trackers << integration.new(key)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
trackers
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,8 +1,4 @@
|
|
1
|
-
class EventTracker::Kissmetrics
|
2
|
-
def initialize(key)
|
3
|
-
@key = key
|
4
|
-
end
|
5
|
-
|
1
|
+
class EventTracker::Integration::Kissmetrics < EventTracker::Integration::Base
|
6
2
|
def init
|
7
3
|
<<-EOD
|
8
4
|
var _kmq = _kmq || [];
|
@@ -21,11 +17,11 @@ class EventTracker::Kissmetrics
|
|
21
17
|
end
|
22
18
|
|
23
19
|
def register(registered_properties)
|
24
|
-
%Q{_kmq.push(['set', #{registered_properties
|
20
|
+
%Q{_kmq.push(['set', #{embeddable_json(registered_properties)}]);}
|
25
21
|
end
|
26
22
|
|
27
23
|
def track(event_name, properties)
|
28
|
-
p = properties.empty? ? "" : ", #{properties
|
24
|
+
p = properties.empty? ? "" : ", #{embeddable_json(properties)}"
|
29
25
|
%Q{_kmq.push(['record', '#{event_name}'#{p}]);}
|
30
26
|
end
|
31
27
|
|
@@ -1,8 +1,4 @@
|
|
1
|
-
class EventTracker::Mixpanel
|
2
|
-
def initialize(key)
|
3
|
-
@key = key
|
4
|
-
end
|
5
|
-
|
1
|
+
class EventTracker::Integration::Mixpanel < EventTracker::Integration::Base
|
6
2
|
def init
|
7
3
|
s = <<-EOD
|
8
4
|
(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;a=e.createElement("script");
|
@@ -20,11 +16,11 @@ class EventTracker::Mixpanel
|
|
20
16
|
end
|
21
17
|
|
22
18
|
def register(registered_properties)
|
23
|
-
%Q{mixpanel.register(#{registered_properties
|
19
|
+
%Q{mixpanel.register(#{embeddable_json(registered_properties)});}
|
24
20
|
end
|
25
21
|
|
26
22
|
def track(event_name, properties)
|
27
|
-
p = properties.empty? ? "" : ", #{properties
|
23
|
+
p = properties.empty? ? "" : ", #{embeddable_json(properties)}"
|
28
24
|
%Q{mixpanel.track("#{event_name}"#{p});}
|
29
25
|
end
|
30
26
|
|
@@ -37,22 +33,22 @@ class EventTracker::Mixpanel
|
|
37
33
|
end
|
38
34
|
|
39
35
|
def people_set(properties)
|
40
|
-
%Q{mixpanel.people.set(#{properties
|
36
|
+
%Q{mixpanel.people.set(#{embeddable_json(properties)});}
|
41
37
|
end
|
42
38
|
|
43
39
|
def people_set_once(properties)
|
44
|
-
%Q{mixpanel.people.set_once(#{properties
|
40
|
+
%Q{mixpanel.people.set_once(#{embeddable_json(properties)});}
|
45
41
|
end
|
46
42
|
|
47
43
|
def people_increment(properties)
|
48
|
-
%Q{mixpanel.people.increment(#{properties
|
44
|
+
%Q{mixpanel.people.increment(#{embeddable_json(properties)});}
|
49
45
|
end
|
50
46
|
|
51
47
|
def set_config(properties)
|
52
|
-
%Q{mixpanel.set_config(#{properties
|
48
|
+
%Q{mixpanel.set_config(#{embeddable_json(properties)});}
|
53
49
|
end
|
54
50
|
|
55
51
|
def alias(identity)
|
56
|
-
%Q{mixpanel.alias(#{identity
|
52
|
+
%Q{mixpanel.alias(#{embeddable_json(identity)});}
|
57
53
|
end
|
58
54
|
end
|
data/spec/event_tracker_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
shared_examples_for "init" do
|
4
|
-
subject { page.find("head script").native.content }
|
4
|
+
subject { page.find("head script", visible: false).native.content }
|
5
5
|
it { should include('mixpanel.init("YOUR_TOKEN")') }
|
6
6
|
it { should include(%q{var _kmk = _kmk || 'KISSMETRICS_KEY'}) }
|
7
7
|
it { should include(%q{ga('create', 'GOOGLE_ANALYTICS_KEY', 'auto', {'name': 'event_tracker'});}) }
|
@@ -29,7 +29,7 @@ shared_examples_for "with event" do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
feature 'basic integration' do
|
32
|
-
subject { page.find("body script").native.content }
|
32
|
+
subject { page.find("body script", visible: false).native.content }
|
33
33
|
|
34
34
|
class BasicController < ApplicationController
|
35
35
|
around_filter :append_event_tracking_tags
|
@@ -94,16 +94,16 @@ feature 'basic integration' do
|
|
94
94
|
def index
|
95
95
|
register_properties age: 19
|
96
96
|
register_properties gender: "female"
|
97
|
-
track_event "Take an action", property1: "a", property2: 1
|
97
|
+
track_event "Take an action", property1: "a", property2: 1, xss: "</script>"
|
98
98
|
render inline: "OK", layout: true
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
102
|
context "track event with properties" do
|
103
103
|
background { visit "/with_properties" }
|
104
|
-
it { should include %
|
104
|
+
it { should include %q{mixpanel.track("Take an action", {"property1":"a","property2":1,"xss":"\u003c/script\u003e"})} }
|
105
105
|
it { should include %Q{mixpanel.register({"age":19,"gender":"female"})} }
|
106
|
-
it { should include %
|
106
|
+
it { should include %q{_kmq.push(['record', 'Take an action', {"property1":"a","property2":1,"xss":"\u003c/script\u003e"}])} }
|
107
107
|
it { should include %Q{_kmq.push(['set', {"age":19,"gender":"female"}])} }
|
108
108
|
end
|
109
109
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event_tracker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul McMahon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.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
26
|
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: capybara
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.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: '
|
40
|
+
version: '2.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec-rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
description: Easy integration with Mixpanel, Kissmetrics, and Google Analytics for
|
56
56
|
Rails
|
57
57
|
email:
|
@@ -60,16 +60,19 @@ executables: []
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
-
- .gitignore
|
63
|
+
- ".gitignore"
|
64
|
+
- CHANGELOG.md
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE
|
66
67
|
- README.md
|
67
68
|
- Rakefile
|
68
69
|
- event_tracker.gemspec
|
69
70
|
- lib/event_tracker.rb
|
70
|
-
- lib/event_tracker/
|
71
|
-
- lib/event_tracker/
|
72
|
-
- lib/event_tracker/
|
71
|
+
- lib/event_tracker/integration.rb
|
72
|
+
- lib/event_tracker/integration/base.rb
|
73
|
+
- lib/event_tracker/integration/google_analytics.rb
|
74
|
+
- lib/event_tracker/integration/kissmetrics.rb
|
75
|
+
- lib/event_tracker/integration/mixpanel.rb
|
73
76
|
- lib/event_tracker/version.rb
|
74
77
|
- spec/app/views/basic/in_views.html.erb
|
75
78
|
- spec/app/views/layouts/application.html.erb
|
@@ -84,17 +87,17 @@ require_paths:
|
|
84
87
|
- lib
|
85
88
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
89
|
requirements:
|
87
|
-
- -
|
90
|
+
- - ">="
|
88
91
|
- !ruby/object:Gem::Version
|
89
92
|
version: '0'
|
90
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
94
|
requirements:
|
92
|
-
- -
|
95
|
+
- - ">="
|
93
96
|
- !ruby/object:Gem::Version
|
94
97
|
version: '0'
|
95
98
|
requirements: []
|
96
99
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
100
|
+
rubygems_version: 2.2.3
|
98
101
|
signing_key:
|
99
102
|
specification_version: 4
|
100
103
|
summary: Track using javascript from your controllers, even when redirecting
|
@@ -103,3 +106,4 @@ test_files:
|
|
103
106
|
- spec/app/views/layouts/application.html.erb
|
104
107
|
- spec/event_tracker_spec.rb
|
105
108
|
- spec/spec_helper.rb
|
109
|
+
has_rdoc:
|