Send Events to OneSignal (User Model)

Send events to OneSignal via the User Model API.

After you have successfully instrumented OneSignal as a destination in RudderStack, follow this guide to correctly send your events to OneSignal via their User Model REST API.

Find the open source transformer code for this integration in the GitHub repository.

Identify

You can make an identify call to add a new user to your OneSignal App. If a user is already present with the specified identifier, then RudderStack updates the user properties instead.

A sample identify call is shown below:

rudderanalytics.identify('1hKOmRA4GRlm', {
      firstName: 'Alex',
      lastName: 'Keener',
      email: "alex@example.com"
    }, {
      integrations: {
        one_signal: {
          aliases: {
            custom_alias: 'custom_identifier'
          },

        }
      }
    });

You can send subscription-level details to OneSignal by passing them in the properties.subscriptions object, as shown:

rudderanalytics.identify('1hKOmRA4GRlm', {
  firstName: 'Alex',
  lastName: 'Keener',
  email: "alex@example.com"
  subscriptions: {
    email: { // for email as device_type
      "enabled": true,
      "notification_types": 23,
      "session_time": 20,
      "session_count": 2,
      "app_version": "1.6.7",
      "test_type": 1
    },
    phone: { // for phone as device_type
      "enabled": true,
      "notification_types": 23,
      "session_time": 20,
      "session_count": 2,
      "app_version": "1.6.7",
      "test_type": 1
    },
    iOSPush: { // for device_type fetched from integrations object
      "enabled": true,
      "notification_types": 23,
      "session_time": 20,
      "session_count": 2,
      "app_version": "1.6.7",
      "test_type": 1
    }
  }
});

For email and SMS, enable the Toggle on to add a device using email and Toggle on to add a device using phone number settings in the RudderStack dashboard and send the relevant data (email or phone) in the event payload.

Property mapping

RudderStack maps the following optional properties to the corresponding OneSignal fields:

RudderStack propertyOneSignal property
context.os.versionsubscriptions.$.device_os
context. timezoneproperties.timezone_id
context.localeproperties.language
traits.address.countryproperties.country
traits.createdAt
context.traits.createdAt
timestamp
originalTimestamp
created_at
traits.createdAt
context.traits.createdAt
timestamp
originalTimestamp
properties.last_active
traits.first_active
context.traits.first_active
properties.first_active
userIdidentity.external_id

Note the following:

  • RudderStack maps all the string key-value pairs from traits inside the tags object as it is.

  • For mobile channels:

    • RudderStack maps context.device.type to subscription.$.type.
    • It also maps context.device.token or context.device.id to OneSignal’s subscriptions.$.token field.
  • For web channels:

    • RudderStack maps <browser_name>_Push (depending on the browser) to subscription.$.type.
    • Also, it maps the event’s anonymousId to OneSignal’s subscription.$.token. However, you can override this mapping by passing the deviceType field or in the integrations object. See the OneSignal documentation for more information on the supported device types.

Track

You can use the track call to update an existing user’s tags in your OneSignal app using the external user ID.

warning
You must associate the external user ID with a single user only.

While updating a tag, you can delete any key inside a tag by providing the key value as an empty string.

A sample track call is shown below:

rudderanalytics.track('Add to cart', {
  purchased_item: "Shirt",
  brand: "Zara"
}, {
  integrations: {
    one_signal: {
      aliases: {
        custom_alias: 'custom_alias_identifier'
      },
    }
  }
});

Property mapping

RudderStack maps the following properties to the corresponding OneSignal properties:

RudderStack propertyOneSignal property
userId
one_signal.aliases
Any one of the above is required
external_id
info
RudderStack maps all properties added in the Allowed Property List dashboard setting to the tags object if they are present in the payload. However, note that the key-value pair should be of the String data type only.

Group

You can use the group call to group the devices with the device tags having the same groupId.

A sample group call is as shown:

rudderanalytics.group('1hKOmRA4GRlm', {
  name: "Apple Inc.",
  location: "USA",
});
info

Note that:

  • groupId is a required field to send group events to OneSignal.
  • RudderStack maps all properties added in the Allowed Property List dashboard setting to the tags object if they are present in the payload. However, note that the key-value pair should be of the String data type only.

Questions? Contact us by email or on Slack