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?
var _mtm = window._mtm = window._mtm || [];
dataLayer.push = function() {
_mtm.push.apply(_mtm, arguments);
return Array.prototype.push.apply(this, arguments);
};
If you then push something to the dataLayer dataLayer.push({'event': "test1"});
, it is also applied to the Matomo dataLayer _mtm.