Google Cloud Messaging (GCM) Migration to Firebase Cloud Messaging (FCM)

At this time, Mixpanel’s Android push services leverage Firebase Cloud Messaging (FCM), as Google deprecated GCM and fully adopted FCM.

If it hasn't been done already, update your Mixpanel library to v5.5 and above, and change your Push Notification Code to continue using Mixpanel Push Notifications.

New Mixpanel Implementations

If you are implementing Mixpanel for the first time and are planning to use Android Push Notifications, then the migration does not affect you. You will implement using FCM.

Follow the instructions in the Android integration document to set up push notifications.

Move from GCM to FCM

Your users’ existing push tokens will work with your updated FCM API key if moving from GCM to FCM. This being said, you should update your GCM API Key on mixpanel.com and use your FCM Server Key instead.

Access Google's migration guide here.

Update your Mixpanel Code

There are several updates that you need to make to an existing Mixpanel implementation in order to use FCM. Click here to view the release notes that outline the change.

How to remove GCM from an existing app

1. Open your AndroidManifest.xml file and remove the following permissions, as they are included in FCM by default:

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="YOUR_PACKAGE.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="YOUR_PACKAGE.permission.C2D_MESSAGE" />

2. Remove the following tag from your AndroidManifest.xml file:

<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="YOUR_PACKAGE" />
         </intent-filter>
</receiver>

3. Remove GCM from your gradle dependencies:

dependencies {
      compile 'com.google.android.gms:play-services-gcm:10.0.1'   // Remove this line
      ....
}

4. Remove any reference to People.initPushHandling(senderId):

MixpanelAPI.getInstance(this).getPeople().initPushHandling(SENDER_ID); // Remove this line

How to add FCM to your app

1. Add the following tag inside of your application tag in your AndroidManifest.xml file:

<application>
     ...
     <service
            android:name="com.mixpanel.android.mpmetrics.MixpanelFCMMessagingService"
            android:enabled="true"
            android:exported="false">
            <intent-filter>
                 <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
      </service>
     ...
</application>

2. Add FCM to your gradle dependencies. Ensure that you have Google Services added:

buildscript {
     ...
     dependencies {
           classpath 'com.google.gms:google-services:4.1.0'
           ...
     }
}

dependencies {
     implementation 'com.google.firebase:firebase-messaging:17.3.4'
     ...
}

apply plugin: 'com.google.gms.google-services

3. Place your google-services.json file into your Android project. You can obtain that file from your Firebase Console center.

4. The existing GCM Key is now called a "Legacy" token and it still can be used. That being said, Mixpanel suggests that you update your GCM API Key and use your FCM Server Key instead.

 
Is this article helpful?
8 out of 37 found this helpful

Comments

0 comments

Article is closed for comments.