Probably since a wordpress update, I’ve got an error when calling my MTM container:
Uncaught SyntaxError: Identifier 's' has already been declared (at data:text/javascript;base64,.......................)
at data:text/javascript;base64,......................................
Browser console also gives me:
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 = !0;
g.src = 'https://MY-MATOMO-SERVER.org/js/container_WC3rwORo.js';
s.parentNode.insertBefore(g, s)
Does anyone have any ideas for solving this sudden problem ?
Hi @bmail
Maybe the s variable has been declared in one of the WP update files…
The advantage of the solution I provided (the use of an anonymous auto-called function), is that you are sure there will never be any variable collision.
You’re absolutely right !
I understood that we were making this function completely autonomous (including the variables used) thanks to the code you provided, but I haven’t managed to adapt it to use your method in my case …
My function ‘echoes’ the script in a tag and then integrates it into header.php, and I can’t see how to do this via an anonymous function.
That’s why I tagged my last post as “the solution”… Rather, it’s “my” solution, not having the skills to implement yours, which is indeed the best ! Anyway, I didn’t want to offend you (if that’s the case).
Thank you for your suggestion, which is the right one. I’ll just have to figure out how to put it into practice.