Get Mixpanel distinct_id for server-side tracking

I am currently setting up Mixpanel. I now try to find a way to get the distinct_id for my server-side tracking. I first implemented it with a function as seen here:

ajs_anonymous_id = segment_get_ajs_anonymous_id(request)
        if ajs_anonymous_id:
            analytics.alias(user.email, ajs_anonymous_id)

But I realised that Segments anonymous_id is not the one used for distinct_id on Mixpanel. Now my question is how do I get the distinct_id? Or is there a way to set the distinct_id to the anonymous_id when a not logged in person is visiting my page?

3replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Hi Marc,


    Thanks for getting in touch! You're pretty close with your implementation! You'll need to be sure to use the Ready method so that the page (including Segment and Mixpanel) loads entirely before you attempt to grab the distinct_id. According to Mixpanel's documentation, you can use the get_distinct_id function to obtain the value of the current user's distinct_id. All in all, a Javascript implementation would look like this:


    let distinctId;
    analytics.ready(function() {
      distinctId = window.mixpanel.get_distinct_id();
    console.log(distinctId); //"13bbf7943e584-0885c2531-5c793977-3e8000-13bbf7943e64cf"


    I believe you would need to grab the distinct_id client-side and send it to the server manually. I don't think it will be directly available on the server automatically.

    I hope that helps!


    Success Engineer | Segment

    Reply Upvote
  • In such cases I simply ask my hosting provider to check the system. I have forgotten to do it my self since I have started to work with Zomro.net Their technical support is very qualified. 

    Reply Upvote
  • Frank Davis A lot of things depend on the qualified hosting support. There are enough new hosts that have not yet gained the quality of service. In such cases, I simply communicate with the ice on the forum or look for reviews to form an opinion on such companies before using their services.

    Reply Upvote