snowplow-tracker 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YTVhZTY2ODI0YjMxNjJlNGYyYjE4NzZjZmM0NzZiMjNkNWYwZjM5Mg==
5
- data.tar.gz: !binary |-
6
- Mjc0YjdhNmJmOGFiZTk5MjljZDNjMzJlMmMzNWRjY2JjY2UzMTQzYQ==
2
+ SHA1:
3
+ metadata.gz: 09edf5a160b319e2e293ca4583bfeac466991990
4
+ data.tar.gz: abe2cba4c1adfe3c1924c62d06c5f77ac0e9164a
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MGFiM2I4ZGFjMjAwNmQ4ODQ1Mjc0YTNhMDk5MWMyZWQyODE3NTJlYWViMWYy
10
- MzZmMWEzNzNiODAyNGViYjFiYTQyNTg2ZjZiZTRjMDY2ZGQzNjdjNWIyNTVj
11
- N2IxZmNhNzEwZjhkZmVmOGRiOWQ1MTlmMDYzNTU3NWMzMTA1Mjg=
12
- data.tar.gz: !binary |-
13
- ODk2OWI5MzBmMjRkMjdmOWJhMTMwOWVkNTA1MmFhNWEzNTBlM2MzOTExMmZk
14
- NGY0ZGVmMzIxNzU2ZjRkMTkwMzZiN2MzZDM5NjU0MjRmODIwZWY1YzRlZjg4
15
- MjNiZDc4YjJmNjUxMzdlYjg0NjUyNTU2MmM3ZGQwZGFmNGI4MGY=
6
+ metadata.gz: 69808182a038139f1fdf3c032b1603b405ba3883ebdee3fcc694e4dd0796a7ba2ba60a45ecedb132861bdca05ad09825be20a44b327047ca4ede9650c7b60bb3
7
+ data.tar.gz: 3159420b1dba13915f3cf8a7debf165b320a3b6d1141792f4d6984c2343c49d7ae93b7eb98c53466e3de60d8541e8f6dd2a94febe7cabbca643c3c0323e0760f
@@ -19,4 +19,6 @@ require 'snowplow-tracker/self_describing_json.rb'
19
19
  require 'snowplow-tracker/payload.rb'
20
20
  require 'snowplow-tracker/subject.rb'
21
21
  require 'snowplow-tracker/emitters.rb'
22
+ require 'snowplow-tracker/timestamp.rb'
22
23
  require 'snowplow-tracker/tracker.rb'
24
+
@@ -113,6 +113,10 @@ module SnowplowTracker
113
113
  end
114
114
  LOGGER.info("Attempting to send #{evts.size} request#{evts.size == 1 ? '' : 's'}")
115
115
 
116
+ evts.each do |event|
117
+ event['stm'] = (Time.now.to_f * 1000).to_i # add the sent timestamp, overwrite if already exists
118
+ end
119
+
116
120
  if @method == 'post'
117
121
  post_succeeded = false
118
122
  begin
@@ -0,0 +1,46 @@
1
+ # Copyright (c) 2016 Snowplow Analytics Ltd. All rights reserved.
2
+ #
3
+ # This program is licensed to you under the Apache License Version 2.0,
4
+ # and you may not use this file except in compliance with the Apache License Version 2.0.
5
+ # You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
6
+ #
7
+ # Unless required by applicable law or agreed to in writing,
8
+ # software distributed under the Apache License Version 2.0 is distributed on an
9
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
11
+
12
+ # Author:: Alex Dean, Fred Blundun, Ed Lewis (mailto:support@snowplowanalytics.com)
13
+ # Copyright:: Copyright (c) 2016 Snowplow Analytics Ltd
14
+ # License:: Apache License Version 2.0
15
+
16
+ module SnowplowTracker
17
+
18
+ class Timestamp
19
+
20
+ attr_reader :type
21
+ attr_reader :value
22
+
23
+ def initialize(type, value)
24
+ @type = type
25
+ @value = value
26
+ end
27
+
28
+ end
29
+
30
+ class TrueTimestamp < Timestamp
31
+
32
+ def initialize(value)
33
+ super 'ttm', value
34
+ end
35
+
36
+ end
37
+
38
+ class DeviceTimestamp < Timestamp
39
+
40
+ def initialize(value)
41
+ super 'dtm', value
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -133,23 +133,33 @@ module SnowplowTracker
133
133
  nil
134
134
  end
135
135
 
136
+ # Log a visit to this page with an inserted device timestamp
137
+ #
138
+ Contract String, Maybe[String], Maybe[String], Maybe[@@ContextsInput], Maybe[Num] => Tracker
139
+ def track_page_view(page_url, page_title=nil, referrer=nil, context=nil, tstamp=nil)
140
+ if tstamp.nil?
141
+ tstamp = get_timestamp
142
+ end
143
+
144
+ track_page_view(page_url, page_title, referrer, context, DeviceTimestamp.new(tstamp))
145
+ end
146
+
136
147
  # Log a visit to this page
