Google Analytics Integration

Use Google Analytics data for audience segmentation

Google Analytics Integration requires CSV Push enabled in your account.

Google Analytics User ID feature lets you collect and apply comprehensive user data by connecting multiple data resources to the same users. Connect Pushwoosh with Google Analytics and use GA data for audience segmentation and targeting your push notifications campaigns. Let's see how it works.

1. Enable User ID

To enable User ID feature in your Google Analytics account, follow the Google guide: https://support.google.com/analytics/answer/3123666

Don't forget to create a User ID reporting view (as described in Step 3 of GA guide on User ID enabling).

2. Set up User ID in your tracking code

We are Google Tag Manager friendly

We encourage to use Google Tag Manager (GTM) to integrate Pushwoosh SDK. The following code is based on GTM, but it is easy to modify it to run as a simple Javascript on a page.

1. Integrate Pushwoosh Web SDK

To integrate Pushwoosh SDK in your Google Tag Manager, follow the Web Push SDK guide.

2. Create User ID tag in GTM

Create a Custom HTML Tag firing on All Pages trigger. Use the following code to set up User ID that matches the user data between Pushwoosh and Google Analytics.

In the example below, we use Pushwoosh Hardware ID (HWID) to set up User ID. You can use a different identifier, but be aware not to put email addresses or any other personally identifiable information (PII) into User ID as this is not compliant with Google Analytics Privacy Policy.

JavaScript
<script>
  var registrationStatus = localStorage.deviceRegistrationStatus;
  var registrationId = localStorage.deviceRegistrationId;
  var gaRegistered = registrationStatus === 'registered' ? registrationId : false;
  
  if (!gaRegistered) {
    var Pushwoosh = Pushwoosh || [];
    Pushwoosh.push(['onPermissionGranted', function(api) {    
      api.getParams()
        .then(function(params) {
          var hwid = params.hwid;
          ga('set', 'userId', hwid);
          ga('send', 'pageview');
          localStorage.setItem('deviceRegistrationId', hwid);
          api.registerUser(hwid);
        })
    }])
};
</script>

3. Add User ID to Page View tag

Modify your Page View tag to include User ID if it is known for the user:

JavaScript
<script>
  var hwid = localStorage.deviceRegistrationId;
  var registrationStatus = localStorage.deviceRegistrationStatus;
  var isNeedToTrackUser = hwid && registrationStatus === "registered";
  
  if (isNeedToTrackUser) {
    ga('set', 'userId', hwid);
  };
  ga('send', 'pageview');
</script>

3. Test with User ID coverage report

To test the integration, use "User ID coverage report": https://support.google.com/analytics/answer/3123670

Please note it takes about a day for GA to process the data.

4. User Explorer

Select your User ID reporting view in Google Analytics. Add any segments there to slice and dice your audience.

By clicking + New Segment button, you can divide your audience into segments.

You can see your User IDs displayed in "User ID" column.

Press the Export button and select the “CSV” option.

5. Send push notifications by GA User IDs

Navigate to CSV Push tab in your Pushwoosh Control Panel and upload the CSV file exported in the previous step.

Select the first column and choose “User ID” for the Data Type. Select a preset in the corresponding dropdown field, set the date (if necessary), and click Woosh!

You've just sent a push notification to your users from Google Analytics!

Last updated

#1685:

Change request updated