zevarito / mixpanel

Simple lib to track events in Mixpanel service. It can be used in any rack based framework.
MIT License
273 stars 84 forks source link

People Tracking #45

Closed sturgill closed 12 years ago

sturgill commented 12 years ago

This gem has done well with pushing events from a backend server, but I wasn't sure how to use it to push changes to people (using the set and add methods).

Sample code to set an attribute:

mixpanel = Mixpanel::Tracker.new TOKEN, env, {:action => :person}
mixpanel.update_person UNIQUE_IDENTIFIER, :set, {'$email' => 'me@domain.com'}

Sample code to use the increment function:

mixpanel = Mixpanel::Tracker.new TOKEN, env, {:action => :person}
mixpanel.update_person UNIQUE_IDENTIFIER, :add, {'Points Earned' => 500}

The update_person method takes 3 parameters: the unique identifier, what action to take (either :set or :add) and a hash of values to pass to the server (consistent with the JS API).

In Mixpanel::Tracker.new, the options hash no longer has an :import key, but has an :action key (as shown above) that can be set to one of three options: :track, :import, and :person. The default value is :track unless otherwise set.

zevarito commented 12 years ago

Hi @sturgill,

Please take a look at this commit https://github.com/zevarito/mixpanel/pull/46

it adds engage endpoint as well, I've take sometime to check both before merge. Thanks!

sturgill commented 12 years ago

Following yesterday's back and forth with @GBH, I ended up rewriting a lot of the gem. This new approach allows for a single Mixpanel object to process multiple types of requests (track, import, set, increment, etc.).

It wouldn't be backward compatible with the current gem, but the code is a bit more organized and extendible.

zevarito commented 12 years ago

Hi @sturgill, @GBH,

This feature implementation has become a big refactor, here is most of the code, but the discussion about implementation is happening in the other thread, so I will close this one for sake of simplicity and let's go back to the other one to continue the discussion.

https://github.com/zevarito/mixpanel/pull/46