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

Alias support #68

Closed tonydaly closed 11 years ago

tonydaly commented 11 years ago

Is there a way to use the mixpanel.alias() with this gem?

mixellent commented 11 years ago

This gem does not yet have direct support for Aliasing, since aliasing is only supported starting version 2.2 of the mixpanel js library.

But there is a way to do it - by using the track method as follows:

@mixpanel.track "$create_alias", { :distinct_id => "32423sfsdsdf", :alias => user.id} 
skyshard commented 11 years ago

would there be any issues with monkey patching render_mixpanel_scripts (https://github.com/zevarito/mixpanel/blob/master/lib/mixpanel/middleware.rb#L83) to embed 2.2?

mixellent commented 11 years ago

You can do it (you would need to add the 'alias' method ref besides just the version number change), but the alias call would still not work this way (I tried the monkeypatch on a fork). You can use the above track method I provided for applying aliasing.

edmar commented 11 years ago

How can I get the auto generated distinct id in order to alias it ?

tomtaylor commented 11 years ago

There's a fork at quadule/mixpanel that supports Mixpanel 2.2 and the alias methods. I've not tried it, but if it works, it probably makes sense to merge in.

zevarito commented 11 years ago

Yes, if it works would make sense to merge it.

quadule commented 11 years ago

Hey that's me! I'm using my fork in production with no issues.

If you're thinking of merging it, I should note that I replaced the tracker's append_people_identify method with append_identify, following Mixpanel's 2.2 API changes. I'm not sure how you want to handle API changes in this project, but you may want to add the method back with a deprecation notice.

mattgibson commented 11 years ago

This works fine for me after adding the latest javascript snippet: mixpanel.append('alias', user.email) Using append_identify works fine for registering people changes for me too.

zevarito commented 11 years ago

I think we should offer both versions of Mixpanel API. And let old one as the default one with deprecation notes until a new release that changes the default lib. What do you think?

mattgibson commented 11 years ago

I am still using my fork with the JS pasted into it in production (from #74 ) with no issues. Would be nice to be able to move back to the master branch of this gem. Why not move to a new point release and switch to the new API? Alias support is really necessary for me and is a core part of Mixpanel's docs. How long since the API changed?

Meekohi commented 11 years ago

Hey for everyone trying to figure this out. This worked alright for me:

mpjson = JSON.parse(cookies["mp_#{Rails.application.settings[ :mixpanel_api_token ]}_mixpanel"])
mixpanel.track "$create_alias", { :distinct_id => mpjson["distinct_id"], :alias => user.username}
mixpanel.set user.username, {:email => user.email, :ip => request.remote_ip, :name => user.username}
zevarito commented 11 years ago

89

zevarito commented 11 years ago

Version 4.0.0 is ready with this changes. Sorry about the delay, I've been running crazy without time lately.