I would like to use Matomo Tag Manager also for my User/Cookie Consent Service Cookiehub (similar to Cookiefirst). They have an integration guide for Google Tag Manager, which I followed [1] but It does not seem to work with MTM. I think the problem is that Cookiehub writes into window.datalayer and MTM does not pick that up. How can I approach this? I have a dev environment you can check out [2]
Overwriting the datalayer.push function sounds like a valid approach for my case. Do you have a quick snippet, how to do that. I tried this, but it does not seem to work:
<script type="text/javascript">
var _mtm = (window._mtm = window._mtm || []);
_mtm.push({ "mtm.startTime": new Date().getTime(), event: "mtm.Start" });
var d = document,
g = d.createElement("script"),
s = d.getElementsByTagName("script")[0];
g.type = "text/javascript";
g.async = true;
g.src =
"MYSOURCE.js";
s.parentNode.insertBefore(g, s);
var dataLayer = [];
dataLayer.push = _mtm.push
</script>
I’m not really a JS professional, but this could work. On the other hand, I don’t know, what sideeffects this could cause. Perhaps a JS ninja can help out?