analytics-ruby 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  analytics-ruby (0.5.4)
5
- faraday (>= 0.8, < 0.10)
5
+ faraday (>= 0.8)
6
6
  faraday_middleware (>= 0.8, < 0.10)
7
7
  multi_json (~> 1.0)
8
8
 
data/History.md CHANGED
@@ -1,3 +1,8 @@
1
+ 0.6.0 / 2014-02-19
2
+ ==================
3
+ * adding .group(), .page(), and .screen() calls
4
+ * relaxing faraday dependency, fixes #31
5
+
1
6
  0.5.4 / 2013-12-31
2
7
  ==================
3
8
  * Add `requestId` fields to all requests for tracing.
@@ -16,7 +21,7 @@
16
21
 
17
22
  0.5.0 / 2013-10-03
18
23
  ==================
19
- * Removing global Analytics alias in favor of adding it to our config. NOTE: If you are upgrading from a previous version and want to continue using the `Analytics` namespace, you'll have to add `Analytics = AnalyticsRuby` to your config. Otherwise you WILL NOT be sending analytics data. See the [setup docs for more info](https://segment.io/libraries/ruby)
24
+ * Removing global Analytics constant in favor of adding it to our config. NOTE: If you are upgrading from a previous version and want to continue using the `Analytics` namespace, you'll have to add `Analytics = AnalyticsRuby` to your config. Otherwise you WILL NOT be sending analytics data. See the [setup docs for more info](https://segment.io/libraries/ruby)
20
25
 
21
26
  0.4.0 / 2013-08-30
22
27
  ==================
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.homepage = 'https://github.com/segmentio/analytics-ruby'
16
16
  spec.license = 'MIT'
17
17
 
18
- spec.add_dependency 'faraday', ['>= 0.8', '< 0.10']
18
+ spec.add_dependency 'faraday', ['>= 0.8']
19
19
  spec.add_dependency 'faraday_middleware', ['>= 0.8', '< 0.10']
20
20
  spec.add_dependency 'multi_json', ['~> 1.0']
21
21
 
@@ -23,6 +23,21 @@ module AnalyticsRuby
23
23
  @client.alias options
24
24
  end
25
25
 
26
+ def group(options)
27
+ return false unless @client
28
+ @client.group options
29
+ end
30
+
31
+ def page(options)
32
+ return false unless @client
33
+ @client.page options
34
+ end
35
+
36
+ def screen(options)
37
+ return false unless @client
38
+ @client.screen options
39
+ end
40
+
26
41
  def flush
27
42
  return false unless @client
28
43
  @client.flush
@@ -159,6 +159,108 @@ module AnalyticsRuby
159
159
  })
160
160
  end
161
161
 
162
+ # public: Associates a user identity with a group.
163
+ #
164
+ # options - Hash
165
+ # :from - String of the id to alias from
166
+ # :to - String of the id to alias to
167
+ # :timestamp - Time of when the alias occured (optional)
168
+ # :context - Hash of context (optional)
169
+ def group(options)
170
+ check_secret
171
+ Util.symbolize_keys! options
172
+ group_id = options[:group_id].to_s
173
+ user_id = options[:user_id].to_s
174
+ traits = options[:traits] || {}
175
+ timestamp = options[:timestamp] || Time.new
176
+ context = options[:context] || {}
177
+
178
+ fail ArgumentError, '.traits must be a hash' unless traits.is_a? Hash
179
+
180
+ ensure_user group_id
181
+ ensure_user user_id
182
+ check_timestamp timestamp
183
+ add_context context
184
+
185
+ enqueue({
186
+ :groupId => group_id,
187
+ :userId => user_id,
188
+ :traits => traits,
189
+ :context => context,
190
+ :timestamp => timestamp.iso8601,
191
+ :action => 'group'
192
+ })
193
+ end
194
+
195
+ # public: Records a page view
196
+ #
197
+ # options - Hash
198
+ # :user_id - String of the id to alias from
199
+ # :name - String name of the page
200
+ # :properties - Hash of page properties (optional)
201
+ # :timestamp - Time of when the pageview occured (optional)
202
+ # :context - Hash of context (optional)
203
+ def page(options)
204
+ check_secret
205
+ Util.symbolize_keys! options
206
+ user_id = options[:user_id].to_s
207
+ name = options[:name].to_s
208
+ properties = options[:properties] || {}
209
+ timestamp = options[:timestamp] || Time.new
210
+ context = options[:context] || {}
211
+
212
+ fail ArgumentError, '.name must be a string' unless !name.empty?
213
+ fail ArgumentError, '.properties must be a hash' unless properties.is_a? Hash
214
+ Util.isoify_dates! properties
215
+
216
+ ensure_user user_id
217
+ check_timestamp timestamp
218
+ add_context context
219
+
220
+ enqueue({
221
+ :userId => user_id,
222
+ :name => name,
223
+ :properties => properties,
224
+ :context => context,
225
+ :timestamp => timestamp.iso8601,
226
+ :action => 'page'
227
+ })
228
+ end
229
+ # public: Records a screen view (for a mobile app)
230
+ #
231
+ # options - Hash
232
+ # :user_id - String of the id to alias from
233
+ # :name - String name of the screen
234
+ # :properties - Hash of screen properties (optional)
235
+ # :timestamp - Time of when the screen occured (optional)
236
+ # :context - Hash of context (optional)
237
+ def screen(options)
238
+ check_secret
239
+ Util.symbolize_keys! options
240
+ user_id = options[:user_id].to_s
241
+ name = options[:name].to_s
242
+ properties = options[:properties] || {}
243
+ timestamp = options[:timestamp] || Time.new
244
+ context = options[:context] || {}
245
+
246
+ fail ArgumentError, '.name must be a string' if name.empty?
247
+ fail ArgumentError, '.properties must be a hash' unless properties.is_a? Hash
248
+ Util.isoify_dates! properties
249
+
250
+ ensure_user user_id
251
+ check_timestamp timestamp
252
+ add_context context
253
+
254
+ enqueue({
255
+ :userId => user_id,
256
+ :name => name,
257
+ :properties => properties,
258
+ :context => context,
259
+ :timestamp => timestamp.iso8601,
260
+ :action => 'screen'
261
+ })
262
+ end
263
+
162
264
  # public: Returns the number of queued messages
