fluent-plugin-mixpanel 0.0.3 → 0.0.4

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: 9406e78fac736d2fd7b8b6b4dfa4645f741170db
4
- data.tar.gz: 43835b93670babcdfe3d6cf184b6b65413507315
3
+ metadata.gz: d484a01b3b20513d87cef2561d3472e2cf4447b1
4
+ data.tar.gz: 56622c0ebdfc8cfb822e542cecd31516ffec9079
5
5
  SHA512:
6
- metadata.gz: 9aa1ecf98277f977a110929ea16356265fc02f858253fcf100f0f5c6f569e65766fce3f20809b0c72286971becb16fae7aa113529774ed5b166f7264898731c4
7
- data.tar.gz: 33c231f32a0eed37ff3225ad41f93dfbb72c6e9383e7afb419fc76c037692e1ce3ad8de3f234aaef89480291b4d3a62224247ff0b69525d98bef6717708bd7f9
6
+ metadata.gz: 6a5c41e85c1d43fdd6ec3b2ecde7425fc210e1bb6c980a4ecb8967c96a97aeaa4617cdc6bcc7f384ccc015d3281bb8bb7a05df797c3f1beb65b65644b2000ef5
7
+ data.tar.gz: 5cbbe5f96c417112b3b80ae6006767664865758922de36b9ac4f4df197bab68145be69d5b79fa965ea69c3345cf120551ae7fde7d33f07f0c5386ebfc0f7d5bf
data/README.md CHANGED
@@ -29,6 +29,9 @@ $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-mixpanel
29
29
  ### MixpanelOutput
30
30
 
31
31
  MixpanelOutput needs mixpanel's `project_token`, that can get from your mixpanel project settings.
32
+
33
+ #### Use distinct_id_key and event_key
34
+
32
35
  You should also specify property key name by `distinct_id_key` and `event_key`.
33
36
 
34
37
  ```
@@ -53,6 +56,33 @@ tracker = Mixpanel::Tracker.new(YOUR_PROJECT_TOKEN)
53
56
  tracker.track("123", "event1", { key1: "value1", key2: "value2" })
54
57
  ```
55
58
 
