---
title: Integrate with Third-Party Analytics
slug: js-api/integrate-analytics
description: How Monetate JavaScript API clients can integrate Monetate with Google Analytics and other third-party analytics platforms
image:  https://archbee-image-uploads.s3.amazonaws.com/ceIfEvQHzQk1IVxoRWUh7/K9eTL4jKm7UQINb6zNziJ-20250912-181225.png
docTags: 
createdAt: 2024-06-27T17:15:02.059Z
---

:::hint{type="warning"}
Monetate doesn't report data for [Product Recommendations for Email](https://docs.monetate.com/docs/product-recommendations-for-email-experiences) experiences nor [Full-Page Test](https://docs.monetate.com/docs/create-a-full-page-test-experience) experiences to third-party platforms. Depending on your site structure, you may need to use [JavaScript polling](https://docs.monetate.com/docs/use-javascript-to-poll-for-necessary-resources) to ensure that Monetate correctly captures your site's data.
:::

In addition to experience analytics available in the Monetate platform, you can integrate your Monetate account with third-party platforms to report experience information. Examples of these platforms include Google Analytics, IBM Digital Analytics (formerly Coremetrics), and Adobe Analytics, including Adobe Marketing Cloud.

## How Integrations Work

:::hint{type="warning"}
Exporting data to a third-party platform may add server calls to your system.
:::

For traditional Monetate tag–based experiences, Monetate writes to a client's webpage the [campaigns](./#the-campaigns-variable) JavaScript variable. It contains the experience ID, name, and split information for every experience running on that page for the site visitor viewing it. By default, experience data is pushed when a site visitor sees an experience and after a 5-minute interval on the next track, be that a new page load or a [retrack](docId\:z7zs1BulqPT_0Z1CoYHww).

:::hint{type="info"}
If you want a custom interval for reporting label pushes, such as having labels pushed on every page load (every track) or every 30 minutes, then submit a support ticket using the Monetate Technical Support portal (support.monetate.com) and provide the name of the report for which you want to customize the interval.
:::

