I'm currently in the process making Google Tag Manager handle all our JavaScripts due to several benefits which I'm sure you all know to well.
Everything is going to plan apart from one problem which I'm sure can be fixed with a minor tweak that I'm hoping that one of you can help.
Comodo adds the seal with using 2 parts of code, one within in the <head>
and one within <body>
Like so:
<head>
<!-- THIS CODE is loaded by GTM -->
<script>
//<![CDATA[
var tlJsHost = ((window.location.protocol == "https:") ? "https://secure.comodo.com/" : "http://www.trustlogo.com/");
document.write(unescape("%3Cscript src='" + tlJsHost + "trustlogo/javascript/trustlogo.js' type='text/javascript'%3E%3C/script%3E"));
//]]>
</script>
</head>
<body>
<!-- This CODE is NOT loaded by GTM and loaded in the FOOTER -->
<footer>
<script type="text/javascript">TrustLogo("https://www.example.com/comodo_secure_seal_113x59_transp.png", "CL1", "none");</script>
</footer>
</body>
I am by no means a JavaScript expert but from what I can tell it loads the JavaScript from the head and then does something extra spicy to JavaScript in the body. Correct me if I am wrong but I think the problem has to do with the fact that Google Tag Manager does not add stuff to the <head>
as it loads things Asynchronously.
The SCRIPT within the body is NOT being loaded by Google Tag Manager while the SCRIPT within <head>
is, I've done it this way out of pure laziness as I am unsure how, or if you can inject JavaScript into a CSS selector or ID HTML element.
The firing triggers I have tested are DOM ready and Page View with document write enabled, hopefully someone can point me in the correct direction to resolving this issue, thanks in advance.
<script src="myjsfile.js" defer></script>
. With larger files such as jQuery it is not recommended to add defer to it. Just let it load async (which is the default, btw, so you never have to add "async" to the script tag). Edit; Async and defer cannot be applied to inline js. – Capacitor