analytics-ruby 2.2.7 → 2.2.8.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/analytics +22 -7
- data/lib/segment/analytics/client.rb +1 -0
- data/lib/segment/analytics/field_parser.rb +17 -9
- data/lib/segment/analytics/message_batch.rb +8 -1
- data/lib/segment/analytics/request.rb +1 -1
- data/lib/segment/analytics/version.rb +1 -1
- data/lib/segment/analytics/worker.rb +9 -2
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e51f2f5e83f0b45ffc47838b0a2048735ee58aa1d64c24229f3f4ca8db1b6383
|
4
|
+
data.tar.gz: 31adbe2f500bc4812e866e099c13f981786881c7b366879991022cbf2bf20e7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dd283eb00b9a0acf4d0b858244bd10ad41e9db50b573b583d5072a534d56bc98f27e238e83dde6017e3ba97152d3131f025d0c1c22946ed12a3cd04841191cd
|
7
|
+
data.tar.gz: ce6e9b2c792654535d3a553697b605bec3a9e3d7ecb3e5c971c3be601eb6dac97d0e0e442ab03610246903ce80953346c6d10aaee7f6118fffc41ac554b112a4
|
data/bin/analytics
CHANGED
@@ -29,6 +29,7 @@ command :send do |c|
|
|
29
29
|
c.option '--userId=<userId>', String, 'the user id to send the event as'
|
30
30
|
c.option '--anonymousId=<anonymousId>', String, 'the anonymous user id to send the event as'
|
31
31
|
c.option '--context=<context>', 'additional context for the event (JSON-encoded)'
|
32
|
+
c.option '--integrations=<integrations>', 'additional integrations for the event (JSON-encoded)'
|
32
33
|
|
33
34
|
c.option '--event=<event>', String, 'the event name to send with the event'
|
34
35
|
c.option '--properties=<properties>', 'the event properties to send (JSON-encoded)'
|
@@ -38,6 +39,7 @@ command :send do |c|
|
|
38
39
|
c.option '--traits=<traits>', 'the identify/group traits to send (JSON-encoded)'
|
39
40
|
|
40
41
|
c.option '--groupId=<groupId>', String, 'the group id'
|
42
|
+
c.option '--previousId=<previousId>', String, 'the previous id'
|
41
43
|
|
42
44
|
c.action do |args, options|
|
43
45
|
Analytics = Segment::Analytics.new({
|
@@ -52,7 +54,8 @@ command :send do |c|
|
|
52
54
|
event: options.event,
|
53
55
|
anonymous_id: options.anonymousId,
|
54
56
|
properties: json_hash(options.properties),
|
55
|
-
context: json_hash(options.context)
|
57
|
+
context: json_hash(options.context),
|
58
|
+
integrations: json_hash(options.integrations)
|
56
59
|
})
|
57
60
|
when "page"
|
58
61
|
Analytics.page({
|
@@ -60,22 +63,25 @@ command :send do |c|
|
|
60
63
|
anonymous_id: options.anonymousId,
|
61
64
|
name: options.name,
|
62
65
|
properties: json_hash(options.properties),
|
63
|
-
context: json_hash(options.context)
|
66
|
+
context: json_hash(options.context),
|
67
|
+
integrations: json_hash(options.integrations)
|
64
68
|
})
|
65
69
|
when "screen"
|
66
70
|
Analytics.screen({
|
67
71
|
user_id: options.userId,
|
68
72
|
anonymous_id: options.anonymousId,
|
69
|
-
name:
|
70
|
-
|
71
|
-
|
73
|
+
name: options.name,
|
74
|
+
properties: json_hash(options.properties),
|
75
|
+
context: json_hash(options.context),
|
76
|
+
integrations: json_hash(options.integrations)
|
72
77
|
})
|
73
78
|
when "identify"
|
74
79
|
Analytics.identify({
|
75
80
|
user_id: options.userId,
|
76
81
|
anonymous_id: options.anonymousId,
|
77
82
|
traits: json_hash(options.traits),
|
78
|
-
context: json_hash(options.context)
|
83
|
+
context: json_hash(options.context),
|
84
|
+
integrations: json_hash(options.integrations)
|
79
85
|
})
|
80
86
|
when "group"
|
81
87
|
Analytics.group({
|
@@ -83,7 +89,16 @@ command :send do |c|
|
|
83
89
|
anonymous_id: options.anonymousId,
|
84
90
|
group_id: options.groupId,
|
85
91
|
traits: json_hash(options.traits),
|
86
|
-
context: json_hash(options.context)
|
92
|
+
context: json_hash(options.context),
|
93
|
+
integrations: json_hash(options.integrations)
|
94
|
+
})
|
95
|
+
when "alias"
|
96
|
+
Analytics.alias({
|
97
|
+
previous_id: options.previousId,
|
98
|
+
user_id: options.userId,
|
99
|
+
anonymous_id: options.anonymousId,
|
100
|
+
context: json_hash(options.context),
|
101
|
+
integrations: json_hash(options.integrations)
|
87
102
|
})
|
88
103
|
else
|
89
104
|
raise "Invalid Message Type #{options.type}"
|
@@ -120,12 +120,15 @@ module Segment
|
|
120
120
|
|
121
121
|
isoify_dates! properties
|
122
122
|
|
123
|
-
common.merge({
|
123
|
+
parsed = common.merge({
|
124
124
|
:type => 'screen',
|
125
125
|
:name => name,
|
126
|
-
:properties => properties
|
127
|
-
:category => category
|
126
|
+
:properties => properties
|
128
127
|
})
|
128
|
+
|
129
|
+
parsed[:category] = category if category
|
130
|
+
|
131
|
+
parsed
|
129
132
|
end
|
130
133
|
|
131
134
|
private
|
@@ -140,15 +143,20 @@ module Segment
|
|
140
143
|
|
141
144
|
add_context! context
|
142
145
|
|
143
|
-
{
|
144
|
-
:anonymousId => fields[:anonymous_id],
|
146
|
+
parsed = {
|
145
147
|
:context => context,
|
146
|
-
:integrations => fields[:integrations],
|
147
148
|
:messageId => message_id,
|
148
|
-
:timestamp => datetime_in_iso8601(timestamp)
|
149
|
-
:userId => fields[:user_id],
|
150
|
-
:options => fields[:options] # Not in spec, retained for backward compatibility
|
149
|
+
:timestamp => datetime_in_iso8601(timestamp)
|
151
150
|
}
|
151
|
+
|
152
|
+
parsed[:userId] = fields[:user_id] if fields[:user_id]
|
153
|
+
parsed[:anonymousId] = fields[:anonymous_id] if fields[:anonymous_id]
|
154
|
+
parsed[:integrations] = fields[:integrations] if fields[:integrations]
|
155
|
+
|
156
|
+
# Not in spec, retained for backward compatibility
|
157
|
+
parsed[:options] = fields[:options] if fields[:options]
|
158
|
+
|
159
|
+
parsed
|
152
160
|
end
|
153
161
|
|
154
162
|
def check_user_id!(fields)
|
@@ -5,6 +5,8 @@ module Segment
|
|
5
5
|
class Analytics
|
6
6
|
# A batch of `Message`s to be sent to the API
|
7
7
|
class MessageBatch
|
8
|
+
class JSONGenerationError < StandardError; end
|
9
|
+
|
8
10
|
extend Forwardable
|
9
11
|
include Segment::Analytics::Logging
|
10
12
|
include Segment::Analytics::Defaults::MessageBatch
|
@@ -16,8 +18,13 @@ module Segment
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def <<(message)
|
19
|
-
|
21
|
+
begin
|
22
|
+
message_json = message.to_json
|
23
|
+
rescue StandardError => e
|
24
|
+
raise JSONGenerationError, "Serialization error: #{e}"
|
25
|
+
end
|
20
26
|
|
27
|
+
message_json_size = message_json.bytesize
|
21
28
|
if message_too_big?(message_json_size)
|
22
29
|
logger.error('a message exceeded the maximum allowed size')
|
23
30
|
else
|
@@ -38,11 +38,10 @@ module Segment
|
|
38
38
|
return if @queue.empty?
|
39
39
|
|
40
40
|
@lock.synchronize do
|
41
|
-
|
41
|
+
consume_message_from_queue! until @batch.full? || @queue.empty?
|
42
42
|
end
|
43
43
|
|
44
44
|
res = Request.new.post @write_key, @batch
|
45
|
-
|
46
45
|
@on_error.call(res.status, res.error) unless res.status == 200
|
47
46
|
|
48
47
|
@lock.synchronize { @batch.clear }
|
@@ -54,6 +53,14 @@ module Segment
|
|
54
53
|
def is_requesting?
|
55
54
|
@lock.synchronize { !@batch.empty? }
|
56
55
|
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def consume_message_from_queue!
|
60
|
+
@batch << @queue.pop
|
61
|
+
rescue MessageBatch::JSONGenerationError => e
|
62
|
+
@on_error.call(-1, e.to_s)
|
63
|
+
end
|
57
64
|
end
|
58
65
|
end
|
59
66
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: analytics-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.8.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Segment.io
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
@@ -156,14 +156,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
159
|
+
version: '2.0'
|
160
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
161
|
requirements:
|
162
|
-
- - "
|
162
|
+
- - ">"
|
163
163
|
- !ruby/object:Gem::Version
|
164
|
-
version:
|
164
|
+
version: 1.3.1
|
165
165
|
requirements: []
|
166
|
-
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 2.7.7
|
167
168
|
signing_key:
|
168
169
|
specification_version: 4
|
169
170
|
summary: Segment.io analytics library
|