tag-manager icon indicating copy to clipboard operation
tag-manager copied to clipboard

The feature to "Actively synchronise from the Google Tag Manager data layer" interferes with GTM to fire events

Open peterbo opened this issue 6 months ago • 6 comments

GTM triggers don't work anymore, if "Actively synchronise from the Google Tag Manager data layer" in Matomo is enabled.

peterbo avatar May 15 '25 13:05 peterbo

Hi @peterbo . Thank you for taking the time to create this issue. Could you please provide more details, maybe images or video to illustrate? Are you saying that triggers in your GTM instance are no longer functioning? Are you seeing any JS errors in your browser's console?

snake14 avatar May 15 '25 21:05 snake14

@peterbo We looked into it, but it isn't clear what the problem is? Could you please provide more information, images, videos, etc?

glitchhunter66 avatar May 20 '25 03:05 glitchhunter66

Hey everyone, i'm on Holiday until 28th of may and unable to provide a PoC before that. I'll post all needed information after my return.

peterbo avatar May 20 '25 06:05 peterbo

@peterbo Thank you so much, we really appreciate your input. Feedback like this helps us improve the product for everyone. (snake14, glitchhunter66 and I are all on the same team that is looking at this).

james-hill-matomo avatar May 26 '25 02:05 james-hill-matomo

Hello everyone, so here is a bit more information on the matter. The feature works by overwriting the "native" dataLayer.push method of the Google TagManager with kind of a proxy function in the Matomo TagManager. This results in every dataLayer.push(object) being present in _mtm and the dataLayer.

The problem is, that the logic that is triggered in the "native" dataLayer.push function is not triggered, resulting in no triggers are being executed in GTM, although the object is being pushed to the dataLayer successfully.

I'm not sure how to show this to you, but it's easy to reproduce with a setup using GTM and MTM at the same time and both should react on an event that was pushed to the dataLayer. Only MTM will react to this trigger, if the feature "Actively synchronise from the Google Tag Manager data layer" is enabled.

I tried this method in the past with the same result. The only way I found to synchronyze both datalayers without interfering with any logic is to look into the dataLayer all xx milliseconds and apply all detected changes to _mtm.

peterbo avatar Jun 05 '25 08:06 peterbo

Hi @peterbo . Thank you for elaborating on the issue so that we're sure what to look into. When Product team prioritises this issue, we can investigate alternative solutions for keeping both dataLayers synced without harming GTM event listeners. In the meantime, we'd be happy to review a PR if you find a solution.

snake14 avatar Jun 05 '25 21:06 snake14

Fix would be something like this, don't have the time to checkout and run the minifier properly at the moment. https://github.com/karlsve/tag-manager/compare/5.x-dev...patch-1

karlsve avatar Sep 12 '25 07:09 karlsve

Fix would be something like this, don't have the time to checkout and run the minifier properly at the moment. karlsve/[email protected]

@karlsve Thanks for the patch, we would still need to plan this and test it, if everything works as expected.

AltamashShaikh avatar Sep 16 '25 02:09 AltamashShaikh

Thank you again @karlsve . I have merged your commit into a new PR.

@peterbo Can you please temporarily apply the patch from PR #1039 and confirm whether it fixes the issue you've been experiencing?

snake14 avatar Sep 18 '25 23:09 snake14