How to use distinct_id correctly in mixpanel

I am trying to create a mixpanel funnel using PHP which includes the following events

  • Home page view
  • check in
  • View toolbar
  • Code posted

I am currently doing this without using a differ_id and so the trend trend of the myth is pretty accurate, but the sequence depending on the unique number of users gives false data.

How can I use distinct_id property to solve this problem?


source to share

1 answer

I am not a PHP developer but I am currently working with Mixpanel and just faced a similar problem. You have two options: force a unique ID on the frontend that can also be easily identified on the backend (like a user ID), or use the default ID provided if you are making calls from the backend. The first option can cause some integrity errors, especially if you're trying to create a funnel that includes something like user registration. The second option, however, is pretty reliable:

Mixpanel sets a cookie named "mp_YOUR-PROJECT-TOKEN-HERE_mixpanel" for each user. This cookie contains, among other things, the idd_disk file that Mixpanel uses for this user for events triggered from the interface. If you retrieve this value from the cookie and explicitly pass it as the distinct_id parameter for Mixpanel calls to the backend, you should get consistent streams and workflows.

Note that for ease of use, Mixpanel also allows you to specify the cookie name as an argument to set_config or init in external javascript:

mixpanel.init("PROJECT-TOKEN-HERE", {cookie_name: foo})


Though for some reason this gives you a cookie named "mp_foo" instead of "foo". Anyway, good luck.



All Articles