I am trying to make Mixpanel people tracking to work but with no success. I see in the logs, that a create alias event
is sent but in the Mixpanel console no user profile is created.
Also this is code from the demo app in which I managed to replicate the issue, I can't share code from original app due to confidentiality reasons.
class MainActivity : AppCompatActivity() {
lateinit var mixpanel: MixpanelAPI
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mixpanel = MixpanelAPI.getInstance(this, "mytoken")
mixpanel.people.set("open date", Date())
mixpanel.identify(mixpanel.distinctId)
setContentView(R.layout.activity_main)
initCustomer()
postToMixpanel("TEST EVENT")
MPLog.setLevel(MPLog.VERBOSE)
}
fun initCustomer() {
mixpanel.alias("1", mixpanel.distinctId)
val map = listOfNotNull(
"\$name" to "Nikola",
"Gender" to "Male",
"Attraction" to "Girls",
"Account type" to "WTF",
"\$email" to "mail@mail.com"
).toMap()
mixpanel.people.setMap(map)
mixpanel.flush()
}
fun postToMixpanel(eventId: String, additionalProps: Map<String, Any>? = null) {
val props = JSONObject()
additionalProps?.let {
for ((key, value) in it) {
props.put(key, value)
}
}
mixpanel.track(eventId, props)
}
}
These are mixpanel logs from create alias event, I can not see any special property in there such as $name
and $email
.
[{ "event": "$create_alias", "properties": { "mp_lib": "android", "$lib_version": "5.4.1", "$os": "Android", "$os_version": "8.1.0", "$manufacturer": "UMIDIGI", "$brand": "UMIDIGI", "$model": "A1_PRO", "$google_play_services": "available", "$screen_dpi": 320, "$screen_height": 1344, "$screen_width": 720, "$app_version": "1.007-staging", "$app_version_string": "1.007-staging", "$app_release": 15, "$app_build_number": 15, "$has_nfc": false, "$has_telephone": true, "$carrier": "m:tel", "$wifi": true, "$bluetooth_enabled": false, "$bluetooth_version": "ble", "token": "", "Has Credit": "False", "Amount of Credits": "0", "time": 1530099794, "distinct_id": "b8769eeb-6a3b-4692-8973-261f9933537e", "alias": "260", "original": "b8769eeb-6a3b-4692-8973-261f9933537e" }, "$mp_metadata": { "$mp_event_id": "43f9c3402ffa6f4c", "$mp_session_id": "c35a49a17d3b9de6", "$mp_session_seq_id": 0, "$mp_session_start_sec": 1530099793 } }]
Try calling identify() method on the people object. It should create a user in Mixpanel.
mixpanel.people.identify(mixpanel.getDistinctId());
after
mixpanel.alias("1", mixpanel.distinctId)
in your fun initCustomer()
method.
Example:
fun initCustomer() {
mixpanel.alias("1", mixpanel.distinctId)
mixpanel.people.identify(mixpanel.getDistinctId());
val map = listOfNotNull(
"\$name" to "Nikola",
"Gender" to "Male",
"Attraction" to "Girls",
"Account type" to "WTF",
"\$email" to "mail@mail.com"
).toMap()
mixpanel.people.setMap(map)
mixpanel.flush()
}
More info in the android documentation in the section: Managing user identity