OneSignal Help & Documentation

Welcome to the OneSignal New IA developer hub. You'll find comprehensive guides and documentation to help you start working with OneSignal New IA as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Discussions

Mixpanel

Integrating OneSignal with Mixpanel

Mixpanel and OneSignal have joined forces to provide:

Feature

Details

Personalized messaging

Boost engagement with more contextualized messaging from OneSignal, triggered when users enter or exit Mixpanel cohorts

Real-time insights

Gain a holistic view of customers by combining Mixpanel in-product user actions and OneSignal message engagement metrics

Data-driven campaigns

Leverage product-level user insights for re-engaging campaigns through OneSignal

🚧

Requirements

A Paid OneSignal Account is required for this integration.

Moving Current Mixpanel Subscriptions to OneSignal

After following the below steps, your user data will be synced with OneSignal as follows:

User Type

Details

Push Subscribers

Automatically and silently (not prompted again) moved into OneSignal upon updating the mobile app or returning to the website. New Users can subscribe through Prompting.

Email Subscribers

Emails can be Imported in a one-time step to immediately message your userbase and synced overtime using our API. Details in Email Quickstart.

SMS Subscribers

You can easily import your subscriber phone numbers and send text messages based on the user activity details from Mixpanel.

Make sure you have added the OneSignal Mobile SDK and/or Web SDK and have started collecting Subscribers.

Step 1. Turn on Integration

Navigate to your onesignal.com Dashboard > Settings > Analytics and Activate Mixpanel

Step 2. Add Mixpanel Token in OneSignal dashboard

You can find your Mixpanel Token under Project Settings > Access Keys. Copy-paste the Project Token into OneSignal. See Mixpanel's "Find Project Token" guide for further details.

Recommended: Select the checkbox to "Use external_user_id to sync events" if you want to send cross-channel messages (push, email, sms, in-app).

If you are using Mixpanel EU servers, select Send events exclusively to Mixpanel EU servers.

OneSignal messaging events will automatically show up in the activity feed of a user in Mixpanel.

Step 3. Add OneSignal to Mixpanel Integrations

Get your OneSignal App ID and REST API Key

In your mixpanel.com dashboard > Data Management > Integrations. Select "OneSignal" and press Connect.

With your OneSignal App ID & REST API Keys input them into the Mixpanel fields and press Continue.

Step 4. Send Mixpanel the OneSignal User ID

Syncing user data across OneSignal and Mixpanel requires setting the Mixpanel User Property called OneSignal User Id ($onesignal_user_id).

Method 1: External User Id (Recommended)

In OneSignal, if you selected Use external_user_id to sync events (recommended) in step 2, then the Mixpanel OneSignal User Id property needs to equal the OneSignal External User Id property.

OneSignal external_user_id is a user-level identifier and can be associate with multiple player_id records across different channels (Push, Email, and/or SMS). You can map your unique Database/DMP User ID to OneSignal's external_user_id.

Method 2: Player Id

If you did not select Use external_user_id to sync events (recommended), then use the OneSignal Player Id as the OneSignal User Id Mixpanel property. However, you will not get access to Email capabilities.

Example Code

Through the Mixpanel API, set this OneSignal User ID Property $onesignal_user_id to the people property.

// Method 1 (Recommended)
//Get the Mixpanel Distinct Id or any User Id of choice
let distinct_id = "";
mixpanel.init('YOUR PROJECT TOKEN', {
    loaded: function(mixpanel) {
        distinct_id = mixpanel.get_distinct_id();
    }
});
//Set the OneSignal External User ID to Mixpanel Distinct Id
OneSignal.push(function() {
  // Check if the current site visitor is subscribed (no player id is created until the user subscribes to push
  OneSignal.isPushNotificationsEnabled(function(isEnabled) {
    if (isEnabled) {
      console.log("Push notifications are enabled!");
      OneSignal.setExternalUserId(distinct_id);
      //Set Mixpanel OneSignal User Id property to Distinct Id or any User Id
      mixpanel.people.set({
        $onesignal_user_id: distinct_id
      });
    } else {
      console.log("Push notifications are not enabled yet.");   
    }
  });
});

//-----------------------------------------------------------

