Integrate with Google Analytics When Using Google Tag Manager

This content is for the following audiences:

  • Clients that previously integrated a version of Google Analytics predating Google Analytics 4 (GA4) with Monetate before April 11, 2023, and that use Google Tag Manager (you're using the data layer JavaScript object for reports), and that now need to update that integration after creating a Google Analytics 4 property
  • Clients that have never integrated a Google Analytics setup with Monetate and that use Google Tag Manager.

If you configured a Google Analytics integration with Monetate before April 11, 2023, and use Google tag (gtag.js) or Universal Analytics (analytics.js) or legacy Google Analytics (ga.js), then follow the instructions in Set Up a Google Analytics 4 Integration Using Google Tag.

If you've never integrated your Google Analytics setup with Monetate and use Google tag, then follow the instructions in the Monetate Knowledge Base's Integrate with Google Analytics.

When you use Google Tag Manager (GTM) to integrate your site with Google Analytics, you configure how it collects analytics data using its interface. Unfortunately for GTM users, Google Analytics 4's gtag.js script for sending analytics data from webpages to Google's analytics platform isn't an option for integrating with the latest version of the Google Analytics platform.

Furthermore, because it cannot modify a client's GTM configuration interface and because it cannot account for the differences amongst all GTM setups its clients might have, Monetate cannot provide a ready-made option in its own platform so that its clients using GTM can configure a Monetate–GA4 integration with just a few clicks.

However, you can still configure a Monetate–GA4 integration using a multi-step approach:

  1. Create and test a custom GA4 report in the Monetate platform that uses a code to push experience data to GTM's data layer.
  2. Configure GTM to extract experience data from the campaigns variable that Monetate writes to the pages of your site for traditional Monetate tag–based experiences.
  3. Add the custom GA4 report to all active experiences in Monetate.

If you have an existing Google Analytics integration in the Monetate platform, be aware that on July 1, 2023, Google's standard Universal Analytics properties stopped processing data, analytics.js stopped working, and your existing Google Analytics integration with Monetate could only use the legacy version of Google Analytics until that date. Complete these GA4 configuration tasks to continue to send experience data to Google Analytics.

Prerequisites

You must have a GA4 property before you can create the custom report in Monetate. Refer to Google's Make the switch to Google Analytics 4 documentation to learn how to create the property.

While not mandatory to do so, you should consider configuring in GTM the Google Analytics: GA4 Configuration tag for your GA4 property before following the steps in Configuring Events and Triggers in Google Tag Manager. See Google's own documentation for setting up a Google Analytics 4 Configuration tag for the steps. If you opt not to configure this tag in GTM, then ensure you have your Google tag ID on hand. See Google's Find your Google tag ID for instructions.

If your account has a custom Google Analytics integration created by Monetate's Development Services team, then you must submit a request using the Monetate Technical Support portal (support.monetate.com) for the integration to be updated.

Creating the Custom Report

Follow these steps to create a custom Google Analytics report that uses data layer polling in the Monetate platform.

  1. Click the settings icon in the top navigation bar and then select Integration.

    Callout of the Integration option in the settings menu

  2. On the Third-Party Analytics tab, take one of the following actions:
    • If the account doesn't have any third-party analytics custom reports, then click SELECT for Custom Reporting.

      Callout of the SELECT button for the Custom Reporting option

    • If the account already has a third-party analytics report, then click ADD REPORT and then, if necessary, select Custom.

      Callout of the 'Custom' option in the ADD REPORT button menu

  3. Give the report a name. If you have an existing Google Analytics integration, ensure the name differentiates it from the existing Google Analytics report.

    Callout of the Title field for a new custom report

  4. Copy this code sample and paste it into the code editor.
    function pollForDatalayer() {
      if (typeof(dataLayer.push) === 'function') {
      // The dataLayer.push function is defined, so you can run it here
        for (var i = 0; i < campaigns.length; i++) {
          var campaign = campaigns[i];
          dataLayer.push({
            'event': 'MonetateExpLoad',
            'event_category': 'Monetate',
            'event_action': campaign.key,
            'event_label': campaign.split
            });
        }
        console.log("Data Layer Found.");
      } else {
         console.log("polling for Data Layer.");
        setTimeout(pollForDatalayer, 5000);  
      }
    }
    pollForDatalayer();

  5. Leave Enable by default for all new experiences set to NO.

    Callout of the 'Enable by default for all new experiences' toggle

  6. Click CREATE.

    Callout of the CREATE button

  7. Test the report.
    1. Open your site in a new browser tab or window, then open your browser's developer tools, and then switch to its console.
    2. Ensure the message in the first console.log() method in the report's code (Data Layer Found.) is present in the console.
  8. In the Monetate platform, set Enable by default for all new experiences to YES, and then click SAVE.

    Setting Enable by default for all new experiences to YES doesn't add the new GA4 report to active Web experiences. You must add the new report to each active experience from the Experience Editor page after you configure the necessary events and triggers in GTM.

    Callout of the 'Enable by default for all new experiences' toggle set to YES and of the SAVE button

If you previously configured a Google Analytics integration in the Monetate platform and have multiple legacy Google Analytics reports in one domain, ensure that you create and test a new GA4-compatible report for each of them.

Configuring Events and Triggers in Google Tag Manager

Follow these steps to create the events and triggers in GTM required to extract data from Monetate's campaigns variable.

  1. Launch GTM and then, if necessary, select the appropriate workspace.
  2. Create a new trigger based on a custom event.
    1. Click Triggers in the left-hand navigation.

      Callout of the Triggers option in the left-hand navigation of a Google Tag Manager workspace

    2. Click New.

      Callout of the New button on the Triggers page of Google Tag Manager

    3. Click Untitled Trigger and then name the trigger.

      Callout of the trigger name field that shows the placeholder 'Untitled Trigger' name

    4. Click the icon in the Trigger Configuration panel, and then select Custom Event from Choose trigger type.

      Animated demonstration of a user clicking the configuration icon in Google Tag Manager's Trigger Configuration panel, and then scrolling down to click the Custom Event option from the 'Choose trigger type' right-hand menu

    5. Give the event a name that matches the name you're sending in the custom report that you set up in Monetate.

      Callout of the 'Event name' field on the Triggers Configuration panel of Google Tag Manager

    6. Leave All Custom Events selected for This trigger fires on if you're unsure of the rules to use.

      Callout of the 'All Custom Events' option for the 'This trigger fires on' setting on the Triggers Configuration panel of Google Tag Manager

    7. Click Save.

      Callout of the Save button on the Triggers Configuration panel of Google Tag Manager

  3. Create the variable(s) that will pass to the data layer.
    1. Click Variables in the left-hand navigation.

      Callout of the Variables option in the left-hand navigation of a Google Tag Manager workspace

    2. Click New.

      Callout of the New button on the Variables panel of Google Tag Manager

    3. Click Untitled Variable and name the variable.

      Callout of the variable name field that shows the placeholder 'Untitled Variable' name

    4. Click the icon in the Variable Configuration panel, and then select Data Layer Variable from Choose variable type.

      Animated demonstration of a user clicking the configuration icon in Google Tag Manager's Variable Configuration panel, and then scrolling down to click the Data Layer Variable option from the 'Choose variable type' right-hand menu

    5. Give the variable a name that matches exactly the parameter you're sending in the custom report that you set up in Monetate.

      Callout of the 'Data Layer Variable Name' field on the Variable Configuration panel of Google Tag Manager

    6. Click Save.

      Callout of the Save button on the Variable Configuration panel of Google Tag Manager

    7. Repeat steps 3b through 3f as necessary so that you have a variable for each parameter you're sending in the custom report.
  4. Create a Google Analytics 4 event tag.
    1. Click Tags in the left-hand navigation.

      Callout of the Tags option in the left-hand navigation of a Google Tag Manager workspace

    2. Click New.

      Callout of the New button on the Tags panel of Google Tag Manager

    3. Click Untitled Tag and name the tag.

      Callout of the tag name field that shows the placeholder 'Untitled Tag' name on the Tags panel of Google Tag Manager

    4. Click the icon in the Tag Configuration panel, and then select Google Analytics: GA4 Event from Choose tag type.

      Animated demonstration of a user clicking the configuration icon in Google Tag Manager's Tag Configuration panel, and then clicking the 'Google Analytics: GA4 Event' option from the 'Choose tag type' right-hand menu

    5. Select from Configuration Tag either the Google Analytics: GA4 Configuration tag for your GA4 property that you previously created, or select None - Manually Set ID and then input your Google tag ID into Measurement ID.

      If you haven't configured the Google Analytics: GA4 Configuration tag for your GA4 property, then follow the steps in Google's Set up the Google Analytics 4 Configuration tag documentation.

      If you prefer to manually set the ID, see Find your Google tag ID for assistance finding this ID.

      Callout of the 'Configuration Tag' selector on the Tag Configuration panel of Google Tag Manager

    6. Give the event the same name as the event name that you input in step 2e when creating the trigger.

      Callout of the 'Event Name' field on the Tag Configuration panel of Google Tag Manager

    7. Expand the Event Parameters section, and then click Add Row.

      Animated demonstration of a user expanding the 'Event Parameters' section on the Tag Configuration panel of Google Tag Manager and then clicking the 'Add Row' button in that 'Event Parameters' section

    8. Click the brick icon for Parameter Name, and then select one of the data layer variables that you defined in step 3.

      Animated demonstration of a user clicking the brick icon to the right of the 'Parameter Name' field and then selecting a data layer variable from the 'Choose a variable' right-hand menu that appears

    9. Click the brick icon for Value, and then select the data layer variable that you selected in the previous step.

      Animated demonstration of a user clicking the brick icon to the right of the 'Value' field and then selecting the same data layer variable option from the 'Choose a variable' right-hand menu that appears as they selected for the parameter name

    10. As necessary, click Add Row and then repeat the two previous steps to add an event parameter for each variable to be pushed to the data layer.
    11. Click the icon in the Triggering panel, and then select the custom event that you created in step 3.

      Animated demonstration of a user clicking the icon in the Triggering section of the Tag panel and then selecting the custom event created for the Monetate integration

    12. Click Save.

      Callout of the Save button on the Tag panel of Google Tag Manager

  5. Publish the changes.
    1. Click Submit.

      Callout of the Submit button in the top-right corner of a Google Tag Manager workspace user interface

    2. Name the version, input a brief description of the changes you made to the workspace, and then click Publish.

      Callout of the 'Version Name' field, the 'Version Description' field, and the Publish button

Typically within 5 minutes the changes that you published are live on your site.

Enabling the New Report in Active Experiences

Follow these steps to add the new GA4 report to an individual Web experience.

If you have never configured a Google Analytics integration in the Monetate platform, skip to step 5.

  1. Click the settings icon in the top navigation bar and then select Integration.

    Callout of the Integration option in the settings menu

  2. Click GOOGLE ANALYTICS in the list of third-party analytics reports.

    Callout of the GOOGLE ANALYTICS option in the list of reports on the 'Third-Party Analytics' tab of the Integration page

  3. Scroll down to the View Associated Experiences table.

    Callout of the 'View Associated Experiences' section of the Google Analytics third-party integration configuration

  4. Click the name of an experience in the table to open it in Experience Editor.
  5. Click the additional options menu (...) on the Experience Editor page, and then click Third-Party Analytics.

    Callout of the 'Third-Party Analytics' option in the additional options menu on the Experience Editor page

  6. Find the new report on the Third-Party Analytics modal, and then toggle its setting to YES.

    Callout of the Google Analytics toggle on the Third-Party Analytics modal

  7. If you have a legacy Google Analytics report and you don't plan to archive that report and if it's currently enabled for this experience, then toggle its setting to NO.

    If you plan to archive the legacy Google Analytics report, skip this step. Archiving the report on the Third-Party Analytics tab of the Integration page automatically removes it from all experiences.

    Callout of the legacy Google Analytics toggle on the Third-Party Analytics modal

  8. If you want to see a specific string for this specific experience in all the third-party analytics platforms enabled for it, enter that string into Report Label.

    The text in Report Label auto-populates with the name of the experience. Monetate reports this string to the integrated third-party platform(s). Monetate also automatically creates labels for holdout variants based on your specified variant labels. For each variant included in the holdout, Monetate appends the label with - Holdout.

    Callout of the Report Label field on the Third-Party Analytics modal

  9. Click SAVE to close the modal.

    Callout of the SAVE button on the Third-Party Analytics modal

If you have a legacy Google Analytics report, repeat these steps for each active Web experience in the View Associated Experiences table that you want reported to your GA4 setup. After you've added the new report to all active Web experiences that you want reported to your GA4 setup, you can then archive the legacy Google Analytics report.

If you don't have a legacy Google Analytics report, repeat the process starting at step 5 until you've added the new report to all active Web experiences that you want reported to your GA4 setup.

You can view a table of experiences that Monetate is reporting to a GA4 setup on its respective custom report configuration screen of the Third-Party Analytics tab of the Integration page of the Monetate platform settings.

Callout of the 'View Associated Experiences' section of the Google Analytics third-party integration configuration

To disable Google Analytics reporting for a single experience, click its name in this table to open it in Experience Editor, then click the additional options menu (...), click Third-Party Analytics, and then toggle Google Analytics to NO in the Third-Party Analytics modal.

Archiving a Legacy Google Analytics Report

After you've enabled the new GA4-compatible report for each active Web experience, you can optionally archive the legacy Google Analytics report(s).

If you choose to archive a report, you cannot reactivate it.

While archiving a legacy Google Analytics report is optional, Monetate recommends doing so not only to prevent your users from potentially confusing the legacy report with the GA4 report if they adjust the enabled third-party analytics for an experience but also to prevent analytics from potentially being skewed by having two different Google Analytics reports enabled for the same experience.

Follow these steps to archive a legacy Google Analytics report.

  1. Click the legacy Google Analytics report in the list of third-party analytics reports.

    Callout of the GOOGLE ANALYTICS option in the list of reports on the 'Third-Party Analytics' tab of the Integration page

  2. Click the archive icon.

    Callout of the archive icon for the Google Analytics report on the 'Third-Party Analytics' tab of the Integration page

  3. Click OK to confirm that you want to archive the report.

    Callout of the OK button on a modal that states, 'This report is currently in use. Are you sure you want to archive it?'

After you click OK, Monetate disables and removes the legacy Google Analytics report from the Third-Party Analytics modal for all existing experiences.