59
+ #### Use distinct_id_key and event_map_tag
60
+
61
+ You can use tag name as event name like this.
62
+
63
+ ```
64
+ <match output.mixpanel.*>
65
+ type mixpanel
66
+ project_token YOUR_PROJECT_TOKEN
67
+ distinct_id_key user_id
68
+ remove_tag_prefix output.mixpanel
69
+ event_map_tag true
70
+ </match>
71
+ ```
72
+
73
+ If tag name is `output.mixpanel.event1` and record like this:
74
+
75
+ ```rb
76
+ { user_id: "123", key1: "value1", key2: "value2" }
77
+ ```
78
+
79
+ above settings send to the following data to mixpanel, using [mixpanel-ruby](https://github.com/mixpanel/mixpanel-ruby) gem.
80
+
81
+ ```rb
82
+ tracker = Mixpanel::Tracker.new(YOUR_PROJECT_TOKEN)
83
+ tracker.track("123", "event1", { key1: "value1", key2: "value2" })
84
+ ```
85
+
56
86
  ### HttpMixpanelInput
57
87
 
58
88
  HttpMixpanelInput has same configuration as [http Input Plugin](http://docs.fluentd.org/en/articles/in_http).
data/example/index.html CHANGED
@@ -14,7 +14,7 @@
14
14
  (function(c,a){window.mixpanel=a;var b,d,h,e;b=c.createElement("script");
15
15
  b.type="text/javascript";b.async=!0;b.src=("https:"===c.location.protocol?"https:":"http:")+'//cdn.mxpnl.com/libs/mixpanel-2.2.min.js';d=c.getElementsByTagName("script")[0];d.parentNode.insertBefore(b,d);a._i=[];a.init=function(b,c,f){function d(a,b){var c=b.split(".");2==c.length&&(a=a[c[0]],b=c[1]);a[b]=function(){a.push([b].concat(Array.prototype.slice.call(arguments,0)))}}var g=a;"undefined"!==typeof f?g=a[f]=[]:f="mixpanel";g.people=g.people||[];h=['disable','track','track_pageview','track_links','track_forms','register','register_once','unregister','identify','alias','name_tag','set_config','people.set','people.set_once','people.increment','people.track_charge','people.append'];for(e=0;e<h.length;e++)d(g,h[e]);a._i.push([b,c,f])};a.__SV=1.2;})(document,window.mixpanel||[]);
16
16
  mixpanel.init("dummy", {
17
- api_host: 'http://0.0.0.0:8888',
17
+ api_host: '//0.0.0.0:5000',
18
18
  debug: true
19
19
  });
20
20
  </script>
@@ -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-mixpanel"
7
- spec.version = "0.0.3"
7
+ spec.version = "0.0.4"
8
8
  spec.authors = ["Kazuyuki Honda"]
9
9
  spec.email = ["hakobera@gmail.com"]
10
10
  spec.summary = %q{Fluentd plugin to input/output event track data to mixpanel}
@@ -3,9 +3,12 @@ class Fluent::MixpanelOutput < Fluent::BufferedOutput
3
3
 
4
4
  config_param :project_token, :string
5
5
  config_param :distinct_id_key, :string
6
- config_param :event_key, :string
6
+ config_param :event_key, :string, :default => nil
7
7
  config_param :ip_key, :string, :default => nil
8
8
 
9
+ config_param :remove_tag_prefix, :string, :default => nil
10
+ config_param :event_map_tag, :bool, :default => false
11
+
9
12
  def initialize
10
13
  super
11
14
  require 'mixpanel-ruby'
@@ -17,17 +20,11 @@ class Fluent::MixpanelOutput < Fluent::BufferedOutput
17
20
  @distinct_id_key = conf['distinct_id_key']
18
21
  @event_key = conf['event_key']
19
22
  @ip_key = conf['ip_key']
23
+ @remove_tag_prefix = conf['remove_tag_prefix']
24
+ @event_map_tag = conf['event_map_tag']
20
25
 
21
- if @project_token.empty?
22
- raise Fluent::ConfigError, "'project_token' must be specifed."
23
- end
24
-
25
- if @distinct_id_key.empty?
26
- raise Fluent::ConfigError, "'distinct_id_key' must be specifed."
27
- end
28
-
29
- if @event_key.empty?
30
- raise Fluent::ConfigError, "'event_key' must be specifed."
26
+ if @event_key.nil? and !@event_map_tag
27
+ raise Fluent::ConfigError, "'event_key' must be specifed when event_map_tag == false."
31
28
  end
32
29
  end
33
30
 
@@ -57,7 +54,9 @@ class Fluent::MixpanelOutput < Fluent::BufferedOutput
57
54
  return
58
55
  end
59
56
 
60
- if record[@event_key]
57
+ if @event_map_tag
58
+ data['event'] = tag.gsub(/^#{@remove_tag_prefix}(\.)?/, '')
59
+ elsif record[@event_key]
61
60
  data['event'] = record[@event_key]
62
61
  record.delete(@event_key)
63
62
  else
@@ -11,11 +11,10 @@ class MixpanelOutputTest < Test::Unit::TestCase
11
11
  CONFIG = %[
12
12
  project_token test_token
13
13
  distinct_id_key user_id
14
- event_key event
15
14
  ]
16
15
 
17
16
  def create_driver(conf = CONFIG)
18
- Fluent::Test::BufferedOutputTestDriver.new(Fluent::MixpanelOutput).configure(conf)
17
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::MixpanelOutput, 'mixpanel.test').configure(conf)
19
18
  end
20
19
 
21
20
  def stub_mixpanel(url="https://api.mixpanel.com/track")
@@ -34,7 +33,7 @@ class MixpanelOutputTest < Test::Unit::TestCase
34
33
  end
35
34
 
36
35
  def test_configure
37
- d = create_driver
36
+ d = create_driver(CONFIG + "event_key event")
38
37
 
39
38
  assert_equal 'test_token', d.instance.project_token
40
39
  assert_equal 'user_id', d.instance.distinct_id_key
@@ -42,7 +41,7 @@ class MixpanelOutputTest < Test::Unit::TestCase
42
41
  end
43
42
 
44
43
  def test_configure_with_ip_key
45
- d = create_driver(CONFIG + 'ip_key ip')
44
+ d = create_driver(CONFIG + "event_key event\n ip_key ip")
46
45
 
47
46
  assert_equal 'test_token', d.instance.project_token
48
47
  assert_equal 'user_id', d.instance.distinct_id_key
@@ -50,9 +49,19 @@ class MixpanelOutputTest < Test::Unit::TestCase
50
49
  assert_equal 'ip', d.instance.ip_key
51
50
  end
52
51
 
52
+ def test_configure_with_event_map_tag
53
+ d = create_driver(CONFIG + "remove_tag_prefix mixpanel\n event_map_tag true")
54
+
55
+ assert_equal 'test_token', d.instance.project_token
56
+ assert_equal 'user_id', d.instance.distinct_id_key
57
+ assert_equal nil, d.instance.event_key
58
+ assert_equal 'mixpanel', d.instance.remove_tag_prefix
59
+ assert_equal true.to_s, d.instance.event_map_tag
60
+ end
61
+
53
62
  def test_write
54
63
  stub_mixpanel
55
- d = create_driver
64
+ d = create_driver(CONFIG + "event_key event")
56
65
  time = Time.new('2014-01-01T01:23:45+00:00')
57
66
  d.emit(sample_record, time)
58
67
  d.run
@@ -66,7 +75,7 @@ class MixpanelOutputTest < Test::Unit::TestCase
66
75
 
67
76
  def test_write_multi_request
68
77
  stub_mixpanel
69
- d = create_driver
78
+ d = create_driver(CONFIG + "event_key event")
70
79
  time1 = Time.new('2014-01-01T01:23:45+00:00')
71
80
  time2 = Time.new('2014-01-02T01:23:45+00:00')
72
81
 
@@ -90,7 +99,7 @@ class MixpanelOutputTest < Test::Unit::TestCase
90
99
 
91
100
  def test_write_with_ip_key
92
101
  stub_mixpanel
93
- d = create_driver(CONFIG + 'ip_key ip_address')
102
+ d = create_driver(CONFIG + "event_key event\n ip_key ip_address")
94
103
  time = Time.new('2014-01-01T01:23:45+00:00')
95
104
  d.emit(sample_record.merge('ip_address' => '192.168.0.2'), time)
96
105
  d.run
@@ -103,9 +112,37 @@ class MixpanelOutputTest < Test::Unit::TestCase
103
112
  assert_equal "value2", @out[0]['properties']['key2']
104
113
  end
105
114
 
115
+ def test_write_with_event_map_tag
116
+ stub_mixpanel
117
+ d = create_driver(CONFIG + "remove_tag_prefix mixpanel\n event_map_tag true")
118
+ time = Time.new('2014-01-01T01:23:45+00:00')
119
+ d.emit(sample_record, time)
120
+ d.run
121
+
122
+ assert_equal "123", @out[0]['properties']['distinct_id']
123
+ assert_equal "test", @out[0]['event']
124
+ assert_equal time.to_i, @out[0]['properties']['time']
125
+ assert_equal "value1", @out[0]['properties']['key1']
126
+ assert_equal "value2", @out[0]['properties']['key2']
127
+ end
128
+
129
+ def test_write_with_no_remove_tag_prefix
130
+ stub_mixpanel
131
+ d = create_driver(CONFIG + "event_map_tag true")
132
+ time = Time.new('2014-01-01T01:23:45+00:00')
133
+ d.emit(sample_record, time)
134
+ d.run
135
+
136
+ assert_equal "123", @out[0]['properties']['distinct_id']
137
+ assert_equal "mixpanel.test", @out[0]['event']
138
+ assert_equal time.to_i, @out[0]['properties']['time']
139
+ assert_equal "value1", @out[0]['properties']['key1']
140
+ assert_equal "value2", @out[0]['properties']['key2']
141
+ end
142
+
106
143
  def test_request_error
107
144
  stub_mixpanel_unavailable
108
- d = create_driver
145
+ d = create_driver(CONFIG + "event_key event")
109
146
  d.emit(sample_record)
110
147
  assert_raise(Mixpanel::ConnectionError) {
111
148
  d.run
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mixpanel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuyuki Honda