Comment on page
Google Analytics Integration
Use Google Analytics data for audience segmentation
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.
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).
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>

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>

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.
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.
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 modified 4mo ago