163
265
  #
164
266
  # returns Fixnum of messages in the queue
@@ -1,3 +1,3 @@
1
1
  module AnalyticsRuby
2
- VERSION = '0.5.4'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -129,6 +129,72 @@ describe AnalyticsRuby::Client do
129
129
  end
130
130
  end
131
131
 
132
+ describe '#group' do
133
+ before :all do
134
+ @client = AnalyticsRuby::Client.new :secret => AnalyticsRubyHelpers::SECRET
135
+ end
136
+
137
+ it 'should error without group_id' do
138
+ expect { @client.group :user_id => 'foo' }.to raise_error(ArgumentError)
139
+ end
140
+
141
+ it 'should error without user_id' do
142
+ expect { @client.group :group_id => 'foo' }.to raise_error(ArgumentError)
143
+ end
144
+
145
+ it 'should not error with the required options' do
146
+ @client.group AnalyticsRubyHelpers::Queued::GROUP
147
+ end
148
+
149
+ it 'should not error with the required options as strings' do
150
+ @client.group Util.stringify_keys(AnalyticsRubyHelpers::Queued::GROUP)
151
+ end
152
+ end
153
+
154
+ describe '#page' do
155
+ before :all do
156
+ @client = AnalyticsRuby::Client.new :secret => AnalyticsRubyHelpers::SECRET
157
+ end
158
+
159
+ it 'should error without user_id' do
160
+ expect { @client.page :name => 'foo' }.to raise_error(ArgumentError)
161
+ end
162
+
163
+ it 'should error without name' do
164
+ expect { @client.page :user_id => 1 }.to raise_error(ArgumentError)
165
+ end
166
+
167
+ it 'should not error with the required options' do
168
+ @client.page AnalyticsRubyHelpers::Queued::PAGE
169
+ end
170
+
171
+ it 'should not error with the required options as strings' do
172
+ @client.page Util.stringify_keys(AnalyticsRubyHelpers::Queued::PAGE)
173
+ end
174
+ end
175
+
176
+ describe '#screen' do
177
+ before :all do
178
+ @client = AnalyticsRuby::Client.new :secret => AnalyticsRubyHelpers::SECRET
179
+ end
180
+
181
+ it 'should error without user_id' do
182
+ expect { @client.screen :name => 'foo' }.to raise_error(ArgumentError)
183
+ end
184
+
185
+ it 'should error without name' do
186
+ expect { A@client.screen :user_id => 1 }.to raise_error(ArgumentError)
187
+ end
188
+
189
+ it 'should not error with the required options' do
190
+ @client.screen AnalyticsRubyHelpers::Queued::SCREEN
191
+ end
192
+
193
+ it 'should not error with the required options as strings' do
194
+ @client.screen Util.stringify_keys(AnalyticsRubyHelpers::Queued::SCREEN)
195
+ end
196
+ end
197
+
132
198
  describe '#flush' do
133
199
  before(:all) do
134
200
  @client = AnalyticsRuby::Client.new :secret => AnalyticsRubyHelpers::SECRET
