mixpanel-ruby 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ *~
1
2
  Gemfile.lock
2
3
  html
3
4
  mixpanel-ruby*.gem
@@ -51,6 +51,11 @@ module Mixpanel
51
51
  # Mixpanel::Consumer is the default consumer. It sends each message,
52
52
  # as the message is recieved, directly to Mixpanel.
53
53
  class Consumer
54
+
55
+ # Create a Mixpanel::Consumer. If you provide endpoint arguments,
56
+ # they will be used instead of the default Mixpanel endpoints.
57
+ # This can be useful for proxying, debugging, or if you prefer
58
+ # not to use SSL for your events.
54
59
  def initialize(events_endpoint=nil, update_endpoint=nil)
55
60
  @events_endpoint = events_endpoint || 'https://api.mixpanel.com/track'
56
61
  @update_endpoint = update_endpoint || 'https://api.mixpanel.com/engage'
@@ -58,6 +63,10 @@ module Mixpanel
58
63
 
59
64
  # Send the given string message to Mixpanel. Type should be
60
65
  # one of :event or :profile_update, which will determine the endpoint.
66
+ #
67
+ # Mixpanel::Consumer#send sends messages to Mixpanel immediately on
68
+ # each call. To reduce the overall bandwidth you use when communicating
69
+ # with Mixpanel, you can also use Mixpanel::BufferedConsumer
61
70
  def send(type, message)
62
71
  type = type.to_sym
