未收到MixPanel推送通知

时间:2017-12-15 09:23:01

标签: android push-notification mixpanel segment-analytics

我已在MixPanel Push Notification Documentation上提及的MiXPanel控制台上设置了所有内容。我只是在谷歌和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

注册Receiver以获取推送通知。

的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发送推送,但没有使用设备。

如果我弄错了,请告诉我。

1 个答案:

答案 0 :(得分:2)

我已经解决了这个问题,现在我从MixPanel那里得到了推动:

我刚刚在方法中删除了不必要的方法调用(initMixPanelForPush)

已更新的方法

private void initMixPanelForPush() {
    try
    {
        MixpanelAPI mMixpanel = MixpanelAPI.getInstance(this, ConstantsLib.MIXPANEL_PROJECT_ID_TOKEN);
        mMixpanel.identify(AppSharedPrefs.getInstance(context).getUserId());

        mMixpanel.getPeople().identify(AppSharedPrefs.getInstance(context).getUserId());
        mMixpanel.getPeople().initPushHandling(ConstantsLib.PROJECT_NUMBER);
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
}

希望如果他们遇到同样的问题,它会帮助他人。

相关问题