analytics_instrumentation 0.1.5 → 0.1.6

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: a2153b9c13c4a12c4f9109c5693ff93d9eaa93a3
4
- data.tar.gz: 1aba06ff204ae0a490ed954bf447bff1fe282dd3
3
+ metadata.gz: ff0321bb8effd93476013ff31e7aa07320119786
4
+ data.tar.gz: ca34cd660ff84ca6b73c6c4776869223a18dcd33
5
5
  SHA512:
6
- metadata.gz: d9243c70c77838a29109126e239682a1266c683a7507134fc7baabac98c924d0cac050d43aa32000b93977cc276813ea858965c4a092da29cc00ee4b769cab89
7
- data.tar.gz: 3a2cb4247846e20d47d06a2211af12f9387489f219e42113d94681cfa12bf261805851d37cfd11fa0c0c1497525b4eea89c76ccec2c226c3355902c9076e62f9
6
+ metadata.gz: fdf6916c194864a4b422be5844304c80cd7c67d7df8e464035f7e19370b175c65fa5a6402e9e2eb256aebabd94dbaac238f419f5bd602b46128c38de4c5165df
7
+ data.tar.gz: 5f3e519d10cb4eae86b5de47a9faec15ab51c28fc7af667024454f333963e49dc94cb8eb6f7382da8323712d47112d322ccc1187bd796ed45b6f12cd15923c59
@@ -40,7 +40,10 @@ module AnalyticsInstrumentation
40
40
  if !session[:last_seen] || session[:last_seen] < 30.minutes.ago
41
41
  analyticsTrackEvent("Session Start")
42
42
  if @@config.intercom? && Rails.env.production?
43
- Intercom.post("https://api.intercom.io/users", {user_id:current_user.id, new_session:true})
43
+ begin
44
+ Intercom.post("https://api.intercom.io/users", {user_id:current_user.id, new_session:true})
45
+ rescue
46
+ end
44
47
  end
45
48
  end
46
49
  session[:last_seen] = Time.now
@@ -115,7 +118,11 @@ module AnalyticsInstrumentation
115
118
 
116
119
  properties = {
117
120
  user_id: user.id,
118
- traits: (user_traits||{})
121
+ traits: (user_traits||{}),
122
+ integrations: {
123
+ # Don't send leads to C.io if they don't have an email
124
+ "Customer.io" => (!user.email.blank?)
125
+ }
119
126
  }
120
127
 
121
128
  logger.debug "Analytics.identify #{JSON.pretty_generate(properties)}"
@@ -125,16 +132,12 @@ module AnalyticsInstrumentation
125
132
  def analyticsSuperProperties
126
133
  superProperties = {
127
134
  "Raw Analytics ID" => raw_analytics_id,
128
- "Ajax" => !request.xhr?.nil?
135
+ "Ajax" => !request.xhr?.nil?,
136
+ "Platform" => analyticsPlatform
129
137
  }
130
138
  if current_user
131
- superProperties.merge!({
132
- "User Created At" => current_user.created_at,
133
- "Username" => current_user.try(:username),
134
- "Full name" => current_user.try(:full_name),
135
- "User ID" => current_user.id,
136
- "Login Provider" => current_user.try(:provider) || "Email"
137
- })
139
+ user_traits = instance_exec(user, &@@config.custom_user_traits)
140
+ superProperties.merge!({user:user_traits}) if user_traits
138
141
  end
139
142
  superProperties
140
143
  end
@@ -165,6 +168,10 @@ module AnalyticsInstrumentation
165
168
  'Google Analytics' => {
166
169
  clientId: googleAnalyticsID
167
170
  }
171
+ },
172
+ integrations: {
173
+ # Don't send leads to C.io if they don't have an email
174
+ "Customer.io" => !!current_user
168
175
  }
169
176
  }
170
177
 
@@ -183,6 +190,15 @@ module AnalyticsInstrumentation
183
190
  end
184
191
 
185
192
  private
193
+ def analyticsPlatform
194
+ case
195
+ when browser.mobile? then "Mobile"
196
+ when browser.platform != :other then "Desktop"
197
+ else
198
+ "Other"
199
+ end
200
+ end
201
+
186
202
  def googleAnalyticsID
187
203
  ck = cookies[:_ga]
188
204
  return "1.1" if ck.nil?