137
148
  #
138
- Contract String, Maybe[String], Maybe[String], Maybe[@@ContextsInput] => Tracker
149
+ Contract String, Maybe[String], Maybe[String], Maybe[@@ContextsInput], SnowplowTracker::Timestamp => Tracker
139
150
  def track_page_view(page_url, page_title=nil, referrer=nil, context=nil, tstamp=nil)
140
151
  pb = Payload.new
141
152
  pb.add('e', 'pv')
142
153
  pb.add('url', page_url)
143
154
  pb.add('page', page_title)
144
155
  pb.add('refr', referrer)
156
+
145
157
  unless context.nil?
146
158
  pb.add_json(build_context(context), @config['encode_base64'], 'cx', 'co')
147
159
  end
148
160
 
149
- if tstamp.nil?
150
- tstamp = get_timestamp
151
- end
152
- pb.add('dtm', tstamp)
161
+ pb.add(tstamp.type, tstamp.value)
162
+
153
163
  track(pb)
154
164
 
155
165
  self
@@ -172,15 +182,29 @@ module SnowplowTracker
172
182
  unless argmap['context'].nil?
173
183
  pb.add_json(build_context(argmap['context']), @config['encode_base64'], 'cx', 'co')
174
184
  end
175
- pb.add('dtm', argmap['tstamp'])
185
+ pb.add(argmap['tstamp'].type, argmap['tstamp'].value)
176
186
  track(pb)
177
187
 
178
188
  self
179
189
  end
180
190
 
181
191
  # Track an ecommerce transaction and all the items in it
182
- #
192
+ # Set the timestamp as the device timestamp
183
193
  Contract @@Transaction, ArrayOf[@@Item], Maybe[@@ContextsInput], Maybe[Num] => Tracker
194
+ def track_ecommerce_transaction(transaction,
195
+ items,
196
+ context=nil,
197
+ tstamp=nil)
198
+ if tstamp.nil?
199
+ tstamp = get_timestamp
200
+ end
201
+
202
+ track_ecommerce_transaction(transaction, items, context, DeviceTimestamp.new(tstamp))
203
+ end
204
+
205
+ # Track an ecommerce transaction and all the items in it
206
+ #
207
+ Contract @@Transaction, ArrayOf[@@Item], Maybe[@@ContextsInput], Timestamp => Tracker
184
208
  def track_ecommerce_transaction(transaction, items,
185
209
  context=nil, tstamp=nil)
186
210
  pb = Payload.new
@@ -198,10 +222,7 @@ module SnowplowTracker
198
222
  pb.add_json(build_context(context), @config['encode_base64'], 'cx', 'co')
199
223
  end
200
224
 
201
- if tstamp.nil?
202
- tstamp = get_timestamp
203
- end
204
- pb.add('dtm', tstamp)
225
+ pb.add(tstamp.type, tstamp.value)
205
226
 
206
227
  track(pb)
207
228
 
@@ -216,8 +237,18 @@ module SnowplowTracker
216
237
  end
217
238
 
218
239
  # Track a structured event
219
- #
240
+ # set the timestamp to the device timestamp
220
241
  Contract String, String, Maybe[String], Maybe[String], Maybe[Num], Maybe[@@ContextsInput], Maybe[Num] => Tracker
242
+ def track_struct_event(category, action, label=nil, property=nil, value=nil, context=nil, tstamp=nil)
243
+ if tstamp.nil?
244
+ tstamp = get_timestamp
245
+ end
246
+
247
+ track_struct_event(category, action, label, property, value, context, DeviceTimestamp.new(tstamp))
248
+ end
249
+ # Track a structured event
250
+ #
251
+ Contract String, String, Maybe[String], Maybe[String], Maybe[Num], Maybe[@@ContextsInput], Timestamp => Tracker
221
252
  def track_struct_event(category, action, label=nil, property=nil, value=nil, context=nil, tstamp=nil)
222
253
  pb = Payload.new
223
254
  pb.add('e', 'se')
@@ -229,10 +260,8 @@ module SnowplowTracker
229
260
  unless context.nil?
230
261
  pb.add_json(build_context(context), @config['encode_base64'], 'cx', 'co')
231
262
  end
232
- if tstamp.nil?
233
- tstamp = get_timestamp
234
- end
235
- pb.add('dtm', tstamp)
263
+
264
+ pb.add(tstamp.type, tstamp.value)
236
265
  track(pb)
237
266
 
238
267
  self
@@ -240,7 +269,7 @@ module SnowplowTracker
240
269
 
241
270
  # Track a screen view event
242
271
  #