Monetate provides ready-made options if you need to integrate your account with [Contentsquare](https://docs.monetate.com/docs/integrate-with-contentsquare) or [Google Analytics](https://docs.monetate.com/docs/integrate-with-google-analytics). You can use your own JavaScript or use integration tools provided by other analytics platform vendors. If you’ve developed your own analytics-tracking tools, you can use them as well.

See [Enabling a Custom Report at the Experience Level](https://docs.monetate.com/docs/third-party-analytics-reports#enabling-a-custom-report-at-the-experience-level) in [Configure a Custom Third-Party Analytics Report](https://docs.monetate.com/docs/third-party-analytics-reports) in the Monetate Knowledge Base for more information about sending experience data to your third-party analytics platform(s).

## The campaigns Variable

The `campaigns` JavaScript variable is an array of objects that contains information about the experiences running on a page of your site. It sends the experience data to your third-party analytics platform(s). The number of indices in `campaigns` is equal to the number of experiences the site visitor sees on the page.

:::hint{type="info"}
Monetate writes the `campaigns` variable on a page of your site, but the variable doesn't provide other functionality by itself. Submit a support ticket using the Monetate Technical Support portal (support.monetate.com) if you have questions.
:::

Each object in the `campaigns` variable contains the following information:

- `id` — The unique experience ID, which doesn't change (for example, `217022`)
- `key` — The experience name shortened and appended with the experience ID (for example, `Winter-Sale_217022`); changes if you change the experience name
- `split` — The split name (for example, `Experiment` or `A-control`)

Here is an example of the data present in the `campaigns` variable for a visitor who was exposed to three different experiences on the page.

::Image[]{src="https://dyzz9obi78pm5.cloudfront.net/app/image/id/643044c7a5d7383152617f5b/n/settings-integration-third-party-analytics-custom-report-campaigns-variable.png" size="94" width="784" height="598" position="center" alt="Code sample of data from multiple experiences captured in the 'campaigns' variable" showCaption="false"}

The following code snippet places the array in a variable available on the front end:

:::CodeblockTabs
campaigns Variable Code Example

```javascript
window.monetate = window.monetate || {};
window.monetate.campaigns = campaigns;
```
:::

The following screenshot shows how to access the `campaigns` variable in your console.

::Image[]{src="https://dyzz9obi78pm5.cloudfront.net/app/image/id/643049d7652abc2c8e34c122/n/settings-integration-third-party-analytics-access-campaigns-variable-in-console.png" size="60" width="335" height="126" position="center" alt="A JavaScript console that shows the 'campaigns' variable" showCaption="false"}

## Session Count Discrepancies and Data Validation Checks

Session counts between Monetate and your third-party analytics platform will always have discrepancies due to various factors. Instead of focusing on [session](https://docs.monetate.com/docs/the-monetate-session) matching, Monetate strongly encourages you to conduct a purchase audit to match purchases between platforms because consistent collection and alignment of purchase data signifies a healthy Monetate implementation.

Session counts between Monetate and a third-party analytics platform may vary for various reasons:

- Differences in session definitions and handling between Monetate and the third-party analytics platform
- Variances in bot traffic–filtering mechanisms between Monetate and the third-party analytics platform
- Varied session timeout and activity limits set by different analytics systems
- Inclusion of nonessential analytics cookies that may be blocked by visitors

By conducting a purchase audit to align purchase data between Monetate and your third-party analytics platform, you can ensure data accuracy and obtain more meaningful insights for analysis.

### Requesting a Purchase Audit

To initiate a purchase audit, contact your Customer Success Manager, who can guide you through the process and provide you with the necessary details regarding the data you need to provide for the audit. You can also find more information in the [Data Alignment Check](docId\:QosI4Y5g5Z9mw5vTLu-PC) section of [Test an Implementation](docId\:QosI4Y5g5Z9mw5vTLu-PC).

## Testing the Integration

After you create the custom third-party analytics reporting integration following the [steps in Configure a Custom Third-Party Analytics Report](https://docs.monetate.com/docs/third-party-analytics-reports#create-custom-report-task), you can ensure it works by adding the JavaScript `console.log()` method and a message to the code in the editor on the report configuration page in the Monetate platform.

The following example is the [minimal Google Analytics 4 with Google Tag code](docId:8Qw_oJmFfjm1qqMMvH0PG) with the `console.log()` method added.

:::CodeblockTabs
GA4 with Google Tag with console.log() Example

```javascript
if (typeof(window.gtag) === "function") {
  for (var i = 0; i < campaigns.length; i++) {
    var campaign = campaigns[i];
    window.gtag('event', campaign.key, {
      'event_category': 'Monetate',
      'event_label': campaign.split,
      'non_interaction': true
    });
  }
  console.log("Google Analytics 4");
}
```
:::

After you add the `console.log()` method and message to the report code, click the preview icon.

![Callout of the preview icon for a for a Google Analytics 4 report configuration](https://dyzz9obi78pm5.cloudfront.net/app/image/id/6446c9a516accf17b778d415/n/settings-integration-third-party-analytics-ga4-custom-report-console-log-preview.png)

While viewing the new browser tab or window in which your site loaded in Preview Mode, open your browser's developer tools, switch to its console, and ensure the message that you used with the `console.log()` method in the report code is present.

![Callout of the 'Google Analytics 4' message resulting from the 'console.log()' method used in the GA4 report's code](https://dyzz9obi78pm5.cloudfront.net/app/image/id/6446d98f62c1a016c446b8b5/n/monetate-retail-site-preview-mode-developer-tool-console-google-analytics-4-message.png)

When you've confirmed that the integration works, you can enable it for all new Web experiences as well as add it to any active Web experiences. Refer to [Enabling a Custom Report at the Experience Level](https://docs.monetate.com/docs/third-party-analytics-reports#enabling-a-custom-report-at-the-experience-level) in the Monetate Knowledge Base for the steps.