@@ -194,7 +210,7 @@ module AnalyticsInstrumentation
194
210
  return true if Rails.env.test?
195
211
  return true if request.bot?
196
212
  return true if request.user_agent.nil?
197
- bad_strings = ["http:", "https:", "twitterbot", "bingbot", "googlebot", "gediapartners-google"]
213
+ bad_strings = ["http:", "https:", "twitterbot", "bingbot", "googlebot", "mediapartners-google", "Webhook"]
198
214
  return true if bad_strings.any? { |s| !request.user_agent.downcase.index(s).nil? }
199
215
  false
200
216
  end
@@ -1,3 +1,3 @@
1
1
  module AnalyticsInstrumentation
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
data/lib/config/routes.rb CHANGED
@@ -1,6 +1,4 @@
1
- # TODO: Not namespace this
2
-
3
- CanopyBackend::Application.routes.draw do
1
+ Rails.application.routes.draw do
4
2
 
5
3
  post "api/analytics_event" => "analytics_implementation#analytics_event", as: :analytics_event
6
4
 
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ class AnalyticsInstrumentationTest < ActiveSupport::TestCase
4
+ test "All analytics routes are valid" do
5
+ mappings = AnalyticsMapping.createMappings
6
+ for method in mappings.keys
7
+ controller, action = method.to_s.split("__")
8
+ begin
9
+ Rails.application.routes.url_helpers.url_for(controller: controller, action: action, id: 1, slug: "a", page: 1, issue_number: 1, user_id: 1, username: 'a', user_collection_id: 1, followable_type: "User", followable_id: 1, host: "canopy.co")
10
+ rescue
11
+ throw "No route for route with analytics instrumentation: #{method}"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -4,4 +4,10 @@ class AnalyticsInstrumentationTest < ActiveSupport::TestCase
4
4
  test "truth" do
5
5
  assert_kind_of Module, AnalyticsInstrumentation
6
6
  end
7
+
8
+ test "C.io wont see users without emails" do
9
+ assert false, "TODO"
10
+ end
11
+
12
+
7
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: analytics_instrumentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Feldstein
@@ -9,62 +9,76 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-31 00:00:00.000000000 Z
12
+ date: 2015-04-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '4.2'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '4.2'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: analytics-ruby
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ~>
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '2.0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ~>
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '2.0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: voight_kampff
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ~>
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ~>
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: browser
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.8'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.8'
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: sqlite3
58
72
  requirement: !ruby/object:Gem::Requirement
59
73
  requirements:
60
- - - ~>
74
+ - - "~>"
61
75
  - !ruby/object:Gem::Version
62
76
  version: '0'
63
77
  type: :development
64
78
  prerelease: false
65
79
  version_requirements: !ruby/object:Gem::Requirement
66
80
  requirements:
67
- - - ~>
81
+ - - "~>"
68
82
  - !ruby/object:Gem::Version
69
83
  version: '0'
70
84
  description: "Add analytics to any app, quickly, robustly, and accurately. \n\nDefine
@@ -89,7 +103,7 @@ files:
89
103
  - lib/config/routes.rb
90
104
  - lib/controllers/analytics_implementation_controller.rb
91
105
  - lib/controllers/application_controller.rb
92
- - lib/tasks/analytics_instrumentation_tasks.rake
106
+ - lib/test/integration/analytics_instrumentation_test.rb
93
107
  - test/analytics_instrumentation_test.rb
94
108
  - test/dummy/README.rdoc
95
109
  - test/dummy/Rakefile
@@ -136,17 +150,17 @@ require_paths:
136
150
  - lib
137
151
  required_ruby_version: !ruby/object:Gem::Requirement
138
152
  requirements:
139
- - - '>='
153
+ - - ">="
140
154
  - !ruby/object:Gem::Version
141
155
  version: '0'
142
156
  required_rubygems_version: !ruby/object:Gem::Requirement
143
157
  requirements:
144
- - - '>='
158
+ - - ">="
145
159
  - !ruby/object:Gem::Version
146
160
  version: '0'
147
161
  requirements: []
148
162
  rubyforge_project:
149
- rubygems_version: 2.4.1
163
+ rubygems_version: 2.4.3
150
164
  signing_key:
151
165
  specification_version: 4
152
166
  summary: Best-practices analytics instrumentation for Rails.
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :analytics_instrumentation do
3
- # # Task goes here
4
- # end