analytics_instrumentation 0.1.0 → 0.1.1

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: 23edc0fcddb60777d22506a73d5644a823beed1d
4
- data.tar.gz: 7229fb73b5606f178e55dbaba1df3be2c2b09e34
3
+ metadata.gz: 541748eba4bb7231b1f791d55aefadd26f8c7bb6
4
+ data.tar.gz: 71dd90eae86fd384c104f90bbd5ccda2c7c432dc
5
5
  SHA512:
6
- metadata.gz: d092014e81ee505b97ca8b5d6f47d8671c492513e0f1367276073b672c21b1da74cbb8e07efe7d561b59946d73f12b8d0a0f9985f254ff8575a588143128402e
7
- data.tar.gz: ab0dd4da0f9d16afb9944b75109a424696643736e84a74a4e55d424d5102bc431e139809b31bb215110fa53e8772fbc29a59df07293e28d8aa69f628bedb642c
6
+ metadata.gz: 4ca866ab4932e2c585fb74bf3351a7aeb1dc28be0d0f4d696188d49545a5c3b689e5856b240502d60ed83b335a21554201b64c30e67ab126d4f20d938d0521a3
7
+ data.tar.gz: 32b8f3dd99d9877309908d5844adb3da6ac241ef358a1ebafd61d08aa721bc396705d7872ef3b80e02226985824f06bab80fd623e1d9f6fa81166e92d92d3353
data/README.rdoc CHANGED
@@ -13,7 +13,7 @@ or
13
13
 
14
14
  Once installed, write your initializer and yml mappings.
15
15
 
16
- == Initializer & Defaults
16
+ == Initializer
17
17
 
18
18
  Most behaviors in AnalyticsInstrumentation are one-size-fits-all.
19
19
 
@@ -28,7 +28,7 @@ The behaviors exposed are:
28
28
  config.segment_write_key = ENV["SEGMENT_API_KEY"] || ""
29
29
 
30
30
  # Define a hash of traits to be passed to `#identify()` calls for each user.
