When I deploy Matomo Tag Manager as a standard JavaScript Tag, AMP restricts custom JavaScript which leads to an AMP error.
How can I AMP-compliantly incorporate the Matomo Tag Manager for my site shuftipro.com?
I’ve already tried to set the default script to fit AMP guidelines for Matomo Tag Manager, but it doesn’t work (script was not loaded).
This was the default script:
<!-- Matomo Tag Manager -->
<script type="text/javascript">
var _mtm = _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.defer=true; g.src='https://mypage.com/js/container_abc.js'; s.parentNode.insertBefore(g,s);
</script>
<!-- End Matomo Tag Manager -->
They way I tried to adjust it was like this:
<!-- Matomo Tag Manager -->
<amp-script layout="container" src='https://mypage.com/js/container_abc.js'>
var _mtm = _mtm || [];
_mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
</amp-script>
<!-- End Matomo Tag Manager -->
I expected that the AMP error would be resolved and that the Matomo Tag Manager would be loaded.
The actual result showed that the script was not loaded (there was no network request).