-1

I want to inject a matomo tag manager script into the head section of a page by javascript code. However when I try the code in matomo preview mode, the code doesn't fire. What am I misssing?

var script = document.createElement('script');
script.type = 'text/javascript';
script.innerHTML = `
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.async=true; g.src='http://url.com/matomo/js/container_xyz.js'; s.parentNode.insertBefore(g,s);
`;
document.head.appendChild(script);
2
  • Why can't you just run the code that is inside ``? Commented Feb 19, 2022 at 9:41
  • I need to inject the tracking code in SharePoint online and don't have direct access to the html Commented Feb 19, 2022 at 12:47

1 Answer 1

0

The problem was on the matomo side. Code works

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.