Question

I have been trying to integrate Mixpanel into my Android app. The things works fine when it comes to tracking events and such, but the problem is that all the events are recorded under a single guest in the report. I called identify() on both the mixpanel.identify() and mixpanel.getPeople().identify() and my code looks something like this:

    MixpanelAPI mixpanel = MixpanelAPI.getInstance(this, MIXPANEL_TOKEN);
    MixpanelAPI.People people = mixpanel.getPeople();
    people.identify("666");
    people.set("first_name", "john");
    people.set("last_name", "smith");

    JSONObject props = new JSONObject();
    try {
        props.put("Gender", "Male");
        props.put("Plan", "Premium");
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }


    mixpanel.track("Plan selected", props);
    mixpanel.flush();       

No matter how many times that tracking event got sent (even if i change the value of the identify and track again), all the event are tracked under a random guest name : Guest #74352

Was it helpful?

Solution

If you want to associate events with the user's name in the activity feed, you'll want to use $first_name and $last_name (including the dollar sign) as properties. The Android library doesn't support name tagging in the streams report directly, but you can have a name there too by adding an mp_name_tag super property to your events. So you might want to have your code look something like this:

MixpanelAPI mixpanel = MixpanelAPI.getInstance(this, MIXPANEL_TOKEN);
MixpanelAPI.People people = mixpanel.getPeople();

// Using the same id for events and people updates will let you
// see events in the people analytics activity feed.
mixpanel.identify("666"); 
people.identify("666");

// Add the dollar sign to the name properties
people.set("$first_name", "john");
people.set("$last_name", "smith");

JSONObject nameTag = new JSONObject();
try {
    // Set an "mp_name_tag" super property 
    // for Streams if you find it useful.
    nameTag.put("mp_name_tag", "john smith");
    mixpanel.registerSuperProperties(nameTag);
} catch(JSONException e) {
    e.printStackTrace();
}

JSONObject props = new JSONObject();
try {
    props.put("Gender", "Male");
    props.put("Plan", "Premium");
} catch (JSONException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

mixpanel.track("Plan selected", props);
mixpanel.flush(); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top