Push Notifications
Enable push notifications for iOS or Android apps that use the Marketo Mobile SDK.
Setup Push Notification on iOS
There are three steps to enable push notifications:
- Configure push notifications in your Apple Developer account.
- Enable push notifications in xCode.
- Enable push notifications in the app with the Marketo SDK.
Configure Push Notifications on Apple Developer Account
- Log in to the Apple Developer Member Center.
- Select “Certificates, Identifiers & Profiles”.
- Select the “Certificates->All” folder under “iOS, tvOS, watchOS”.
- Select the “+” next to certificates in the upper-left corner.
- Select “Apple Push Notification service SSL (Sandbox & Production)”, and then select Continue.
- Select the application identifier used to build the app.
- Create and upload a CSR to generate the push certificate.
- Download the certificate and double-click it to install.
- Open “Keychain Access”, right-click the certificate, and export both items to the
.p12file.
- Upload this file through Marketo Admin Console to configure notifications.
- Update app provisioning profiles.
Enable Push Notifications in xCode
Turn on the push notification capability in the xCode project.
Enable Push Notifications in App with Marketo SDK
Add the following code to the AppDelegate.m file to deliver push notifications to customer devices.
Note - If you use the Adobe Launch extension, use ALMarketo as the class name.
Add the following import to AppDelegate.h.
| code language-objectivec |
|---|
|
| code language-swift |
|---|
|
Add UNUserNotificationCenterDelegate to AppDelegate as shown below.
| code language-objectivec |
|---|
|
| code language-swift |
|---|
|
Add the following code to initialize the push notification service.
| code language-objectivec |
|---|
|
| code language-swift |
|---|
|
Call this method to start registration with Apple Push Service. If registration succeeds, the app calls the App delegate object’s application:didRegisterForRemoteNotificationsWithDeviceToken: method and passes it a device token.
If registration fails, the app calls its App delegate’s application:didFailToRegisterForRemoteNotificationsWithError: method instead.
Register the push token with Marketo. The device token must be registered to receive push notifications from Marketo.
| code language-objectivec |
|---|
|
| code language-swift |
|---|
|
You can also unregister the token when the user logs out.
| code language-objectivec |
|---|
|
| code language-swift |
|---|
|
To re-register the push token, extract the code from step 3 into an AppDelegate method. Call that method from the ViewController login method.
Handle the push notification after registering the device token with Marketo.
| code language-objectivec |
|---|
|
| code language-swift |
|---|
|
Add the following method to AppDelegate.
Use this method to display an alert, play a sound, or increase the badge while the app is in the foreground. Call the appropriate completionHandler in this method.
| code language-objectivec |
|---|
|
| code language-swift |
|---|
|
Handle newly received push notifications in AppDelegate.
The delegate calls this method when the user responds to a notification by opening the application, dismissing the notification, or choosing a UNNotificationAction. Set the delegate before the application returns from applicationDidFinishLaunching:.
| code language-objectivec |
|---|
|
| code language-swift |
|---|
|
Track push notifications.
If the app is in the background or inactive, the device receives a push notification as shown below. Marketo tracks when the user selects the notification.
When the device receives a push notification, it passes the notification to the application:didReceiveRemoteNotification: callback on the App delegate.
The following Marketo activity log shows app events and push notification events.
Setup Push Notification on Android
-
Add the following permissions inside the application tag.
Open
AndroidManifest.xmland add the following permissions. Your app must request the “INTERNET” and “ACCESS_NETWORK_STATE” permissions. Skip this step if the app already requests them.code language-xml <uses‐permission android:name="android.permission.INTERNET"/> <uses‐permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <!‐‐Following permissions are required for push notification.‐‐> <uses-permission android:name="android.permission.GET_ACCOUNTS"/> <!‐‐Keeps the processor from sleeping when a message is received.‐‐> <uses-permission android:name="android.permission.WAKE_LOCK"/> <permission android:name="<PACKAGE_NAME>.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="<PACKAGE_NAME>.permission.C2D_MESSAGE" /> <!-- This app has permission to register and receive data message. --> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> -
Set up FCM with HTTPv1.
- Enable MME FCM HTTPv1 in Marketo feature manager.
- Upload the Service Account Json file for the app in MLM.
- Download the Service Account Json file from Firebase Console.
- Wait one hour after uploading the Service Account Json file in Marketo before sending push notifications.
- Enable MME FCM HTTPv1 in Marketo feature manager.
Android Test Devices
Add Marketo Activity to the manifest file inside the application tag.
<activity android:name="com.marketo.MarketoActivity" android:configChanges="orientation|screenSize">
<intent-filter android:label="MarketoActivity">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="add_test_device" android:scheme="mkto"/>
</intent-filter/>
</activity/>
Register Marketo Push Service
-
Add the Firebase messaging service to
AndroidManifest.xmlbefore the closing application tag.code language-xml <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <service android:name=".MyFirebaseMessagingService"> <intent-filter> <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/> <action android:name="com.google.firebase.MESSAGING_EVENT"/> </intent-filter> </service> -
Add the Marketo SDK methods to
MyFirebaseMessagingServiceas follows.code language-java import com.marketo.Marketo; public class MyFirebaseMessagingService extends FirebaseMessagingService { @Override public void onNewToken(String s) { super.onNewToken(s); Marketo marketoSdk = Marketo.getInstance(this.getApplicationContext()); marketoSdk.setPushNotificaitonToken(s); // Add your code here... } @Override public void onMessageReceived(RemoteMessage remoteMessage) { Marketo marketoSdk = Marketo.getInstance(this.getApplicationContext()); marketoSdk.showPushNotificaiton(remoteMessage); // Add your code here... } }Note - If you use the Adobe extension, add the following code.
code language-java import com.marketo.Marketo; public class MyFirebaseMessagingService extends FirebaseMessagingService { @Override public void onNewToken(String token) { super.onNewToken(token); ALMarketo.setPushNotificationToken(token); // Add your code here... } @Override public void onMessageReceived(RemoteMessage remoteMessage) { ALMarketo.showPushNotification(remoteMessage); // Add your code here... } }
NOTE: The FCM SDK automatically adds the required permissions and receiver functionality. If you used a previous SDK version, remove the following obsolete elements, which might cause message duplication.
<receiver android:name="com.marketo.MarketoBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<!‐‐Receives the actual messages.‐‐>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<!‐‐Register to enable push notification‐‐>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<!‐‐‐Replace YOUR_PACKAGE_NAME with your own package name‐‐>
<category android:name="YOUR_PACKAGE_NAME"/>
</intent-filter>
</receiver>
<!‐‐Marketo service to handle push registration and notification‐‐>
<service android:name="com.marketo.MarketoIntentService"/>
-
Initialize Marketo Push. After saving the configuration, create or open the Application class and add the following code. Get the sender ID from Firebase Console.
code language-java Marketo marketoSdk = Marketo.getInstance(getApplicationContext()); // Enable push notification here. The push notification channel name can by any string marketoSdk.initializeMarketoPush(SENDER_ID,"ChannelName");If you use the Adobe Launch extension, use the following code.
code language-java // Enable push notification here. The push notification channel name can by any string ALMarketo.initializeMarketoPush(SENDER_ID,"ChannelName");If you do not have a SENDER_ID, then enable Google Cloud Messaging Service by completing the steps detailed in this tutorial.
You can also unregister the token when the user logs out.
code language-java marketoSdk.uninitializeMarketoPush();If you use the Adobe Launch extension, use the following code.
code language-java ALMarketo.uninitializeMarketoPush();Note: To re-register the push token, extract the code from step 3 into an AppDelegate method. Call that method from the ViewController login method.
-
Optional: Set a notification icon. Call the following method to configure a custom notification icon.
code language-java MarketoConfig.Notification config = new MarketoConfig.Notification(); // Optional bitmap for honeycomb and above config.setNotificationLargeIcon(bitmap); // Required icon Resource ID config.setNotificationSmallIcon(R.drawable.notification_small_icon); // Set the configuration //Use the static methods on ALMarketo class when using Adobe Extension Marketo.getInstance(context).setNotificationConfig(config); // Get the configuration set Marketo.getInstance(context).getNotificationConfig();
Troubleshooting
If mobile push messages do not work as expected, check the common configuration issues before investigating the implementation details.
Push Message is Not Showing Up
Check whether push messages are disabled on the device. Mobile users can control whether they receive messages for each app, and developers or marketers might disable messages during development.
Check whether the app is open and active. When the app is active, mobile push messages do not appear on the screen. They appear in the app’s “local notifications” area instead.
View the Activity Logs in Marketo
Use the Marketo Activity logs to verify that a message was sent.
Review the activity records for a person who should have received the message. If the message was sent, the activity log contains a record. If no record exists, check the iOS certificate or Android API key configuration in Marketo.
Certificate or Key is Invalid
Verify that the correct certificate is loaded for Sandbox or Production. If necessary, re-export the iOS certificates or Android keys and reload them into Marketo.
.p12 file is Missing a Certificate or Key (iOS)
When you export the certificate, export both the key and the certificate.
Provisioning Profiles Out-of-Date (iOS)
After adding a device, update the provisioning profiles and generate new certificates. Point the Xcode project to the correct profiles and certificates, and import the certificates into Marketo.
Cannot Upload iOS Certificate (IOS)
Ensure that the password used to export the certificate does not contain spaces. For example, instead of this:
Hello World 123
use this:
HelloWorld123
Troubleshooting iOS Certificates
For sandbox applications, use a “developer” or “universal” certificate. For production applications, upload a valid “distribution” or “universal” certificate.
Push Bounce / Invalid Token
A registration token can become invalid in the following scenarios:
- If the client app un-registers with GCM.
- If the client app is automatically unregistered, which can happen if the user uninstalls the application. For example, on iOS, if the APNS Feedback Service reported the APNS token as invalid.
- If the registration token expires. For example, Google might decide to refresh registration tokens, or the APNS token has expired for iOS devices.
- If the client app is updated but the new version is not configured to receive messages.