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.
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.
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.
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 price
→ Form 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,
},
],
},
});
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.