243
- Contract Maybe[String], Maybe[String], Maybe[@@ContextsInput], Maybe[Num] => Tracker
272
+ Contract Maybe[String], Maybe[String], Maybe[@@ContextsInput], Or[Timestamp, Num, nil] => Tracker
244
273
  def track_screen_view(name=nil, id=nil, context=nil, tstamp=nil)
245
274
  screen_view_properties = {}
246
275
  unless name.nil?
@@ -258,9 +287,34 @@ module SnowplowTracker
258
287
  self
259
288
  end
260
289
 
261
- # Track an unstructured event
290
+ # Better name for track unstruct event
262
291
  #
292
+ Contract SelfDescribingJson, Maybe[@@ContextsInput], Timestamp => Tracker
293
+ def track_self_describing_event(event_json, context=nil, tstamp=nil)
294
+ track_unstruct_event(event_json, context, tstamp)
295
+ end
296
+
297
+ # Better name for track unstruct event
298
+ # set the timestamp to the device timestamp
299
+ Contract SelfDescribingJson, Maybe[@@ContextsInput], Maybe[Num] => Tracker
300
+ def track_self_describing_event(event_json, context=nil, tstamp=nil)
301
+ track_unstruct_event(event_json, context, tstamp)
302
+ end
303
+
304
+ # Track an unstructured event
305
+ # set the timestamp to the device timstamp
263
306
  Contract SelfDescribingJson, Maybe[@@ContextsInput], Maybe[Num] => Tracker
307
+ def track_unstruct_event(event_json, context=nil, tstamp=nil)
308
+ if tstamp.nil?
309
+ tstamp = get_timestamp
310
+ end
311
+
312
+ track_unstruct_event(event_json, context, DeviceTimestamp.new(tstamp))
313
+ end
314
+
315
+ # Track an unstructured event
316
+ #
317
+ Contract SelfDescribingJson, Maybe[@@ContextsInput], Timestamp => Tracker
264
318
  def track_unstruct_event(event_json, context=nil, tstamp=nil)
265
319
  pb = Payload.new
266
320
  pb.add('e', 'ue')
@@ -273,10 +327,7 @@ module SnowplowTracker
273
327
  pb.add_json(build_context(context), @config['encode_base64'], 'cx', 'co')
274
328
  end
275
329
 
276
- if tstamp.nil?
277
- tstamp = get_timestamp
278
- end
279
- pb.add('dtm', tstamp)
330
+ pb.add(tstamp.type, tstamp.value)
280
331
 
281
332
  track(pb)
282
333
 
@@ -14,6 +14,6 @@
14
14
  # License:: Apache License Version 2.0
15
15
 
16
16
  module SnowplowTracker
17
- VERSION = '0.5.2'
17
+ VERSION = '0.6.0'
18
18
  TRACKER_VERSION = "rb-#{VERSION}"
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snowplow-tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Dean
@@ -9,54 +9,54 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-07 00:00:00.000000000 Z
12
+ date: 2016-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: contracts
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0.7'
21
- - - <=
21
+ - - "<="
22
22
  - !ruby/object:Gem::Version
23
23
  version: '0.11'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
- - - ~>
28
+ - - "~>"
29
29
  - !ruby/object:Gem::Version
30
30
  version: '0.7'
31
- - - <=
31
+ - - "<="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.11'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rspec
36
36
  requirement: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.14.1
41
41
  type: :development
42
42
  prerelease: false
43
43
  version_requirements: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.14.1
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: webmock
50
50
  requirement: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.17.4
55
55
  type: :development
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.17.4
62
62
  description: With this tracker you can collect event data from your Ruby applications,
@@ -74,6 +74,7 @@ files:
74
74
  - lib/snowplow-tracker/payload.rb
75
75
  - lib/snowplow-tracker/self_describing_json.rb
76
76
  - lib/snowplow-tracker/subject.rb
77
+ - lib/snowplow-tracker/timestamp.rb
77
78
  - lib/snowplow-tracker/tracker.rb
78
79
  - lib/snowplow-tracker/version.rb
79
80
  homepage: http://github.com/snowplow/snowplow-ruby-tracker
@@ -86,17 +87,17 @@ require_paths:
86
87
  - lib
87
88
  required_ruby_version: !ruby/object:Gem::Requirement
88
89
  requirements:
89
- - - ! '>='
90
+ - - ">="
90
91
  - !ruby/object:Gem::Version
91
- version: 1.9.3
92
+ version: 2.0.0
92
93
  required_rubygems_version: !ruby/object:Gem::Requirement
93
94
  requirements:
94
- - - ! '>='
95
+ - - ">="
95
96
  - !ruby/object:Gem::Version
96
97
  version: '0'
97
98
  requirements: []
98
99
  rubyforge_project:
99
- rubygems_version: 2.4.8
100
+ rubygems_version: 2.6.6
100
101
  signing_key:
101
102
  specification_version: 4
102
103
  summary: Ruby Analytics for Snowplow