Sending iOS in-app notifications

Introduction

Mixpanel allows you to create and send richer notifications that appear while your iOS app is running. If you are using our in-app notifications product, there are 3 things you need to make sure of.

  1. Include the latest version of the Mixpanel iOS library in your app
  2. Make sure you are identifying your users in the app.
  3. Create an in-app notification on the Notifications tab of the Mixpanel website.

Integration

The Mixpanel iOS library will automatically check for a notification when your app loads or resumes from the background. If a notification is available for the current user that they haven't already seen, it will be displayed immediately in an overlay view.

That's it, you're done!

Controlling when to show an in-app notification

You may not want the notifications to show immediately when your app loads. If, for example, you have a game and would like to show a notification when a user accomplishes a goal, you need to turn off the automatic showing of notifications by setting showNotificationOnActive to NO and call showNotificationWithID: at the appropriate point in your app.

// In application:didFinishLaunchingWithOptions:
Mixpanel *mixpanel = [Mixpanel sharedInstanceWithToken:
    YOUR_MIXPANEL_TOKEN];
// Turn this off so the notification doesn't pop up automatically.
mixpanel.showNotificationOnActive = NO;

- (void)playerFinishedLevel
{
    [mixpanel showNotificationWithID:INAPP_NOTIFICATION_ID];
}

If you don't want to specify the notification ID, you can use showNotification instead, which will show the first available in-app notification targeted at the identified user if there is one. Notifications are never shown twice to the same user, so you don't have to check for yourself if the user already saw the notification before calling showNotificationWithID.

If you don't want mixpanel checking for new in-app notifications when your app becomes active, you can turn it off by setting checkForNotificationsOnActive to NO. This means that in-app notifications will not show automatically, and that the network request to retrieve the notifications will occur only when you call showNotification or showNotificationWithID:

Adjusting the timing of mini notifications

By default, a mini in-app notification will display for 6 seconds before automatically dismissing itself. This number can be easily adjusted with the miniNotificationPresentationTime property.

// In application:didFinishLaunchingWithOptions:
Mixpanel *mixpanel = [Mixpanel sharedInstanceWithToken:
    YOUR_MIXPANEL_TOKEN];

// Give users more time to see the notification.
mixpanel.miniNotificationPresentationTime = 10.0;

Takeover (fullscreen) notifications will only dismiss themselves in response to a user action and have no "duration".

Using profile properties

Just like emails, in-app notifications will replace content wrapped in {{}}. For example, if you add a Location property to your user profiles, you can send notifications like this:

Come and visit us at our {{ ${Location} }} office!

A user with a profile property Location: Asheville will get the following message:

Come and visit us at our Asheville office!
If some of your profiles have a value, but others don't, you can use a fallback value:

Come and visit us at our {{ ${Location} | fallback:"nearest" }} office!

Profiles without a Location property will receive this message:

Come and visit us at our nearest office!