Identify Mixpanel User Actions Before Logging In

I am having trouble identifying Mixpanel. I want to track events registered before a user logs in and identify them as such.

Here is an example. Louis opens a web page and visits the About page. Using mixpanel.track('Visit About') , I can register an anonymous visit to Louies. Everything is alright and dandy.

Louis decides to log in, and a call to mixpanel.identify(user.id) identifies him - and subsequent events can be tracked by Louis. However, the first event ("Visit about") still displays with a random, distinct Mixpanel ID and is not associated with Louie.

Is this behavior expected? What can I do? Greetings

+5
source share
2 answers

You want alias .

From the JavaScript API link :

Use an alias () when a unique identifier is first assigned (registration), and use the identification function () to identify the user with this unique identifier on an ongoing basis (for example, every time a user registers after registration). Do not call ident () at the same time as the alias ().

From your description, this sounds, rather than viewing the anonymous About page, and then logging in, Louis anonymously looks at the About page, and then signs.

In this case, call alias when Louie logs in, and call identify when he logs in after that. This should associate a random, anonymous Mixpanel identifier with the newly registered Louie user ID.

Note. Using this method will mean that since Louis triggered the event anonymously and then logged in, Louis's anonymous identifier for this event will not be associated with his separate identifier from the login. If he registered after starting an anonymous event, you would call alias and they would be connected. Unfortunately, this is a known limitation of Mixpanel. From their documentation:

This is the first time he accessed your site from this device, so we assign him a new distinct_id. He clicks and then logs in. In this situation, you should not call mixpanel.alias () - we have not seen him on this device, but he is not a new user .... Instead of calling mixpanel.alias (), you should simply call mixpanel.identify (). This reassigns his phone activity to the original identifier that he used when registering for your service, which is the most desirable result. This means that, unfortunately, the events that he fired before entering the system will not be associated with him.

Read more about aliasing in Mixpanel here .

+4
source

Alias does not work for the scenario when an existing user logs in, but I found a job for this.

When the user logs in for the first time, check to see if the request cookie drive_file matches the user ID.

If they do not match, create a backend task to populate the anonymous_Disk_ID to user_disk_id.

Download events using JQL, then run them again using the mixpanel import endpoint.

The downside is that you will have recurring events in the system, as there is no way to remove events from anonymous_drive.

For imported events, you can add a property to them indicating that they are imported so that they can be filtered out if necessary.

0
source

Source: https://habr.com/ru/post/1241154/


All Articles