// Method 2 (Not Recommended)
//Set the OneSignal Push Player ID to Mixpanel record
OneSignal.push(function() {
  // Check if the current site visitor is subscribed (no player id is created until the user subscribes to push
  OneSignal.isPushNotificationsEnabled(function(isEnabled) {
    if (isEnabled) {
      console.log("Push notifications are enabled!");
      OneSignal.getUserId(function (userId) {
        console.log("OneSignal User ID:", userId);
        mixpanel.people.set({
          $onesignal_user_id: userId
        });
      });
    } else {
      console.log("Push notifications are not enabled yet.");   
    }
  });
});
// Method 1 (Recommended)
//Get the Mixpanel Distinct Id or any User Id of choice
MixpanelAPI mixpanel = MixpanelAPI.getInstance(context, "MIXPANEL_PROJECT_TOKEN");

String distinctId = mixpanel.getDistinctId();

// Setting External User Id with Callback Available in SDK Version 4.0.0+
OneSignal.setExternalUserId(distinctId, new OneSignal.OSExternalUserIdUpdateCompletionHandler() {
   @Override
   public void onSuccess(JSONObject results) {
      // The results will contain push and email success statuses
      OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "Set external user id done with results: " + results.toString());
     //Set Mixpanel OneSignal User Id property to Distinct Id or any User Id
     mixpanel.getPeople().set("$onesignal_user_id", distinctId);
   }
   @Override
   public void onFailure(OneSignal.ExternalIdError error) {
      // The results will contain push and email failure statuses
      // Use this to detect if external_user_id was not set and retry when a better network connection is made
      OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "Set external user id done with error: " + error.toString());
   }
});


//-----------------------------------------------------------

// Method 2 (Not Recommended)
//Set the OneSignal Push Player ID to Mixpanel record
OSDeviceState device = OneSignal.getDeviceState();
String userId = device.getUserId();//String: the OS Player Id or null if device has not registered with OS Servers
mixpanel.getPeople().set("$onesignal_user_id", userId);
// Method 1 (Recommended)
//Get the Mixpanel Distinct Id or any User Id of choice
Mixpanel.initialize(token: "MIXPANEL_PROJECT_TOKEN")
let mixpanel = Mixpanel.mainInstance()

let distinctId = mixpanel.distinctId

// Setting External User Id with Callback Available in SDK Version 3.x.x
OneSignal.setExternalUserId(distinctId, withSuccess: { results in
  // The results will contain push and email success statuses
  print("External user id update complete with results: ", results!.description)
  //Set Mixpanel OneSignal User Id property to Distinct Id or any User Id
  mixpanel.people.set(properties: ["$onesignal_user_id":userId])
})


//-----------------------------------------------------------

// Method 2 (Not Recommended)
//Set the OneSignal Push Player ID to Mixpanel record
let deviceState = OneSignal.getDeviceState()
if let userId = deviceState?.userId {
    mixpanel.people.set(properties: ["$onesignal_user_id":userId])
}
//Get the Mixpanel Distinct Id or any User Id of choice
const distinctId = await mixpanel.getDistinctId(); 

// Setting External User Id with Callback Available in SDK Version 3.7.0+
OneSignal.setExternalUserId(distinctId, (results) => {
  // The results will contain push and email success statuses
  console.log('Results of setting external user id');
  console.log(results);
  
  //Set Mixpanel OneSignal User Id property to Distinct Id or any User Id
  mixpanel.getPeople().set("$onesignal_user_id", distinctId);
  
  // Push can be expected in almost every situation with a success status, but
  // as a pre-caution its good to verify it exists
  if (results.push && results.push.success) {
    console.log('Results of setting external user id push status:');
    console.log(results.push.success);
  }
  
  // Verify the email is set or check that the results have an email success status
  if (results.email && results.email.success) {
    console.log('Results of setting external user id email status:');
    console.log(results.email.success);
  }
});

🚧

Highly Important

User profiles without this user property ($onesignal_user_id) will not export to OneSignal - it is a requirement for user matching.

🚧

Migrating from Player Id to External User Id

  1. In OneSignal, select Use external_user_id to sync events (recommended) in step 2, then the Mixpanel OneSignal User Id property needs to equal the OneSignal External User Id property.

  2. Send Mixpanel the External User Id set within OneSignal. See example code.

Step 5. Export Mixpanel Cohorts to OneSignal

As you start sending Mixpanel the $onesignal_user_id you will see a new User Property in Mixpanel called OneSignal User Id. You can use is set to filter all devices currently associated with the OneSignal Device Record.

In Mixpanel Users > Cohorts select the 3-dot option next to the cohort you want to send push.

Select Export to... > OneSignal

Under "Export Type" you have 2 options:

  1. "One-time export" will send OneSignal the current user data. Best if sending one message only to the current users.
  2. "Dynamic Sync" is where Mixpanel will send OneSignal the updated cohort data around every 15 minutes. Best if sending recurring messages to updated user list.