31
- config.custom_user_traits = (user) -> {
31
+ config.custom_user_traits = Proc.new { |user|
32
32
  {
33
33
  name: user.full_name,
34
34
  email: user.email,
@@ -47,7 +47,7 @@ The behaviors exposed are:
47
47
  # 1. Event-specific properties are configured via the YML files (see below)
48
48
  # 2. System-wide properties are included for you with all events (see below)
49
49
  # 3. To have your own system-wide properties included on all events, have them returned by a Proc set to `config.extra_event_properties`, like so:
50
- config.extra_event_properties = -> {
50
+ config.extra_event_properties = Proc.new {
51
51
  {
52
52
  user_sees_experiment_a: current_user.experiment_a?
53
53
  user_sees_experiment_b: current_user.experiment_b?
@@ -56,16 +56,16 @@ The behaviors exposed are:
56
56
 
57
57
  # To capture and handle errors that happen within AnalyticsInstrumentation,
58
58
  # Define an error_handler, like so:
59
- config.error_handler = (e, msg) -> {
59
+ config.error_handler = Proc.new { |e, msg|
60
60
  if Rails.env.production?
61
- Rollbar.error(e, msg)
61
+ Rollbar.error(e, msg) # or Airbrake, etc
62
62
  else
63
63
  raise
64
64
  end
65
65
  }
66
66
  end
67
67
 
68
- == Configuring Events & Their Properties
68
+ == YML Mappings: Named Events & Properties
69
69
 
70
70
  AnalyticsInstrumentation maps controller#action pairs to events using YML files in `./config/analytics/*.yml`.
71
71
 
@@ -1,14 +1,19 @@
1
+ require 'active_model'
2
+ require 'segment/analytics'
3
+ require 'voight_kampff'
4
+
1
5
  require 'analytics_instrumentation/analytics_attribution'
2
6
  require 'analytics_instrumentation/analytics_mapping'
7
+ require 'analytics_instrumentation/config'
3
8
 
4
9
  module AnalyticsInstrumentation
5
10
  include AnalyticsAttribution
6
11
 
7
12
  class << self
8
13
  def included(base)
9
- @segment = Segment::Analytics.new({
10
- write_key: @config.segment_write_key,
11
- on_error: @config.error_handler
14
+ @@segment = Segment::Analytics.new({
15
+ write_key: @@config.segment_write_key,
16
+ on_error: @@config.error_handler
12
17
  })
13
18
 
14
19
  base.class_eval do
@@ -18,13 +23,13 @@ module AnalyticsInstrumentation
18
23
  end
19
24
 
20
25
  def configure(&proc)
21
- @config ||= Config.new
22
- yield @config
26
+ @@config ||= AnalyticsInstrumentation::Config.new
27
+ yield @@config
23
28
 
24
- unless @config.valid?
25
- errors = @config.errors.full_messages.join(', ')
26
- raise Config::Invalid.new(errors)
27
- end
29
+ # unless @config.valid?
30
+ # errors = @config.errors.full_messages.join(', ')
31
+ # raise AnalyticsInstrumentation::Config::Invalid.new(errors)
32
+ # end
28
33
  end
29
34
  end
30
35
 
@@ -34,7 +39,7 @@ module AnalyticsInstrumentation
34
39
  if current_user
35
40
  if !session[:last_seen] || session[:last_seen] < 30.minutes.ago
36
41
  analyticsTrackEvent("Session Start")
37
- if @config.intercom? && Rails.env.production?
42
+ if @@config.intercom? && Rails.env.production?
38
43
  Intercom.post("https://api.intercom.io/users", {user_id:current_user.id, new_session:true})
39
44
  end
40
45
  end
@@ -46,7 +51,11 @@ module AnalyticsInstrumentation
46
51
  session[:last_seen_logged_out] = Time.now
47
52
  end
48
53
  rescue => e
49
- @config.error_handler(e, "Analytics Check Session Crash: #{request.filtered_path}")
54
+ puts "FOUND ERROR #{e.inspect}"
55
+ puts caller
56
+ puts @@config.inspect
57
+ puts @@config.error_handler.inspect
58
+ @@config.error_handler(e, "Analytics Check Session Crash: #{request.filtered_path}")
50
59
  end
51
60
  end
52
61
 
@@ -72,7 +81,7 @@ module AnalyticsInstrumentation
72
81
  properties.merge! analyticsSuperProperties
73
82
  analyticsTrackEvent "Page View", properties
74
83
  rescue => e
75
- @config.error_handler(e, "Analytics Crash: #{request.filtered_path}")
84
+ @@config.error_handler(e, "Analytics Crash: #{request.filtered_path}")
76
85
  end
77
86
  end
78
87
 
@@ -97,8 +106,8 @@ module AnalyticsInstrumentation
97
106
  }
98
107
 
99
108
  logger.debug "Analytics.alias #{aliasProperties}"
100
- @segment.alias(aliasProperties)
101
- @segment.flush
109
+ @@segment.alias(aliasProperties)
110
+ @@segment.flush
102
111
  end
103
112
 
104
113
  def analyticsSetPerson(user)
@@ -106,11 +115,11 @@ module AnalyticsInstrumentation
106
115
 
107
116
  properties = {
108
117
  user_id: user.id,
109
- traits: @config.custom_user_traits(user)
118
+ traits: @@config.custom_user_traits(user)
110
119
  }
111
120
 
112
121
  logger.debug "Analytics.identify #{JSON.pretty_generate(properties)}"
113
- @segment.identify(properties)
122
+ @@segment.identify(properties)
114
123
  end
115
124
 
116
125
  def analyticsSuperProperties
@@ -139,7 +148,7 @@ module AnalyticsInstrumentation
139
148
  properties["source"] = params[:source] if params[:source]
140
149
 
141
150
  properties.merge! analyticsSuperProperties
142
- properties.merge! @config.extra_event_properties
151
+ properties.merge! @@config.extra_event_properties
143
152
 
144
153
  analyticsApplyOriginatingPage properties
145
154
 
@@ -157,7 +166,7 @@ module AnalyticsInstrumentation
157
166
  }
158
167
 
159
168
  logger.debug "Analytics.track #{JSON.pretty_generate(analyticsProperties)}"
160
- @segment.track(analyticsProperties)
169
+ @@segment.track(analyticsProperties)
161
170
  end
162
171
 
163
172
  def raw_analytics_id
@@ -16,18 +16,19 @@ module AnalyticsInstrumentation
16
16
  :custom_user_traits,
17
17
  :error_handler
18
18
  ]
19
+
19
20
  validate do
20
- @@REQUIRED_CALLABLES.each |callable| do
21
- unless self.send(callable).respond_to?(:call)
22
- errors.add(callable, "must be a callable object (eg. Proc)")
21
+ @@REQUIRED_CALLABLES.each do |callable|
22
+ unless self.send(callable).is_a?(Proc)
23
+ errors.add(callable, "must be a Proc")
23
24
  end
24
25
  end
25
26
  end
26
27
 
27
28
  def initialize
28
- self.extra_event_properties = -> {}
29
- self.custom_user_traits = -> {}
30
- self.error_handler = (msg) -> { raise }
29
+ self.extra_event_properties = Proc.new {}
30
+ self.custom_user_traits = Proc.new {}
31
+ self.error_handler = Proc.new { |e, msg=""| raise }
31
32
  end
32
33
 
33
34
  def custom_user_traits(user)
@@ -1,3 +1,3 @@
1
1
  module AnalyticsInstrumentation
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Feldstein
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-29 00:00:00.000000000 Z
12
+ date: 2015-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails