I have a NextJS app that uses GTM to pass event to GA4.
I load GTM using the package react-gtm-module and initialize it as follows:
TagManager.initialize({
gtmId: process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER,
dataLayer: {
user_id: user_id,
}
})
I created a custom event 'view_faq' that has two variables (category and description). I trigger the event by invoke a function on a button click that pushes to the data layer. The custom event trigger fires on all events having the name 'view_faq'.
const handleClick = (index) => {
window.dataLayer.push({
event: 'view_faq',
category: 'faq',
description: 'This is a FAQ item',
})
}
When I do this, I see the event fire in Tag Assistant (debug mode) and I see the event appear along with the correct variables in GA4 Debug view.
The problem I'm having is that the event fires about 10 additional times in succession. So I see it 10 extra times in Tag Assistant and also GA4. None of my non-custom events are doing this (e.g., page views, button clicks).
Looking at each fired event and corresponding API call, it seems only what is passed to the data layer is changing with a parameter engagement_time_metrics...
The first API call is...
dataLayer.push({
event: "view_faq",
category: "faq",
description: "This is a FAQ item",
gtm.uniqueEventId: 11
})
The subsequent 10 API calls are as follows with the exception that only the field 'engagement_time_msec' changes on each one.
dataLayer.push({
event: "view_faq",
eventModel: {
category: "faq",
description: "This is a FAQ item",
user_id: "...",
engagement_time_msec: 3572, // <=== this is changing in each of the 10 calls...
client_id: "...",
session_id: "...",
session_number: 19,
session_engaged: 0,
page_location: "http://localhost/landing?gtm_debug=...",
page_referrer: "https://tagassistant.google.com/",
page_title: "My page",
language: "en-us",
screen_resolution: "2560x1440",
_user_agent_architecture: "arm",
_user_agent_bitness: "64",
_user_agent_full_version_list: "...",
_user_agent_mobile: "0",
_user_agent_model: "",
_user_agent_platform: "macOS",
_user_agent_platform_version: "12.6.0",
_user_agent_wow64: "0"
},
gtm.uniqueEventId: 11,
gtm.priorityId: 4
})
Anyone knows what is causing this?