# Google Analytics integration

<Aside type="caution" icon="setting" title="Developer assistance needed">
 You'll need help from your development team to set up the integration. Please share this guide with them.
</Aside>

Google Analytics [User ID](https://support.google.com/analytics/answer/3123662?authuser=1) 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.

## Enable User ID

To enable User ID feature in your [Google Analytics account](https://analytics.google.com/analytics/web/provision/#/provision), follow the Google guide: [https://support.google.com/analytics/answer/3123666](https://support.google.com/analytics/answer/3123666)

<Aside type="note">
Don't forget to create a User ID reporting view (as described in _Step 3_ of GA guide on User ID enabling).
</Aside>

## Set up User ID in your tracking code

<Aside type="note">
 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.
</Aside>

## Integrate Pushwoosh Web SDK

To integrate Pushwoosh SDK in your Google Tag Manager, follow the [Web Push SDK guide](/developer/pushwoosh-sdk/web-push-notifications/web-push-sdk-30#installing-from-google-tag-manager).

## 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](https://policies.google.com/privacy).

```javascript title="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>
```

<img src="/integrations-google-analytics-integration-1.webp" alt="Custom HTML tag in Google Tag Manager for User ID setup"/>

## Add User ID to Page View tag

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

```javascript title="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>
```

<img src="/integrations-google-analytics-integration-2.webp" alt="Page View tag configuration with User ID"/>

## Test with User ID coverage report

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

<Aside type="note">
Please note it takes about a day for GA to process the data.
</Aside>

## User Explorer

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

<img src="/integrations-google-analytics-integration-3.webp" alt="New Segment button to divide audience into segments"/>

You can see your User IDs displayed in the "User ID" column. Use the **Export** button and select the CSV option to download the list of User IDs.

<img src="/integrations-google-analytics-integration-4.webp" alt="User ID column displaying user identifiers"/>

## Send push notifications to GA User IDs

To send a push to users from your GA audience, use [One-Time Push](/product/messaging-channels/push-notifications/send-push-notifications/one-time-push/) and at the **Audience** step choose **Import segment**. Upload the CSV file you exported from Google Analytics and map the column that contains User IDs to the User ID field. [Learn more](/product/audience-data-and-segmentation/segmentation/create-segments/by-import/#how-to-import-a-segment)