Question

Using API for Identity Management

  • 16 September 2020
  • 2 replies
  • 69 views

Hello,

When a user signs up for an account in my app, I would like to create an alias for that user via HTTP. I understand the $create_alias event requires including the distinct_id parameter (as described here: https://help.mixpanel.com/hc/en-us/articles/115004495783-Assigning-Your-Own-Unique-IDs-to-Users and here https://developer.mixpanel.com/reference/http#create_alias). How do I get the distinct_id parameter for the user via HTTP?

Thanks!


2 replies

Userlevel 1
Badge +1

Hi @mkerp,

Are you by chance setting up a Hybrid Server/Client implementation as described in this help article


If yes, you can rely on the Mixpanel JavaScript library to store a distinct_id locally on the device. You can pass it to your server via a form (as shown in the code snippet below) or parse the cookie directly. 

$(function(){
var myForm = $("#myForm");
//track the page load
mixpanel.track("Page load", {"Page": "Signup Form"});

/*
Listen to the form being submitted;
before it sends the request, the current distinct ID will be added
*/

myForm.submit(function(event){
var hiddenInput = myForm.find("input[name='distinct_id']");
hiddenInput[0].value = mixpanel.get_distinct_id();
});
});

 

If you have ID Merge enabled, you can identify users at both signup and login, and skip creating aliases. 

 

Hope this helps!
Cassie

Thanks Cassie! The last point regarding ID Merge was exactly what I needed to hear. I had missed that point in the documentation.

Reply


Mixpanel