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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 151e2c0afc12d5647faa456efe7e679050d5a251
4
- data.tar.gz: abdda1c6803826eb6df78d8283d9ef1ea7004f4b
3
+ metadata.gz: ce23650ea41be224d3c3cace3bc46ecd231868e7
4
+ data.tar.gz: 9c51f42644f97118db2ff87001d9109d118a0f6a
5
5
  SHA512:
6
- metadata.gz: c07e35b6e4fd5147796bee6dc3270ff0bbf486e26bc405f71675dee9972f807a6a4773c5983baadd7643c559155f9e04ada15d81c506e523df460ea0cd048558
7
- data.tar.gz: 51b777c6ea536b11e7a5d1d704346a4cca5261946e462e08c3672cabe6d72025a4d0b19dcb6da1ffedcd362562bd17999030637300a2c4bd8c517286731dbdf2
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.4'
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, :string
12
- config_param :user_id_key, :string
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 && record[@user_id_key]
70
- amplitude_hash[:user_id] = record.delete(@user_id_key)
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
- if @device_id_key && record[@device_id_key]
74
- amplitude_hash[:device_id] = record.delete(@device_id_key)
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)
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-amplitude
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vijay Ramesh