Hey gus,
I’m trying to send an event to Google Tag Manager, via node HTML, but it’s not being fired to my WEB container, what could be the problem?
Hey gus,
I’m trying to send an event to Google Tag Manager, via node HTML, but it’s not being fired to my WEB container, what could be the problem?
It looks like your topic is missing some important information. Could you provide the following if applicable.
I’m not able to add my workflow here, it’s giving a 403 error, so I’ve pasted the flow here for you to take a look at if possible
Hey @htnrodrigues Right now, your dataLayer.push()
is executing immediately. If GTM hasn’t finished loading, the event might not be registered.
Try adding this script before pushing events:
window.addEventListener("load", function() {
console.log("Google Tag Manager Loaded");
});
If you don’t see this message in the browser console, GTM is not loading correctly.
If this is the issue, you can delay the event push until the GTM is loaded. You could modify your section like this:
window.dataLayer = window.dataLayer || [];
window.addEventListener("load", function () {
window.dataLayer.push({
'event': 'initiate_form',
'toolName': 'Typebot',
'typebotEmail': "{{perguntaEmail}}",
'typebotPhone': "{{perguntaPhone}}",
'typebotFullName': "{{perguntaFullName}}",
'typebotInsta': "{{perguntaInsta}}",
'typebotArea': "{{perguntaArea}}",
'typebotAtuacao': "{{perguntaAtuacao}}",
'typebotFaturamento': "{{perguntaFaturamento}}"
});
console.log("✅ DataLayer push realizado:", window.dataLayer[window.dataLayer.length - 1]);
});
Hey @Exnav29,
Thanks for helping me, but it seems that it is not rendering and the event is not being fired for GTM, if I add the webhook and access it through the browser it works normally, I would like to fire it when I execute the workflow, I’m still thinking about how to do it, if you have any ideas can you share them with me?
Thanks for the update! Since the event fires when accessed via the browser but not when executing the workflow, the issue is likely due to how n8n runs the HTML node internally. Unlike a browser, n8n does not render or execute JavaScript inside the HTML node—so the dataLayer.push()
event is never triggered.
Try using an HTTP Request Node Instead of the HTML Node
Since GTM requires the page to load and execute JavaScript, an easier way to send an event is directly triggering a GTM event via the Measurement Protocol API.
Here’s how you can do it:
Replace the HTML node with an HTTP Request node.
Set it up to send a request to GTM’s Measurement Protocol:
Method: POST
URL:
https://www.google-analytics.com/mp/collect?measurement_id=G-XXXXXXX&api_secret=YOUR_API_SECRET
Headers:
{
"Content-Type": "application/json"
}
Body (JSON):
{
"client_id": "n8n-automation",
"events": [
{
"name": "initiate_form",
"params": {
"toolName": "Typebot",
"typebotEmail": "{{perguntaEmail}}",
"typebotPhone": "{{perguntaPhone}}",
"typebotFullName": "{{perguntaFullName}}",
"typebotInsta": "{{perguntaInsta}}",
"typebotArea": "{{perguntaArea}}",
"typebotAtuacao": "{{perguntaAtuacao}}",
"typebotFaturamento": "{{perguntaFaturamento}}"
}
}
]
}
This bypasses the need for a browser to execute JavaScript.
It directly sends an event to Google Analytics (which GTM can capture).
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.