63
72
  endpoint = {
@@ -106,6 +115,15 @@ module Mixpanel
106
115
  class BufferedConsumer
107
116
  MAX_LENGTH = 50
108
117
 
118
+ # Create a Mixpanel::BufferedConsumer. If you provide endpoint arguments,
119
+ # they will be used instead of the default Mixpanel endpoints.
120
+ # This can be useful for proxying, debugging, or if you prefer
121
+ # not to use SSL for your events.
122
+ #
123
+ # You can also change the preferred buffer size before the
124
+ # consumer automatically sends its buffered events. The Mixpanel
125
+ # endpoints have a limit of 50 events per HTTP request, but
126
+ # you can lower the limit if your individual events are very large.
109
127
  def initialize(events_endpoint=nil, update_endpoint=nil, max_buffer_length=MAX_LENGTH)
110
128
  @max_length = [ max_buffer_length, MAX_LENGTH ].min
111
129
  @consumer = Consumer.new(events_endpoint, update_endpoint)
@@ -10,7 +10,7 @@ module Mixpanel
10
10
  # to instantiate this class directly- to send
11
11
  # profile updates, use Mixpanel::Tracker#people
12
12
  #
13
- # tracker = Mixpanel::Tracker.new
13
+ # tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
14
14
  # tracker.people.set(...) # Or .append(..), or track_charge(...) etc.
15
15
  class People
16
16
 
@@ -42,7 +42,7 @@ module Mixpanel
42
42
  # 'Sign-Up Date' => DateTime.now
43
43
  # });
44
44
  #
45
- # If you provide an ip argument, Mixpanel will use that
45
+ # If you provide an ip argument, \Mixpanel will use that
46
46
  # ip address for geolocation (rather than the ip of your server)
47
47
  def set(distinct_id, properties, ip=nil)
48
48
  properties = fix_property_dates(properties)
@@ -83,7 +83,7 @@ module Mixpanel
83
83
  end
84
84
 
85
85
  # Changes the value of properties by a numeric amount. Takes a
86
- # hash with string keys and numeric properties. Mixpanel will add
86
+ # hash with string keys and numeric properties. \Mixpanel will add
87
87
  # the given amount to whatever value is currently assigned to the
88
88
  # property. If no property exists with a given name, the value
89
89
  # will be added to zero.
@@ -167,7 +167,7 @@ module Mixpanel
167
167
  end
168
168
 
169
169
  # Records a payment to you to a profile. Charges recorded with
170
- # #track_charge will appear in the Mixpanel revenue report.
170
+ # #track_charge will appear in the \Mixpanel revenue report.
171
171
  #
172
172
  # tracker = Mixpanel::Tracker.new
173
173
  #
@@ -185,12 +185,12 @@ module Mixpanel
185
185
  append(distinct_id, { '$transactions' => charge_properties }, ip)
186
186
  end
187
187
 
188
- # Clear all charges from a Mixpanel people profile
188
+ # Clear all charges from a \Mixpanel people profile
189
189
  def clear_charges(distinct_id)
190
190
  unset(distinct_id, '$transactions')
191
191
  end
192
192
 
193
- # Permanently delete a profile from Mixpanel people analytics
193
+ # Permanently delete a profile from \Mixpanel people analytics
194
194
  def delete_user(distinct_id)
195
195
  update({
196
196
  '$distinct_id' => distinct_id,
@@ -198,12 +198,13 @@ module Mixpanel
198
198
  })
199
199
  end
200
200
 
201
- # Send a generic update to Mixpanel people analytics.
202
- # Caller is responsible for formatting the update, as
203
- # documented in the Mixpanel HTTP specification. This
201
+ # Send a generic update to \Mixpanel people analytics.
202
+ # Caller is responsible for formatting the update message, as
203
+ # documented in the \Mixpanel HTTP specification, and passing
204
+ # the message as a dict to #update. This
204
205
  # method might be useful if you want to use very new
205
206
  # or experimental features of people analytics from Ruby
206
- # The Mixpanel HTTP tracking API is documented at
207
+ # The \Mixpanel HTTP tracking API is documented at
207
208
  # http://joe.dev.mixpanel.org/help/reference/http
208
209
  def update(message)
209
210
  message = {
@@ -13,6 +13,9 @@ module Mixpanel
13
13
  # tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
14
14
  # tracker.people.set(a_distinct_id, { properties })
15
15
  #
16
+ # You can find your project token in the settings dialog for your
17
+ # project, inside of the Mixpanel web application.
18
+ #
16
19
  # Mixpanel::Tracker is a subclass of Mixpanel::Events, and exposes
17
20
  # an instance of Mixpanel::People as Tracker#people
18
21
  class Tracker < Events
@@ -45,6 +48,30 @@ module Mixpanel
45
48
  @people = People.new(token, &block)
46
49
  end
47
50
 
51
+ # A call to #track is a report that an event has occurred. #track
52
+ # takes a distinct_id representing the source of that event (for
53
+ # example, a user id), an event name describing the event, and a
54
+ # set of properties describing that event. Properties are provided
55
+ # as a Hash with string keys and strings, numbers or booleans as
56
+ # values.
57
+ #
58
+ # tracker = Mixpanel::Tracker.new
59
+ #
60
+ # # Track that user "12345"'s credit card was declined
61
+ # tracker.track("12345", "Credit Card Declined")
62
+ #
63
+ # # Properties describe the circumstances of the event,
64
+ # # or aspects of the source or user associated with the event
65
+ # tracker.track("12345", "Welcome Email Sent", {
66
+ # 'Email Template' => 'Pretty Pink Welcome',
67
+ # 'User Sign-up Cohort' => 'July 2013'
68
+ # })
69
+ def track(distinct_id, event, properties={}, ip=nil)
70
+ # This is here strictly to allow rdoc to include the relevant
71
+ # documentation
72
+ super
73
+ end
74
+
48
75
  # Creates a distinct_id alias. \Events and updates with an alias
49
76
  # will be considered by mixpanel to have the same source, and
50
77
  # refer to the same profile.
@@ -1,3 +1,3 @@
1
1
  module Mixpanel
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'mixpanel-ruby/events.rb'
3
+ require 'mixpanel-ruby/version.rb'
3
4
  require 'time'
4
5
 
5
6
  describe Mixpanel::Events do
@@ -22,6 +23,8 @@ describe Mixpanel::Events do
22
23
  'properties' => {
23
24
  'Circumstances' => 'During a test',
24
25
  'distinct_id' => 'TEST ID',
26
+ 'mp_lib' => 'ruby',
27
+ '$lib_version' => Mixpanel::VERSION,
25
28
  'token' => 'TEST TOKEN',
26
29
  'time' => 76695784
27
30
  }
@@ -39,6 +39,8 @@ describe Mixpanel::Tracker do
39
39
  'properties' => {
40
40
  'Circumstances' => 'During test',
41
41
  'distinct_id' => 'TEST ID',
42
+ 'mp_lib' => 'ruby',
43
+ '$lib_version' => Mixpanel::VERSION,
42
44
  'token' => 'TEST TOKEN',
43
45
  'time' => 76695784
44
46
  }
@@ -59,6 +61,8 @@ describe Mixpanel::Tracker do
59
61
  { 'event' => 'Event',
60
62
  'properties' => {
61
63
  'distinct_id' => 'ID',
64
+ 'mp_lib' => 'ruby',
65
+ '$lib_version' => Mixpanel::VERSION,
62
66
  'token' => 'TEST TOKEN',
63
67
  'time' => 76695784
64
68
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixpanel-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: