Skip to Content
Support Hub
Integrations & ActionsHow to Push Information to Your Google Data Layer

Integrations & Actions

How to Push Information to Your Google Data Layer

This article explains how to pass information to your Google Data Layer using client-side tagging—whether from the Mavenoid assistant embedded on your website, within your app, or from a Mavenoid Help Center page.

How Client-Side Tagging Works

When using client-side tagging, your Google Tag Manager (GTM) container resides on your webpage or app. This means Mavenoid must communicate with the GTM container loaded on the page.

In Mavenoid, this is done using the External Script functionality. External Scripts allow you to call a JavaScript function (declared in the Mavenoid Embed Script) to interact with webpage resources at any point in the Mavenoid flow.

For more details on External Scripts, refer to Configuring Your First External Script.

Enabling Google Data Layer Push

To push data to your Google Data Layer, add the googleDataLayerPush external script to your Mavenoid Embed Script:

mavenoid.push({
  event: "assistant-mount",
  clientId: "YOUR_CLIENT_ID",
  externalScripts: {
    async googleDataLayerPush(input) {
      if (!window.dataLayer) {
        // Ensure the GTM script initializes the data layer if it hasn’t been created yet
      }

      window.dataLayer.push(input);

      return {
        formData: [{ id: "result", value: { type: "string", value: "ok" } }],
      };
    },
  },
});

Once this function is included in your Mavenoid Embed Script, you can call it by adding an External Script node in the Mavenoid canvas.

Example: Sending Event Data to Google Data Layer

When calling the External Script, you provide an input like this:

{
  "event": "mavenoid_referral",
  "url": {{ $created-on-page-url }},
  "eCommerce": {
      "items": [
          "item_name": {{ item-name }},
          "item_sku": {{ sku }},
          "price": {{ price }}
        ]
   }
}

Here’s what each variable represents:

  • $created-on-page-url → The URL where the assistant was loaded

  • item-name, sku, and priceForm data keys set in the conversation

For example, if the Mavenoid assistant was opened on "https://example.com/wireless-headphones", and the conversation contained the following values:

  • Product name: "Wireless Headphones"

  • SKU: "WH-12345"

  • Price: 99.99

Then, when the conversation reaches the "Google Data Layer Push" External Script node, the following event is pushed to the Google Data Layer:

window.dataLayer.push({
  event: "mavenoid_referral",
  url: "https://example.com/wireless-headphones",
  eCommerce: {
    items: [
      {
        item_name: "Wireless Headphones",
        item_sku: "WH-12345",
        price: 99.99,
      },
    ],
  },
});

Pushing Events from the Mavenoid Help Center

If you want to push events to your Google Data Layer from within the Mavenoid Help Center, contact your Mavenoid representative—we’ll help add the External Script to the Help Center site.

Need more help?

Ask a different questionIntegrations & Actions
Select a different product
© 2024 Mavenoid ABSitemap
Terms of servicePrivacy policyCookie policyData processing agreement