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

Google Analytics

OneSignal Features - Integrating OneSignal with Google Analytics

For Developers
For Marketers

Notification Behavior Tracking in Google Analytics

OneSignal supports tracking subscription and notification data when users subscribe and notifications are clicked on each platform, including sending this data to Google Analytics so that it can be analyzed in the context of your other user data.

Mobile

Tracking Mobile Notification Received and Clicked Events

Received: Send an event to your analytics system from the SDKs NotificationReceived event handler when a notification is received. Keep in mind, this event only gets called if the app is open and in the foreground or background. It will not get called if the app has been swiped away.

Clicked: Send another event to your analytics system from the NotificationOpened or Action event handler when a notification is clicked.

Tracking Mobile Subscription Events

Send a subscription event to your analytics system from the SDKs PermissionObserver event handler when a user subscribes.

iOS

Android

Track Subscription Event


Web Push

Tracking Web Push Notification Clicks

By UTM Parameters

The easiest way to track notification clicks is to add Google Analytics UTM parameters to the end of the URL for the notification. Here's an overview on UTM parameters: http://blog.rafflecopter.com/2014/04/utm-parameters-best-practices/

When sending a notification, please pick a UTM source (Such as "Notification"), a UTM medium (Such as "Web-Push"), and a UTM campaign parameter (Such as "Promotional-Offer-Template-123"). Next, add these parameters to your url, like so:

https://yoursite.com/your-page?utm_source=Notification&utm_medium=Web-Push&utm_campaign=Promotional-Offer-Template-123

After this, in Google analytics you can visit the Acquisition -> All Campaigns view to see all the campaigns you have sent and filter by day, browser, or campaign.

By Page JavaScript

You can use the addListenerForNotificationOpened event of the OneSignal Javascript SDK to detect when a user clicks a notification.

Add the Google Tracking code to the head tags of your site, then add this code to the body tags of the page you are directing users upon clicking the notification. This will track the notification ID and OneSignal player ID

<script>
OneSignal.push(["addListenerForNotificationOpened", function(data) {
    console.log("Received NotificationOpened:");
    console.log(data);
    console.log(data.id);
    console.log(data.heading);
    OneSignal.getUserId( function(userId) {
            console.log("OneSignal User ID:", userId);
            // Make a POST call to GA with the notification data and userId aka playerId
            ga('send', 'event', 'Notification_Clicked', data.id, userId);
        });
}]);
</script>

Tracking Subscriptions

You can use the notificationPermissionChange event of the OneSignal Javascript SDK to detect when a user subscribes to notifications or unsubscribes from notifications on your site.

Add the Google Tracking code to the head tags of your site, then add this code to the body tags of the pages users can subscribe. This will track the subscription change event and the OneSignal player ID.

OneSignal.push(function() {
    // Occurs when the user's subscription changes to a new value.
    OneSignal.on('notificationPermissionChange', function(permissionChange) {
      var currentPermission = permissionChange.to;
      console.log('New permission state:', currentPermission);
      ga('send', {
        hitType: 'event',
        eventCategory: 'notification_permission_change',
        eventAction: currentPermission
      });
   });
});

This will create several event actions in Google Analytics when users opt-in or opt-out.
You can then use filtering options in Google Analytics to track by day, week, month, landing pages and browsers.

Tracking Impressions of the opt in request pop-up

You can use the permissionPromptDisplay method to send an event to Google Analytics from your page's code, like so:

OneSignal.push(function() {
  OneSignal.on('permissionPromptDisplay', function(permissionChange) {
    ga('send', {
      hitType: 'event',
      eventCategory: 'notification_prompt',
      eventAction: 'displayed'
    });
  });
});

This will create an event in Google Analytics that you can track and filter by day, week, month, landing pages and browsers.

Tracking Notification Receipts & Dismissals

Advanced Topic

We recommend sending this data to Google Analytics as well (or another analytics tool). However since your website may not be open when notifications are received, dismissed, and opened by a user, this should be done by using our Webhook support.

For example, you can construct a webhook on top of the Google Analytics Measurement Protocol feature (https://developers.google.com/analytics/devguides/collection/protocol/v1/), then provide that URL with the query parameters of your choice when initializing OneSignal.

Filtering options like by day, week, month, browser, template will be available in Google analytics alongside the above event for your use.


Google Analytics


OneSignal Features - Integrating OneSignal with Google Analytics

For Developers
For Marketers

Suggested Edits are limited on API Reference Pages

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