Sending Android in-app messages

Introduction

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

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

Integration

The Mixpanel Android library automatically checks for messages in the background, and will attempt to display them anytime an Activity is displayed. If you only wish to use mini in-app messages, then no extra integration is necessary.

If you wish to use takeover messages, then you must declare TakeoverInAppActivity in your AndroidManifest.xml file.

<activity android:name="com.mixpanel.android.takeoverinapp.TakeoverInAppActivity"
          android:theme="@style/com_mixpanel_android_TakeoverInAppActivityTheme"/>
            

For versions prior to 5.0.0 you should use com.mixpanel.android.surveys.SurveyActivity and @style/com_mixpanel_android_SurveyActivityTheme instead.

The specified theme is a general Mixpanel default, so feel free to substitute your own theme better match the look and feel of your application.

Controlling when to show an in-app message

You may not want the messages to show everytime a new Activity is displayed. For example, if you have a game and only want to show a message when a user accomplishes a goal, you need to turn off the automatic showing of messages by adding the following option in the <application> section of your AndroidManifest.xml file.

<meta-data android:name="com.mixpanel.android.MPConfig.AutoShowMixpanelUpdates"
           android:value="false" />
            

To manually check if an in-app message is available, you may call MixpanelAPI.getPeople().getNotificationIfAvailable(). This method will return an InAppNotification object if the Mixpanel library has received an in-app message for the currently identified user, and null otherwise. You may then use this object to render your own in-app message.

You can also call MixpanelAPI.getPeople().showNotificationIfAvailable() to allow the Mixpanel library to show an in-app message for you.

Note that MixpanelAPI.getPeople().showNotificationIfAvailable() will not display a message if there is already a message showing, so it is safe to call this function at any location where you want to potentially display a message.

Using profile properties

Just like emails, in-app messages will replace content wrapped in {{}}. For example, if you add a Location property to your user profiles, you can send messages 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!