Solved

AppsFlyer integration - Android

  • 2 January 2019
  • 4 replies
  • 287 views

Badge

Hi guys,

I was integrating the Mixpanel framework to identify the users. Basically, I’m using the ‘identify’ and ‘alias’ methods. I was able to verify this is working properly on the Explore section on dashboard.

Now, I need to integrate AppsFlyer framework to get the source attribution tracking. Basically, what I did was to set the ‘customer user id’ as the “Mixpanel.distinctId”. However, when I do this, the user profile contains the “Media Source”, but it does not include other properties like: name, email and id. I’m adding these properties using the mixpanel.getPeople().identify and mixpanel.getPeople().set.

Could you help on this? I’m attaching the profile that I’m getting after tracking the install source.



icon

Best answer by sehyris 17 July 2019, 22:33

Thanks for the help.

We fixed this issue calling 'alias' only on the sign ups and 'identify' only on the logins.


View original

4 replies

Userlevel 5
Badge +3

Hi @sehyris,

To integrate AppsFlyer into your Mixpanel project you can take two routes:

OPTION 1
Make the customUser_id equal to the mixpanel.getDistinct_id referenced here at app launch. You can use AppsFlyers setCustomerUserId SDK function to do this. This is the option that you elected and is the simplest option if you are only sending information from AppsFlyer to mixpanel (and not any other product).

OPTION 2, the inverse
Alternatively, you could change mixpanel's default distinct id to the customUser_id using the mixpanel.identify() and mixpanel.getPeople().identify() methods documented here.


---
For any future profile updates , (name, email and id) you will need to make sure that the distinct_id is equal to whatever option you chose above to make sure that the update shows up for the same profile. For more context, anytime a people property update is sent to Mixpanel, it will either update the profile of the same distinct_id, or it will create a new profile if the distinct_id does not already have a profile.


---
For more background, when a user first downloads your app the Mixpanel iOS and Android libraries assign a unique identifier which we call a distinct_id. The distinct_id sent with each event and profile update cannot be modified or updated once it is sent to Mixpanel. This means that in order to tie the install event together with app launch, registration and future events, we need the distinct_id to be the same from the start.


Badge

Hi @cherise, thanks for your reply.

Yes, I think I'm doing that. For example, to set the AppsFlyer Customer User id I'm doing this when the app starts:

private void initAppsFlyer() {
AppsFlyerConversionListener conversionDataListener = new AppsFlyerConversionListener() {
...
    };
    AppsFlyerLib.getInstance().registerConversionListener(this, conversionDataListener);
    String distintId = MixpanelManager.getMixpanelInstance().getDistinctId();
    if (distintId != null) {
        AppsFlyerLib.getInstance().setCustomerUserId(distintId);
    }
    AppsFlyerLib.getInstance().startTracking(this, Constants.APPSFLYER_KEY);
}


Then when the user sign in/up, we are using the 'identify' and 'alias' functions from Mixpanel:

public static void identifyUser() {
    MixpanelAPI mixpanel = getMixpanelInstance();
    if (mixpanel != null) {
        if (alreadyDoAliasOnMixpanel) {
        // Ensure all future events sent from the device will have the distinct_id
        mixpanel.identify(localUserId);
    
        // Ensure all future people properties sent from the device will have the distinct_id
        mixpanel.getPeople().identify(localUserId);
    } else {
        alreadyDoAliasOnMixpanel = true;
        // This makes the current ID (by default an auto-generated GUID)
        // and 'user id' interchangeable distinct ids (but not retroactively).
        mixpanel.alias(localUserId, mixpanel.getDistinctId());

        // To create a user profile, you must call getPeople().identify
        mixpanel.getPeople().identify(mixpanel.getDistinctId());
    }

    mixpanel.getPeople().set("Id", localUserId);
mixpanel.getPeople().set("$email", user.getEmail());
...
}

I'm doing something wrong?

As I said, before implementing the AppsFlyer integration the profiles on Mixpanel work ok.


Thanks in advance,


Userlevel 3
Badge

Hey @sehyris -

We use appsflyer too -- It looks like you might be running into a race condition.

It looks like you are calling identify

mixpanel.identify(localUserId); 

and creating a profile

mixpanel.getPeople().identify(localUserId);

before you are aliasing 'localUserId' to the Mixpanel 'distinct_id.'

Because of this, a profile would be created with a distinct_id = 'localUserId' — but then all future events and profile updates sent with the distinct_id = 'localUserId' would be aliased to the Mixpanel 'distinct_id'.

Can you check if this race condition is the reason you are seeing this behavior?



Badge

Thanks for the help.

We fixed this issue calling 'alias' only on the sign ups and 'identify' only on the logins.


Reply