@@ -71,6 +71,51 @@ describe AnalyticsRuby do
71
71
  end
72
72
  end
73
73
 
74
+ describe '#group' do
75
+ it 'should error without group_id' do
76
+ expect { AnalyticsRuby.group :user_id => 'foo' }.to raise_error(ArgumentError)
77
+ end
78
+
79
+ it 'should error without user_id' do
80
+ expect { AnalyticsRuby.group :group_id => 'foo' }.to raise_error(ArgumentError)
81
+ end
82
+
83
+ it 'should not error with the required options' do
84
+ AnalyticsRuby.group AnalyticsRubyHelpers::Queued::GROUP
85
+ sleep(1)
86
+ end
87
+ end
88
+
89
+ describe '#page' do
90
+ it 'should error without user_id' do
91
+ expect { AnalyticsRuby.page :name => 'foo' }.to raise_error(ArgumentError)
92
+ end
93
+
94
+ it 'should error without name' do
95
+ expect { AnalyticsRuby.page :user_id => 1 }.to raise_error(ArgumentError)
96
+ end
97
+
98
+ it 'should not error with the required options' do
99
+ AnalyticsRuby.page AnalyticsRubyHelpers::Queued::PAGE
100
+ sleep(1)
101
+ end
102
+ end
103
+
104
+ describe '#screen' do
105
+ it 'should error without user_id' do
106
+ expect { AnalyticsRuby.screen :name => 'foo' }.to raise_error(ArgumentError)
107
+ end
108
+
109
+ it 'should error without name' do
110
+ expect { AnalyticsRuby.screen :user_id => 1 }.to raise_error(ArgumentError)
111
+ end
112
+
113
+ it 'should not error with the required options' do
114
+ AnalyticsRuby.screen AnalyticsRubyHelpers::Queued::SCREEN
115
+ sleep(1)
116
+ end
117
+ end
118
+
74
119
  describe '#flush' do
75
120
 
76
121
  it 'should flush without error' do
@@ -18,8 +18,7 @@ module AnalyticsRubyHelpers
18
18
  :likes_animals => true,
19
19
  :instrument => 'Guitar',
20
20
  :age => 25
21
- },
22
- :action => 'identify'
21
+ }
23
22
  }
24
23
 
25
24
  ALIAS = {
@@ -27,15 +26,29 @@ module AnalyticsRubyHelpers
27
26
  :to => 'abcd'
28
27
  }
29
28
 
29
+ GROUP = {}
30
+
31
+ PAGE = {
32
+ :name => 'home'
33
+ }
34
+
35
+ SCREEN = {
36
+ :name => 'main'
37
+ }
38
+
30
39
  USER_ID = 1234
40
+ GROUP_ID = 1234
31
41
 
32
- # Hashes sent to the client
42
+ # Hashes sent to the client, snake_case
33
43
  module Queued
34
44
  TRACK = TRACK.merge :user_id => USER_ID
35
45
  IDENTIFY = IDENTIFY.merge :user_id => USER_ID
46
+ GROUP = GROUP.merge :group_id => GROUP_ID, :user_id => USER_ID
47
+ PAGE = PAGE.merge :user_id => USER_ID
48
+ SCREEN = SCREEN.merge :user_id => USER_ID
36
49
  end
37
50
 
38
- # Hashes which are sent from the consumer
51
+ # Hashes which are sent from the consumer, camel_cased
39
52
  module Requested
40
53
  TRACK = TRACK.merge({
41
54
  :userId => USER_ID,
@@ -46,5 +59,14 @@ module AnalyticsRubyHelpers
46
59
  :userId => USER_ID,
47
60
  :action => 'identify'
48
61
  })
62
+
63
+ GROUP = GROUP.merge({
64
+ :groupId => GROUP_ID,
65
+ :userId => USER_ID,
66
+ :action => 'group'
67
+ })
68
+
69
+ PAGE = PAGE.merge :userId => USER_ID
70
+ SCREEN = SCREEN.merge :userId => USER_ID
49
71
  end
50
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: analytics-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-31 00:00:00.000000000 Z
12
+ date: 2014-02-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -19,9 +19,6 @@ dependencies:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0.8'
22
- - - <
23
- - !ruby/object:Gem::Version
24
- version: '0.10'
25
22
  type: :runtime
26
23
  prerelease: false
27
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,9 +27,6 @@ dependencies:
30
27
  - - ! '>='
31
28
  - !ruby/object:Gem::Version
32
29
  version: '0.8'
33
- - - <
34
- - !ruby/object:Gem::Version
35
- version: '0.10'
36
30
  - !ruby/object:Gem::Dependency
37
31
  name: faraday_middleware
38
32
  requirement: !ruby/object:Gem::Requirement