我已经在MixPanel 推送通知文档中提到的 MiXPanel 控制台上设置了所有东西。我只是在 google 和 MixPanel Docs 上找到 needfull 浪费了我 2 天的时间。
这是我的代码
private void initMixPanelForPush() {
try
{
MixpanelAPI mMixpanel = MixpanelAPI.getInstance(this, ConstantsLib.MIXPANEL_PROJECT_ID_TOKEN);
MixpanelAPI.People people = mMixpanel.getPeople();
people.initPushHandling(ConstantsLib.PROJECT_NUMBER);
people.identify(AppSharedPrefs.getInstance(context).getUserId());
people.setPushRegistrationId(AppSharedPrefs.getInstance(context).getDeviceToken());
people.showNotificationIfAvailable(this);
AppController.getInstance().getAnalyticInstance().getAnalyticsContext().putDeviceToken(AppSharedPrefs.getInstance(context).getDeviceToken());
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
我用过的变量:
MIXPANEL_PROJECT_ID_TOKEN:我是从 mixPanel ProjectSetting->Management->Token 获得的。
PROJECT_NUMBER:来自google-service.json文件的 project_number
注册接收器以获取推送通知。
AndroidManifest.xml
<receiver
android:name="com.mixpanel.android.mpmetrics.GCMReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="my_package _name" />
</intent-filter>
</receiver>
将身份发送到段。(此处添加设备令牌)
Traits traits = new Traits();
traits.putName(basicDetails.getFullName());
traits.putEmail(basicDetails.getContactEmail());
traits.putPhone(basicDetails.getContactNumber());
traits.putValue("userId", basicDetails.getUserId());
traits.putValue("android_devices", AppSharedPrefs.getInstance(context).getDeviceToken());
getAnalyticInstance().identify(AppSharedPrefs.getInstance(this).getUserId(), traits, null);
我通过选择用户从 MixPanel 发送推送,但没有进入设备。
如果我在某个地方弄错了,请告诉我。