Push Notifications

How to enable Push Notifications.

Setup Push Notification on iOS

There are two steps to enable push notifications:

  1. Configure push notifications on Apple Developer Account.
  2. Enable push notifications in xCode.
  3. Enable push notifications in app with Marketo SDK.

Configure Push Notifications on Apple Developer Account

  1. Log into the Apple Developer Member Center.
  2. Click on “Certificates, Identifiers & Profiles”.
  3. Click on “Certificates->All” folder underneath “iOS, tvOS, watchOS”.
  4. Select the “+” the button on the top right of the screen.
  5. Enable “Apple Push Notification service SSL (Sandbox & Production)” checkbox, and click “Continue”.add_cert
  6. Select the application identifier that you are using the build the app.select_app
  7. Create and upload CSR to generate the push certificate.
    upload_csr
  8. Download certificate to local computer and double-click to install.
  9. Open “Keychain Access”, right click on the certificate, and export 2 items into .p12 file.key_chain
  10. Upload this file through Marketo Admin Console to configure notifications.Screen Shot 2015-03-13 at 2.58.03 PM
  11. Update app provisioning profiles.

Enable Push Notifications in xCode

  1. Turn on push notification capability in xCode project.notification_capability

Enable Push Notifications in App with Marketo SDK

Add the following code to AppDelegate.m file to deliver push notifications to your customer’s devices.

1. Import following in AppDelegate.h.


2. Add UNUserNotificationCenterDelegate to AppDelegate as shown below.


3. Initiate Push notification Service

To enable push notification add below code.


Call this method to initiate the registration process with Apple Push Service. If registration succeeds, the app calls your 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.

4 Register Push Token with Marketo

To receive push notifications from Marketo you must register the device token with Marketo.


The token can also be unregistered when user logs out.


Note To re-register the push token extract the code from step 3 into an AppDelegate method and call form the ViewController login method.

5. Handle push notification

To receive push notifications from Marketo you must register the device token with Marketo.


6. Handle Local notification

This code helps Marketo SDK to handle push notification while app is in the foreground.


7. Add the following method in AppDelegate

By using this method you can either present alert, sound or increase badge while the app is in foreground with iOS 10. You must call completionHandler of your choice in this Method.


8. Handle newly received Push notification in AppDelegate iOS 10

The method will be called on the delegate when the user responded to the notification by opening the application, dismissing the notification or choosing a UNNotificationAction. The delegate must be set before the application returns from applicationDidFinishLaunching:.


9. Track push notifications

If your app is running in the background (or is not active), then the device will receive a push notification as shown below. Marketo will track when the user taps the notification.

mobile8

If the device receives a push notification it will be passed to application:didReceiveRemoteNotification: callback on your App delegate.

The following is a Marketo activity log from Marketo that shows app events, and push notification events.

.mobile9

Setup Push Notification on Android

1. Add following permission inside application tag.

Open AndroidManifest.xml and add following permissions. Your app must request the “INTERNET” and “ACCESS_NETWORK_STATE” permissions. If your app already requests these permissions, then skip this step.



Android Test Devices

1. Add Marketo Activity in manifest file inside application tag.

Register Marketo Push Service

1. To receive push notifications from Marketo, you need to add the Marketo Service and Broadcast Receiver to your AndroidManifest.xml. Add before the closing application tag.



2. Initialize Marketo Push
After saving the configuration above, you must initialize Marketo Push Notification. Create or open your Application class and copy/paste the code below. You can get your sender ID from the Google Developer Portal.


If you do not have a SENDER_ID, then enable Google Cloud Messaging Service by completing the steps detailed in this tutorial.

The token can also be unregistered when user logs out.


Note: To re-register the push token extract the code from step 3 into an AppDelegate method and call form the ViewController login method.

3. Set Notification Icon (Optional)
To configure a custom notification icon the following method should be called.


Troubleshooting

Setting up mobile push messages involves many steps and the coordination of developers and marketers. If you are experiencing difficulties, there are some simple things that you can check.

After you ensure that the simple things are correct, then you can dig deeper into the programming details.

Push Message is Not Showing Up

First, check to see if push messages are disabled on the handset. Mobile users can control whether or not they receive messages for any particular app. Often developers (and marketers) will disable these messages at some point during development. So the first thing to check is whether the recipient has disabled push messages for your app.

Second, is the app already open and active on the device? When your app is the active app on the device, mobile push messages do not pop up on the screen. Instead, they appear in the “local notifications” area of your app.

In-App Message is Not Showing Up

Marketo responds to triggers from apps only after the Marketo Mobile SDK is initialized with the Marketo Platform. The initialization process occurs when you install and open the app for the first time. Since initialization occurs after the first app open, the “App Open” event is not triggered until the app is opened a second time. Close the app and open it again, and a message triggered by App Open should appear on your device.

Custom events are triggered by user interaction after the app is open. Custom events will be recognized by Marketo during the first session.

View the Activity Logs in Marketo

The first place to look when tracking down an error is in the Marketo Activity logs. You can use activity logs to verify that a message was sent.

In the activity log, look at the activity records for a person that was supposed to receive a message. If the message was sent, there will be a record present in the activity log. If not, the problem is likely due to the configuration of the iOS certificate or Android API key within Marketo.

Certificate or Key is Invalid

Double check your configuration to make sure that you have the proper certificate loaded for Sandbox or Production. Sometimes it is best to have the developer re-export the certificates (iOS) or keys (Android) and then reload them into Marketo to ensure that they are correct.

.p12 file is Missing a Certificate or Key (iOS)

When you export the certificate, make sure that you export the key and the certificate.

Provisioning Profiles Out-of-Date (iOS)

Whenever you add a new device, you need to update your provisioning profiles and generate new certificates. Make sure that your Xcode project then points to the correct profiles and certificates, and import those certificates into Marketo.

Cannot Upload iOS Certificate (IOS)

Ensure that the password used while exporting the certificate does not contain an spaces.  For example, instead of this:

“Hello World 123”

use this:

“HelloWorld123”

Troubleshooting iOS Certificates

For sandbox applications, you can use either a “developer” or “universal” certificate. But for production applications you must upload a valid “distribution” or “universal” certificate.