meta_events 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/CHANGES.md +5 -1
- data/README.md +36 -1
- data/lib/meta_events/definition/category.rb +1 -0
- data/lib/meta_events/definition/event.rb +9 -3
- data/lib/meta_events/definition/version.rb +1 -1
- data/lib/meta_events/tracker.rb +63 -17
- data/lib/meta_events/version.rb +1 -1
- data/spec/meta_events/controller_methods_and_helpers_spec.rb +13 -2
- data/spec/meta_events/definition/event_spec.rb +15 -0
- data/spec/meta_events/tracker_spec.rb +88 -6
- data/vendor/assets/javascripts/meta_events.js.erb +5 -4
- metadata +71 -91
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c8e90b6eab418b987148fddd9cef0821956dc09f
|
4
|
+
data.tar.gz: eba083b1ffef6f56b1775cc28ac55bd94e5c7dc9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f2e1dbafa769577654782ecdfc7c1a7f8d0fb4b06a983b10677710bec4e85a79164412bcabc7af0ed77f8941588d4b9d40cdbe3c5881b3dba1f91a87bbf4e1e1
|
7
|
+
data.tar.gz: 39f251715f387ad67b30c8bee7ba12e9fa8be416e95c9309cfe18b9c57446721ef06dffae1ee3de84a167cd9685d7a0bf61a9bb8cafeca16b667f477f4f47c07
|
data/CHANGES.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# `meta_events` Changelog
|
2
2
|
|
3
|
-
## 1.0
|
3
|
+
## 1.1.0, 25 May 2014
|
4
|
+
|
5
|
+
* Support for customizing the event names to Mixpanel using any algorithm you want (`:external_name` in `MetaEvents::Tracker#initialize` or `MetaEvents::Tracker.default_external_name`), or by overriding them on an `Event`-by-`Event` basis (`:external_name` in the DSL on an `Event`). Many thanks to [Aaron Lerch](https://github.com/aaronlerch) for the awesome code and responsiveness!
|
6
|
+
|
7
|
+
### 1.0.3, 24 March 2014
|
4
8
|
|
5
9
|
* Fixed an issue where the `TestReceiver`'s `Rails.logger` reference could happen before `Rails.logger` was actually loaded, causing an exception. (Thanks to [Jesse Rusak](https://github.com/jder)!)
|
6
10
|
* Fixed a minor documentation bug (Thanks to [Jesse Rusak](https://github.com/jder)!)
|
data/README.md
CHANGED
@@ -11,7 +11,9 @@ particularly dependent on exact Ruby versions, and should be compatible with a b
|
|
11
11
|
|
12
12
|
Current build status: ![Current Build Status](https://api.travis-ci.org/swiftype/meta_events.png?branch=master)
|
13
13
|
|
14
|
-
Brought to you by the folks at [Swiftype](https://www.swiftype.com/). First version written by [Andrew Geweke](https://www.github.com/ageweke).
|
14
|
+
Brought to you by the folks at [Swiftype](https://www.swiftype.com/). First version written by [Andrew Geweke](https://www.github.com/ageweke). Major contributions by:
|
15
|
+
|
16
|
+
* [Aaron Lerch](https://github.com/aaronlerch): support for sending human-readable event names to Mixpanel via `:external_name` in the DSL on an Event, or via `:external_name` in `MetaEvents::Tracker#initialize` or `MetaEvents::Tracker.default_external_name`.
|
15
17
|
|
16
18
|
### Background
|
17
19
|
|
@@ -589,6 +591,39 @@ it is difficult or impossible to know if true underlying usage, etc., _actually_
|
|
589
591
|
of changing events.) You can simply create two `MetaEvents::Tracker` instances, one for each version, and use them
|
590
592
|
in parallel.
|
591
593
|
|
594
|
+
### Customizing the Event Name
|
595
|
+
|
596
|
+
Developers love names like "xyz1_user_signed_up" but sometimes it's not a developer doing the analysis.
|
597
|
+
Depending on what the back-end analytics library supports, event names in external systems are frequently not
|
598
|
+
given a lot of real estate.
|
599
|
+
|
600
|
+
In cases like these, you can override the default external event name behavior. There are three ways to
|
601
|
+
override these external names.
|
602
|
+
|
603
|
+
First, you can override them globally for all `MetaEvents::Tracker` instances:
|
604
|
+
|
605
|
+
MetaEvents::Tracker.default_external_name = lambda { |event| "#{event.category_name} #{event.name}" }
|
606
|
+
|
607
|
+
Second, you can override them for a specific `MetaEvents::Tracker` instance:
|
608
|
+
|
609
|
+
MetaEvents::Tracker.new(current_user.try(:id),
|
610
|
+
request.remote_ip,
|
611
|
+
:external_name => lambda { |event| "#{event.category_name} #{event.name}" }
|
612
|
+
)
|
613
|
+
|
614
|
+
Finally, you can override each event's external name in the events DSL:
|
615
|
+
|
616
|
+
global_events_prefix :ab
|
617
|
+
|
618
|
+
version 1, "2014-02-11" do
|
619
|
+
category :example_category do
|
620
|
+
event :example_event, "2014-02-11", "Example was exampled!", :external_name => 'ex. was ex.'
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
624
|
+
The order of precedence for determining the external event name is the DSL's `event :external_name => 'foo'`,
|
625
|
+
`MetaEvents::Tracker.new`, `MetaEvents::Tracker.default_external_name`, built-in default.
|
626
|
+
|
592
627
|
## Contributing
|
593
628
|
|
594
629
|
1. Fork it ( http://github.com/swiftype/meta_events/fork )
|
@@ -89,12 +89,18 @@ module MetaEvents
|
|
89
89
|
@introduced
|
90
90
|
end
|
91
91
|
|
92
|
+
# Returns, or sets, an external_name to use for an event.
|
93
|
+
def external_name(name = nil)
|
94
|
+
@external_name = name if name
|
95
|
+
@external_name
|
96
|
+
end
|
97
|
+
|
92
98
|
# Returns the name of the category for an event.
|
93
99
|
def category_name
|
94
100
|
category.name
|
95
101
|
end
|
96
102
|
|
97
|
-
# Returns the full name of an event, including all prefixes.
|
103
|
+
# Returns the canonical full name of an event, including all prefixes.
|
98
104
|
def full_name
|
99
105
|
"#{category.prefix}#{name}"
|
100
106
|
end
|
@@ -139,12 +145,12 @@ module MetaEvents
|
|
139
145
|
# Called with the set of options (which can be empty) supplied in the constructor; responsible for applying those
|
140
146
|
# to the object properly.
|
141
147
|
def apply_options!(options)
|
142
|
-
options.assert_valid_keys(:introduced, :desc, :description, :retired_at)
|
148
|
+
options.assert_valid_keys(:introduced, :desc, :description, :retired_at, :external_name)
|
143
149
|
|
144
150
|
introduced options[:introduced] if options[:introduced]
|
145
151
|
desc options[:desc] if options[:desc]
|
146
152
|
desc options[:description] if options[:description]
|
147
|
-
|
153
|
+
external_name options[:external_name] if options[:external_name]
|
148
154
|
|
149
155
|
@retired_at = Time.parse(options[:retired_at]) if options[:retired_at]
|
150
156
|
end
|
@@ -50,7 +50,7 @@ module MetaEvents
|
|
50
50
|
instance_eval(&block) if block
|
51
51
|
end
|
52
52
|
|
53
|
-
# Returns the prefix that all events in this version should have -- something like "
|
53
|
+
# Returns the prefix that all events in this version should have -- something like "pz1", for example.
|
54
54
|
def prefix
|
55
55
|
"#{definition_set.global_events_prefix}#{number}_"
|
56
56
|
end
|
data/lib/meta_events/tracker.rb
CHANGED
@@ -219,6 +219,22 @@ module MetaEvents
|
|
219
219
|
#
|
220
220
|
# We recommend that you keep the global events prefix short, simply because tools like Mixpanel often have a
|
221
221
|
# relatively small amount of screen real estate available for event names.
|
222
|
+
#
|
223
|
+
# ### Overriding Event Names
|
224
|
+
#
|
225
|
+
# There might be a situation where users performing analysis desire a friendlier name than the default.
|
226
|
+
# The external name can be customized with a lambda (or any object that responds to <tt>#call(event)</tt>).
|
227
|
+
# To customize the external name for all MetaEvents::Tracker instances,
|
228
|
+
# specify <tt>MetaEvents::Tracker.default_external_name = lambda { |event| "custom event name" }</tt>.
|
229
|
+
#
|
230
|
+
# To customize the external name for a specific MetaEvents::Tracker instance, pass the lambda
|
231
|
+
# in the constructor, for example:
|
232
|
+
# <tt>MetaEvents::Tracker.new(current_user.id, request.remote_ip, :external_name => lambda {|e| "#{e.full_name}_CUSTOM" })</tt>
|
233
|
+
#
|
234
|
+
# To reset default behavior back to the built-in default, simply set <tt>MetaEvents::Tracker.default_external_name = nil</tt>
|
235
|
+
#
|
236
|
+
# The event passed to external_name is an instance of ::MetaEvents::Definition::Event
|
237
|
+
#
|
222
238
|
class Tracker
|
223
239
|
class EventError < StandardError; end
|
224
240
|
class PropertyCollisionError < EventError; end
|
@@ -231,17 +247,34 @@ module MetaEvents
|
|
231
247
|
cattr_accessor :default_event_receivers
|
232
248
|
self.default_event_receivers = [ ]
|
233
249
|
|
234
|
-
# The set of event definitions from the MetaEvents DSL that MetaEvents::Tracker instances will use, by default (_i.e._, if not
|
235
|
-
# passed a separate definitions file using <tt>:definitions =></tt> in the constructor). You can set this to
|
236
|
-
# the pathname of a file containing event definitions, an +IO+ object containing the text of event definitions, or
|
237
|
-
# an ::MetaEvents::Definition::DefinitionSet object that you create any way you want.
|
238
|
-
#
|
239
|
-
# Reading +default_definitions+ always will return an instance of ::MetaEvents::Definition::DefinitionSet.
|
240
250
|
class << self
|
251
|
+
|
252
|
+
# The set of event definitions from the MetaEvents DSL that MetaEvents::Tracker instances will use, by default (_i.e._, if not
|
253
|
+
# passed a separate definitions file using <tt>:definitions =></tt> in the constructor). You can set this to
|
254
|
+
# the pathname of a file containing event definitions, an +IO+ object containing the text of event definitions, or
|
255
|
+
# an ::MetaEvents::Definition::DefinitionSet object that you create any way you want.
|
256
|
+
#
|
257
|
+
# Reading +default_definitions+ always will return an instance of ::MetaEvents::Definition::DefinitionSet.
|
241
258
|
def default_definitions=(source)
|
242
259
|
@default_definitions = ::MetaEvents::Definition::DefinitionSet.from(source)
|
243
260
|
end
|
244
261
|
attr_reader :default_definitions
|
262
|
+
|
263
|
+
# The built-in default calculation of an external event name, which is the event's <tt>:full_name</tt>
|
264
|
+
DEFAULT_EXTERNAL_NAME = lambda { |event| event.full_name }
|
265
|
+
|
266
|
+
# The default value that new MetaEvents::Tracker instances will use to provide external names for events.
|
267
|
+
def default_external_name=(provider)
|
268
|
+
if provider && !provider.respond_to?(:call)
|
269
|
+
raise ArgumentError, "default_external_name must respond to #call"
|
270
|
+
end
|
271
|
+
@default_external_name = provider
|
272
|
+
end
|
273
|
+
|
274
|
+
# If a default external name provider was not specified, use the built-in default.
|
275
|
+
def default_external_name
|
276
|
+
@default_external_name || DEFAULT_EXTERNAL_NAME
|
277
|
+
end
|
245
278
|
end
|
246
279
|
|
247
280
|
# The default version that new MetaEvents::Tracker instances will use to look up events in the MetaEvents DSL.
|
@@ -260,6 +293,9 @@ module MetaEvents
|
|
260
293
|
# The version of events that this Tracker is using.
|
261
294
|
attr_reader :version
|
262
295
|
|
296
|
+
# A method that provides the external name for an event.
|
297
|
+
attr_reader :external_name
|
298
|
+
|
263
299
|
# Creates a new instance.
|
264
300
|
#
|
265
301
|
# +distinct_id+ is the "distinct ID" of the user on behalf of whom events are going to be fired; this can be +nil+
|
@@ -297,8 +333,11 @@ module MetaEvents
|
|
297
333
|
# with every event fired from this Tracker. This can use the hash-merge and object syntax
|
298
334
|
# (#to_event_properties) documented above. Any properties explicitly passed with an event
|
299
335
|
# that have the same name as these properties will override these properties for that event.
|
336
|
+
# [:external_name] If present, this should be a lambda that takes a single argument and returns a string, or an
|
337
|
+
# object that responds to call(event). If +:external_name+ is not provided, it will use the
|
338
|
+
# default configured for the MetaEvents::Tracker class.
|
300
339
|
def initialize(distinct_id, ip, options = { })
|
301
|
-
options.assert_valid_keys(:definitions, :version, :implicit_properties, :event_receivers)
|
340
|
+
options.assert_valid_keys(:definitions, :version, :external_name, :implicit_properties, :event_receivers)
|
302
341
|
|
303
342
|
definitions = options[:definitions] || self.class.default_definitions
|
304
343
|
unless definitions
|
@@ -311,6 +350,8 @@ module MetaEvents
|
|
311
350
|
|
312
351
|
@definitions = ::MetaEvents::Definition::DefinitionSet.from(definitions)
|
313
352
|
@version = options[:version] || self.class.default_version || raise(ArgumentError, "Must specify a :version")
|
353
|
+
@external_name = options[:external_name] || self.class.default_external_name || raise(ArgumentError, "Must specify an :external_name")
|
354
|
+
raise ArgumentError, ":external_name option must respond to #call" unless @external_name.respond_to? :call
|
314
355
|
|
315
356
|
@implicit_properties = { }
|
316
357
|
self.class.merge_properties(@implicit_properties, { :ip => normalize_ip(ip).to_s }) if ip
|
@@ -346,19 +387,20 @@ module MetaEvents
|
|
346
387
|
event_data[:properties] = { 'time' => Time.now.to_i }.merge(event_data[:properties])
|
347
388
|
|
348
389
|
self.event_receivers.each do |receiver|
|
349
|
-
receiver.track(event_data[:distinct_id], event_data[:
|
390
|
+
receiver.track(event_data[:distinct_id], event_data[:external_name], event_data[:properties])
|
350
391
|
end
|
351
392
|
end
|
352
393
|
|
353
394
|
# Given a category, an event, and (optionally) additional properties, performs all of the expansion and validation
|
354
395
|
# of #event!, but does not actually fire the event -- rather, returns a Hash containing:
|
355
396
|
#
|
356
|
-
# [:distinct_id]
|
357
|
-
#
|
358
|
-
# [:event_name]
|
359
|
-
#
|
360
|
-
#
|
361
|
-
#
|
397
|
+
# [:distinct_id] The +distinct_id+ that should be passed with the event; this can be +nil+ if there is no distinct
|
398
|
+
# ID being passed.
|
399
|
+
# [:event_name] The fully-qualified event name, including +global_events_prefix+ and version number.
|
400
|
+
# [:external_name] The event name for use in an events backend.
|
401
|
+
# By default this is +:event_name+ but can be overridden.
|
402
|
+
# [:properties] The full set of properties, expanded (so values will only be scalars, never Hashes or objects),
|
403
|
+
# with String keys, exactly as they should be passed to an events system.
|
362
404
|
#
|
363
405
|
# This method can be used for many things, but its primary purpose is to support front-end (Javascript-fired)
|
364
406
|
# events: you can have it compute exactly the set of properties that should be attached to such events, embed
|
@@ -376,10 +418,14 @@ module MetaEvents
|
|
376
418
|
# We need to do this instead of just using || so that you can override a present distinct_id with nil.
|
377
419
|
net_distinct_id = if properties.has_key?('distinct_id') then properties.delete('distinct_id') else self.distinct_id end
|
378
420
|
|
421
|
+
event_external_name = event.external_name || external_name.call(event)
|
422
|
+
raise TypeError, "The external name of an event must be a String" unless event_external_name.kind_of?(String)
|
423
|
+
|
379
424
|
{
|
380
|
-
:distinct_id
|
381
|
-
:event_name
|
382
|
-
:
|
425
|
+
:distinct_id => net_distinct_id,
|
426
|
+
:event_name => event.full_name,
|
427
|
+
:external_name => event_external_name,
|
428
|
+
:properties => properties
|
383
429
|
}
|
384
430
|
end
|
385
431
|
|
data/lib/meta_events/version.rb
CHANGED
@@ -7,6 +7,7 @@ describe MetaEvents::ControllerMethods do
|
|
7
7
|
category :foo do
|
8
8
|
event :bar, '2014-01-31', 'this is bar'
|
9
9
|
event :baz, '2014-01-31', 'this is baz'
|
10
|
+
event :custom, '2014-01-31', 'this is quux', :external_name => 'super-amazing-custom'
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -50,11 +51,16 @@ describe MetaEvents::ControllerMethods do
|
|
50
51
|
end
|
51
52
|
|
52
53
|
describe "frontend-event registration" do
|
53
|
-
def expect_defined_event(name,
|
54
|
+
def expect_defined_event(name, external_name, properties, options = { })
|
55
|
+
expect_defined_event_with_event_name(name, external_name, external_name, properties, options)
|
56
|
+
end
|
57
|
+
|
58
|
+
def expect_defined_event_with_event_name(name, external_name, event_name, properties, options = { })
|
54
59
|
expected_distinct_id = options[:distinct_id] || 'abc123'
|
55
60
|
expect(@obj.meta_events_defined_frontend_events[name]).to eq({
|
56
61
|
:distinct_id => expected_distinct_id,
|
57
62
|
:event_name => event_name,
|
63
|
+
:external_name => external_name,
|
58
64
|
:properties => properties
|
59
65
|
})
|
60
66
|
|
@@ -63,7 +69,7 @@ describe MetaEvents::ControllerMethods do
|
|
63
69
|
js =~ /["']#{name}["']\s*,\s*(.*?)\s*\)\s*\;/i
|
64
70
|
matched = $1
|
65
71
|
hash = JSON.parse($1)
|
66
|
-
expect(hash).to eq('distinct_id' => expected_distinct_id, 'event_name' => event_name, 'properties' => properties)
|
72
|
+
expect(hash).to eq('distinct_id' => expected_distinct_id, 'event_name' => event_name, 'external_name' => external_name, 'properties' => properties)
|
67
73
|
end
|
68
74
|
|
69
75
|
it "should work fine if there are no registered events" do
|
@@ -99,6 +105,11 @@ describe MetaEvents::ControllerMethods do
|
|
99
105
|
expect_defined_event('foo_bar', 'xy1_foo_bar', { 'imp1' => 'imp1val2', 'a_b' => 'c', 'a_d' => 'e' })
|
100
106
|
end
|
101
107
|
|
108
|
+
it "should use an overridden external_name" do
|
109
|
+
@obj.meta_events_define_frontend_event(:foo, :custom, { :imp1 => 'imp1val1' })
|
110
|
+
expect_defined_event_with_event_name('foo_custom', 'super-amazing-custom', 'xy1_foo_custom', { 'imp1' => 'imp1val1' })
|
111
|
+
end
|
112
|
+
|
102
113
|
context "with one simple defined event" do
|
103
114
|
before :each do
|
104
115
|
@obj.meta_events_define_frontend_event(:foo, :bar, { :quux => 123 })
|
@@ -52,6 +52,11 @@ describe ::MetaEvents::Definition::Event do
|
|
52
52
|
expect(klass.new(category, :foo, "2014-01-01") { desc 'foobar' }.desc).to eq("foobar")
|
53
53
|
end
|
54
54
|
|
55
|
+
it "should let you set external_name via both mechanisms" do
|
56
|
+
expect(klass.new(category, :foo, "2014-01-01", "foobar", :external_name => "custom external name").external_name).to eq("custom external name")
|
57
|
+
expect(klass.new(category, :foo, "2014-01-01", "foobar") { external_name "custom external name" }.external_name).to eq("custom external name")
|
58
|
+
end
|
59
|
+
|
55
60
|
context "with an instance" do
|
56
61
|
let(:instance) { klass.new(category, :foo, "2014-01-01", "foobar") }
|
57
62
|
|
@@ -142,5 +147,15 @@ describe ::MetaEvents::Definition::Event do
|
|
142
147
|
expect(note_2[:who]).to eq("someone else")
|
143
148
|
expect(note_2[:text]).to eq("whatever")
|
144
149
|
end
|
150
|
+
|
151
|
+
context "with a custom external name" do
|
152
|
+
let(:instance) { klass.new(category, :foo, "2014-01-01", "foobar", :external_name => "custom external name") }
|
153
|
+
|
154
|
+
it "should return and allow setting its external name via #external_name" do
|
155
|
+
expect(instance.external_name).to eq("custom external name")
|
156
|
+
instance.external_name "my name"
|
157
|
+
expect(instance.external_name).to eq("my name")
|
158
|
+
end
|
159
|
+
end
|
145
160
|
end
|
146
161
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require "active_support"
|
1
2
|
require 'active_support/core_ext/numeric/time'
|
2
3
|
require 'ipaddr'
|
3
4
|
|
@@ -8,7 +9,7 @@ describe MetaEvents::Tracker do
|
|
8
9
|
version 1, '2014-01-31' do
|
9
10
|
category :foo do
|
10
11
|
event :bar, '2014-01-31', 'this is bar'
|
11
|
-
event :baz, '2014-01-31', 'this is baz'
|
12
|
+
event :baz, '2014-01-31', 'this is baz', :external_name => 'foo bazzeroo'
|
12
13
|
event :nolonger, '2014-01-31', 'should be retired', :retired_at => '2020-01-01'
|
13
14
|
end
|
14
15
|
end
|
@@ -299,11 +300,92 @@ EOS
|
|
299
300
|
end
|
300
301
|
|
301
302
|
it "should pick up the default version from the class" do
|
302
|
-
klass.default_version
|
303
|
+
original_default_version = klass.default_version
|
303
304
|
|
304
|
-
|
305
|
-
|
306
|
-
|
305
|
+
begin
|
306
|
+
klass.default_version = 2
|
307
|
+
|
308
|
+
i = klass.new(@distinct_id, nil, :event_receivers => receiver_1, :definitions => definition_set)
|
309
|
+
i.event!(:foo, :quux)
|
310
|
+
expect_event("xy2_foo_quux", { })
|
311
|
+
ensure
|
312
|
+
klass.default_version = original_default_version
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
it "should use the default external name from the class" do
|
317
|
+
begin
|
318
|
+
klass.default_external_name = lambda { |event| "#{event.category_name}-super-custom-#{event.name}" }
|
319
|
+
|
320
|
+
i = klass.new(@distinct_id, nil, :event_receivers => receiver_1, :definitions => definition_set)
|
321
|
+
i.event!(:foo, :bar, { })
|
322
|
+
expect_event('foo-super-custom-bar', { })
|
323
|
+
ensure
|
324
|
+
klass.default_external_name = nil
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
it "should allow resetting the default external name from the class back to the built-in default" do
|
329
|
+
begin
|
330
|
+
klass.default_external_name = lambda { |event| "#{event.category_name}-super-custom-#{event.name}" }
|
331
|
+
|
332
|
+
i = klass.new(@distinct_id, nil, :event_receivers => receiver_1, :definitions => definition_set)
|
333
|
+
i.event!(:foo, :bar, { })
|
334
|
+
expect_event('foo-super-custom-bar', { })
|
335
|
+
|
336
|
+
klass.default_external_name = nil
|
337
|
+
|
338
|
+
i = klass.new(@distinct_id, nil, :event_receivers => receiver_1, :definitions => definition_set)
|
339
|
+
i.event!(:foo, :bar, { })
|
340
|
+
expect_event('xy1_foo_bar', { })
|
341
|
+
ensure
|
342
|
+
klass.default_external_name = nil
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
it "should allow overriding the external name in the constructor" do
|
347
|
+
i = new_instance(@distinct_id, nil, :definitions => definition_set, :external_name => lambda { |event| "#{event.category_name}-super-custom-#{event.name}" })
|
348
|
+
i.event!(:foo, :bar, { })
|
349
|
+
expect_event('foo-super-custom-bar', { })
|
350
|
+
end
|
351
|
+
|
352
|
+
it "should require the result of the external name to be a string" do
|
353
|
+
expect {
|
354
|
+
i = new_instance(@distinct_id, nil, :definitions => definition_set, :external_name => lambda { |event| 1234 })
|
355
|
+
i.event!(:foo, :bar, { })
|
356
|
+
}.to raise_error(TypeError, /external name/i)
|
357
|
+
end
|
358
|
+
|
359
|
+
context "with default_external_name set" do
|
360
|
+
before :each do
|
361
|
+
klass.default_external_name = lambda { |event| "default-#{event.category_name}-#{event.name}-custom" }
|
362
|
+
end
|
363
|
+
|
364
|
+
after :each do
|
365
|
+
klass.default_external_name = nil
|
366
|
+
end
|
367
|
+
|
368
|
+
it "should return event external_name if set" do
|
369
|
+
i = new_instance(@distinct_id, nil, :definitions => definition_set, :external_name => lambda { |event| "#{event.category_name}-#{event.name}-custom" })
|
370
|
+
i.event!(:foo, :baz, { })
|
371
|
+
expect_event('foo bazzeroo', { })
|
372
|
+
end
|
373
|
+
|
374
|
+
context "no event external_name is set" do
|
375
|
+
it "should return instance external_name" do
|
376
|
+
i = new_instance(@distinct_id, nil, :definitions => definition_set, :external_name => lambda { |event| "#{event.category_name}-#{event.name}-custom" })
|
377
|
+
i.event!(:foo, :bar, { })
|
378
|
+
expect_event('foo-bar-custom', { })
|
379
|
+
end
|
380
|
+
|
381
|
+
context "no instance external_name is set" do
|
382
|
+
it "should return default_external_name" do
|
383
|
+
i = new_instance(@distinct_id, nil, :definitions => definition_set)
|
384
|
+
i.event!(:foo, :bar, { })
|
385
|
+
expect_event('default-foo-bar-custom', { })
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
307
389
|
end
|
308
390
|
|
309
391
|
it "should allow firing a valid event, and include implicit properties" do
|
@@ -413,7 +495,7 @@ EOS
|
|
413
495
|
end
|
414
496
|
|
415
497
|
it "should include no additional keys" do
|
416
|
-
expect(@instance.effective_properties(:foo, :bar).keys.sort_by(&:to_s)).to eq(%w{distinct_id event_name properties}.map(&:to_sym).sort_by(&:to_s))
|
498
|
+
expect(@instance.effective_properties(:foo, :bar).keys.sort_by(&:to_s)).to eq(%w{distinct_id event_name external_name properties}.map(&:to_sym).sort_by(&:to_s))
|
417
499
|
end
|
418
500
|
end
|
419
501
|
|
@@ -92,7 +92,7 @@ MetaEvents = (function() {
|
|
92
92
|
*
|
93
93
|
* @param name - The name that we'll use to access this event, using 'event', below; this is different from the name
|
94
94
|
* of the actual event that will be fired and need not have any correlation;
|
95
|
-
* @param eventData - The data for the event; this must be an object containing '
|
95
|
+
* @param eventData - The data for the event; this must be an object containing 'external_name', which is the name of
|
96
96
|
* the event to fire, and 'properties', the set of properties to fire with that event.
|
97
97
|
*/
|
98
98
|
out.registerFrontendEvent = function(name, eventData) {
|
@@ -128,14 +128,15 @@ MetaEvents = (function() {
|
|
128
128
|
$.extend(effectiveProperties, arguments[i]);
|
129
129
|
}
|
130
130
|
|
131
|
-
|
131
|
+
var external_name = eventData.external_name || eventData.event_name;
|
132
|
+
this.eventHandler(external_name, effectiveProperties);
|
132
133
|
};
|
133
134
|
|
134
135
|
/**
|
135
136
|
* The default event handler that we use if you haven't called setEventHandler(), below.
|
136
137
|
*/
|
137
|
-
out.mixpanelEventHandler = function(
|
138
|
-
mixpanel.track(
|
138
|
+
out.mixpanelEventHandler = function(externalName, properties) {
|
139
|
+
mixpanel.track(externalName, properties);
|
139
140
|
};
|
140
141
|
|
141
142
|
/**
|
metadata
CHANGED
@@ -1,100 +1,82 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: meta_events
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Andrew Geweke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
|
12
|
+
date: 2014-05-25 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
14
15
|
name: json
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.0'
|
20
|
-
type: :runtime
|
21
16
|
prerelease: false
|
22
|
-
|
23
|
-
requirements:
|
24
|
-
- -
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: activesupport
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.0'
|
34
|
-
- - "<="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 4.99.99
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: "1.0"
|
37
22
|
type: :runtime
|
23
|
+
version_requirements: *id001
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: activesupport
|
38
26
|
prerelease: false
|
39
|
-
|
40
|
-
requirements:
|
27
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
41
29
|
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version:
|
44
|
-
- -
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 4.
|
47
|
-
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "3.0"
|
32
|
+
- - <
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "4.0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
48
38
|
name: bundler
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '1.5'
|
54
|
-
type: :development
|
55
39
|
prerelease: false
|
56
|
-
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version:
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: rake
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - ">="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '0'
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "1.5"
|
68
45
|
type: :development
|
46
|
+
version_requirements: *id003
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
69
49
|
prerelease: false
|
70
|
-
|
71
|
-
requirements:
|
72
|
-
-
|
73
|
-
-
|
74
|
-
|
75
|
-
|
76
|
-
name: rspec
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - "~>"
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '2.14'
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- &id006
|
53
|
+
- ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
82
56
|
type: :development
|
57
|
+
version_requirements: *id004
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rspec
|
83
60
|
prerelease: false
|
84
|
-
|
85
|
-
requirements:
|
86
|
-
- -
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version:
|
61
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "2.14"
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id005
|
89
68
|
description:
|
90
|
-
email:
|
69
|
+
email:
|
91
70
|
- ageweke@swiftype.com
|
92
71
|
executables: []
|
72
|
+
|
93
73
|
extensions: []
|
74
|
+
|
94
75
|
extra_rdoc_files: []
|
95
|
-
|
96
|
-
|
97
|
-
-
|
76
|
+
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- .travis.yml
|
98
80
|
- CHANGES.md
|
99
81
|
- Gemfile
|
100
82
|
- LICENSE.txt
|
@@ -121,31 +103,29 @@ files:
|
|
121
103
|
- spec/meta_events/tracker_spec.rb
|
122
104
|
- vendor/assets/javascripts/meta_events.js.erb
|
123
105
|
homepage: http://www.github.com/swiftype/meta_events
|
124
|
-
licenses:
|
106
|
+
licenses:
|
125
107
|
- MIT
|
126
108
|
metadata: {}
|
109
|
+
|
127
110
|
post_install_message:
|
128
111
|
rdoc_options: []
|
129
|
-
|
112
|
+
|
113
|
+
require_paths:
|
130
114
|
- lib
|
131
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
-
requirements:
|
133
|
-
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
requirements:
|
138
|
-
- - ">="
|
139
|
-
- !ruby/object:Gem::Version
|
140
|
-
version: '0'
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- *id006
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- *id006
|
141
121
|
requirements: []
|
122
|
+
|
142
123
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.0.14
|
144
125
|
signing_key:
|
145
126
|
specification_version: 4
|
146
|
-
summary: Structured, documented, powerful event emitting library for Mixpanel and
|
147
|
-
|
148
|
-
test_files:
|
127
|
+
summary: Structured, documented, powerful event emitting library for Mixpanel and other such systems.
|
128
|
+
test_files:
|
149
129
|
- spec/meta_events/controller_methods_and_helpers_spec.rb
|
150
130
|
- spec/meta_events/definition/category_spec.rb
|
151
131
|
- spec/meta_events/definition/definition_set_spec.rb
|