fluent-plugin-amplitude 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/fluent-plugin-amplitude.gemspec +1 -1
- data/lib/fluent/plugin/out_amplitude.rb +16 -7
- data/spec/out_amplitude_spec.rb +86 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce23650ea41be224d3c3cace3bc46ecd231868e7
|
4
|
+
data.tar.gz: 9c51f42644f97118db2ff87001d9109d118a0f6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdfe8433824bbed0fc3eaf4f84d625c54f1a8262b541d11730d28939a857c4e834320dfac4414131cf0501e21401f9c131e93cbc7667ff14e3bcc977132f22ac
|
7
|
+
data.tar.gz: da8cda4768e715a4cbfd58f4acc18029b35677a5d8e1c2cd19141d7d8aa2e2275022111b4a685d49ee43951714f427d59cd4628c2a1d6c59900f26721a045b29
|
data/README.md
CHANGED
@@ -41,7 +41,7 @@ $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-amplitude
|
|
41
41
|
AmplitudeOutput needs your Amplitude `api_key` ([see Amplitude for more information](https://amplitude.zendesk.com/hc/en-us/articles/206728448-Where-can-I-find-my-app-s-API-Key-or-Secret-Key-))
|
42
42
|
|
43
43
|
#### user_id_key and device_id_key
|
44
|
-
You must set at least one of `user_id_key` and `device_id_key`. They will be used to pull out the `user_id` and `device_id` values from the record to send to the Amplitude API.
|
44
|
+
You must set at least one of `user_id_key` and `device_id_key`. They will be used to pull out the `user_id` and `device_id` values from the record to send to the Amplitude API. Note these can both be arrays, and the first matching key will be used.
|
45
45
|
|
46
46
|
#### user_properties and event_properties
|
47
47
|
You can optionally specify lists of `user_properties` and `event_properties` to pull from the record.
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'fluent-plugin-amplitude'
|
7
|
-
spec.version = '0.0.
|
7
|
+
spec.version = '0.0.5'
|
8
8
|
spec.authors = ['Vijay Ramesh']
|
9
9
|
spec.email = ['vijay@change.org']
|
10
10
|
spec.summary = 'Fluentd plugin to output event data to Amplitude'
|
@@ -8,8 +8,8 @@ module Fluent
|
|
8
8
|
include FakeActiveSupport
|
9
9
|
|
10
10
|
config_param :api_key, :string, secret: true
|
11
|
-
config_param :device_id_key, :
|
12
|
-
config_param :user_id_key, :
|
11
|
+
config_param :device_id_key, :array, default: nil
|
12
|
+
config_param :user_id_key, :array, default: nil
|
13
13
|
config_param :user_properties, :array, default: nil
|
14
14
|
config_param :event_properties, :array, default: nil
|
15
15
|
config_param :properties_blacklist, :array, default: nil
|
@@ -66,12 +66,21 @@ module Fluent
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def extract_user_and_device_or_fail!(amplitude_hash, record)
|
69
|
-
if @user_id_key
|
70
|
-
|
69
|
+
if @user_id_key
|
70
|
+
@user_id_key.each do |user_id_key|
|
71
|
+
if record[user_id_key]
|
72
|
+
amplitude_hash[:user_id] = record.delete(user_id_key)
|
73
|
+
break
|
74
|
+
end
|
75
|
+
end
|
71
76
|
end
|
72
|
-
|
73
|
-
|
74
|
-
|
77
|
+
if @device_id_key
|
78
|
+
@device_id_key.each do |device_id_key|
|
79
|
+
if record[device_id_key]
|
80
|
+
amplitude_hash[:device_id] = record.delete(device_id_key)
|
81
|
+
break
|
82
|
+
end
|
83
|
+
end
|
75
84
|
end
|
76
85
|
|
77
86
|
verify_user_and_device_or_fail(amplitude_hash)
|
data/spec/out_amplitude_spec.rb
CHANGED
@@ -206,5 +206,91 @@ describe Fluent::AmplitudeOutput do
|
|
206
206
|
amplitude.run
|
207
207
|
end
|
208
208
|
end
|
209
|
+
|
210
|
+
context 'multiple user_id_key specified' do
|
211
|
+
let(:conf) do
|
212
|
+
%(
|
213
|
+
api_key XXXXXX
|
214
|
+
user_id_key user_id, another_user_id_field
|
215
|
+
device_id_key uuid
|
216
|
+
user_properties first_name, last_name
|
217
|
+
event_properties current_source
|
218
|
+
)
|
219
|
+
end
|
220
|
+
let(:event) do
|
221
|
+
{
|
222
|
+
'another_user_id_field' => 42,
|
223
|
+
'uuid' => 'e6153b00-85d8-11e6-b1bc-43192d1e493f',
|
224
|
+
'first_name' => 'Bobby',
|
225
|
+
'last_name' => 'Weir',
|
226
|
+
'state' => 'CA',
|
227
|
+
'current_source' => 'fb_share',
|
228
|
+
'recruiter_id' => 710
|
229
|
+
}
|
230
|
+
end
|
231
|
+
|
232
|
+
let(:formatted_event) do
|
233
|
+
{
|
234
|
+
event_type: tag,
|
235
|
+
user_id: 42,
|
236
|
+
device_id: 'e6153b00-85d8-11e6-b1bc-43192d1e493f',
|
237
|
+
user_properties: {
|
238
|
+
first_name: 'Bobby',
|
239
|
+
last_name: 'Weir'
|
240
|
+
},
|
241
|
+
event_properties: {
|
242
|
+
current_source: 'fb_share'
|
243
|
+
}
|
244
|
+
}
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'produces the expected output' do
|
248
|
+
amplitude.expect_format [tag, now, formatted_event].to_msgpack
|
249
|
+
amplitude.run
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
context 'multiple device_id_key specified' do
|
254
|
+
let(:conf) do
|
255
|
+
%(
|
256
|
+
api_key XXXXXX
|
257
|
+
user_id_key user_id
|
258
|
+
device_id_key uuid, user_uuid
|
259
|
+
user_properties first_name, last_name
|
260
|
+
event_properties current_source
|
261
|
+
)
|
262
|
+
end
|
263
|
+
let(:event) do
|
264
|
+
{
|
265
|
+
'user_id' => 42,
|
266
|
+
'user_uuid' => 'e6153b00-85d8-11e6-b1bc-43192d1e493f',
|
267
|
+
'first_name' => 'Bobby',
|
268
|
+
'last_name' => 'Weir',
|
269
|
+
'state' => 'CA',
|
270
|
+
'current_source' => 'fb_share',
|
271
|
+
'recruiter_id' => 710
|
272
|
+
}
|
273
|
+
end
|
274
|
+
|
275
|
+
let(:formatted_event) do
|
276
|
+
{
|
277
|
+
event_type: tag,
|
278
|
+
user_id: 42,
|
279
|
+
device_id: 'e6153b00-85d8-11e6-b1bc-43192d1e493f',
|
280
|
+
user_properties: {
|
281
|
+
first_name: 'Bobby',
|
282
|
+
last_name: 'Weir'
|
283
|
+
},
|
284
|
+
event_properties: {
|
285
|
+
current_source: 'fb_share'
|
286
|
+
}
|
287
|
+
}
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'produces the expected output' do
|
291
|
+
amplitude.expect_format [tag, now, formatted_event].to_msgpack
|
292
|
+
amplitude.run
|
293
|
+
end
|
294
|
+
end
|
209
295
|
end
|
210
296
|
end
|