Select the option and press Begin Sync.

  1. The exported Mixpanel Cohorts will show in the onesignal.com dashboard Audience > Segments as a new segment and will become available as a segment filter for further customization.

Why am I not seeing all my cohort users inside the OneSignal segment?

There are generally 3 reasons why your Mixpanel Cohort Users will not all show up inside a OneSignal Segment:

  1. The OneSignal player_id or external_user_id must be synced. Make sure you add the $onesignal_user_id to the Mixpanel user record through our SDKs. See Step 4.
  2. The device must be subscribed. Device records with an active $onesignal_user_id in Mixpanel may not be subscribed to push notifications or emails. Any device not subscribed will not be inside the OneSignal Segment.
  3. Dynamic vs One-time export. Syncing occurs every 15 minutes for Dynamic exports. You may need to wait to see all the data sync over.

You can verify this in the Mixpanel Cohort filtering All Users where OneSignal User Id is set.

🚧

Cohort - Segment User Discrepancies

Users within Mixpanel Cohorts sent to OneSignal must satisfy 2 requirements:

  1. the $onesignal_user_id property must be set on the device. See step 4.
  2. the device must be subscribed to push. OneSignal Segments only contain subscribed users.

OneSignal will also automatically sync the $first_name and $last_name user info from Mixpanel user records to our Data Tags if they are present. This is helpful for Message Personalization.

Step 6. Tracking Message Data in Mixpanel

In Mixpanel User Activity Feed, OneSignal Message Events will appear in activity feed like:

  • Message Sent
  • App Opened from Push (clicked event)

Those have properties
time - the time the event happened
delivery_id - OneSignal notification ID
campaign_id - the heading from the notification or title from the IAM
$source - this is always onesignal
message_type - push/in-app/email/sms

Cohort Events

You can use the following events to create cohorts in Mixpanel:

OneSignal Event

Mixpanel Event

Mixpanel Message Event Property

Push Notification Clicked Which Opens the App/Website

App Opened from Push

Message = Push Notification Title/Headings

Message Contents = Push Notification Message/Contents

Push Notification Sent from OneSignal

Message Sent

Message = Push Notification Title/Headings

Message Contents = Push Notification Message/Contents

Push Notification Received on Device (Confirmed Deliveries)

Message Received

Message = Push Notification Title/Headings

Message Contents = Push Notification Message/Contents

In-App Message Clicked

Message Opened

Message Name set within OneSignal Dashboard - does not track what was clicked. Use the Click Action ID to send event to Mixpanel.

In-App Message Impression (shown to user)

Message Sent

Message Name set within OneSignal Dashboard

Email sent from OneSignal

Message Sent

Message = Subject of the email sent from OneSignal

Message Contents = first 255 bytes of the email body

Email opened/viewed from OneSignal

Message Opened

Message = Subject of the email sent from OneSignal

Message Contents = first 255 bytes of the email body

SMS sent from OneSignal

Message Sent

Message = Contents of the SMS sent from OneSignal

Message Contents = Contents of the SMS sent from OneSignal

Those have properties
time - the time the event happened
delivery_id - OneSignal notification ID
campaign_id - the heading from the notification or title from the IAM
$source - this is always onesignal.

Example Cohorts

Did not click a push or in-app message

With this type of Cohort you can track devices that may not have received your push or in-app message to send them an email or sms text.

Checking the users that did get a Message Sent greater than 1 time in the Last Day, where Message Type equals to push.
AND
Users that Did Not have the App Opened from Push (works on web as well) in the Last day.

Were Shown a Specific Message in the Past Day

Using Message Sent at least 1 time, in the Last 7 days where Message Type equals in-app and Message equals [name of the message]

In this cast the [name of the message] is pulled from:

  • Push Notification Title
  • In-App Message Name

FAQ

Do unsubscribed devices within my Mixpanel Cohort sync to OneSignal?

Devices not subscribed to push notification or emails will not show in the OneSignal segment's device count. However, sending In-App Messages will reach the unsubscribed devices.

Can I change the cohort name and have that reflected in OneSignal?

Changing the name of a synced Mixpanel Cohort will not show in OneSignal.

Upon syncing cohorts into OneSignal Segments, 2 things happen:

  1. a OneSignal Segment is created with that cohort name
  2. a Segment Data Filter is created for that cohort

The OneSignal Segment name can be changed, but the Segment Data Filter will always reflect the original name of the Mixpanel Cohort.

If you want to reflect this change, you will need to create a new Cohort in Mixpanel and sync it to OneSignal with the new name.

Updated a day ago



Mixpanel


Integrating OneSignal with Mixpanel

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.