Google Tag Manager with Comodo SSL Trusted Site Seal
Asked Answered
V

1

6

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.

Variorum answered 15/1, 2018 at 16:41 Comment(3)
I don't get the question. Async scripts means that it will load during the document loading phase. Not after. To load scripts after the document is loaded, you need to use "defer". Example: <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
The JavaScript SRC is handled by GTM so you never need to use Async but the inline JavaScript found within the body is handled by WordPress, the problem is that the body JavaScript is firing before the scripts in GTM.Variorum
You never need to use async anyway since it's the default value/setting.Capacitor
H
0

Im not javascript experit eigther but i work a lot with GTM and from time to time i insert javascript that is supposed to go in the header and it works just fine.

Maybe your problem is that since its Async the first js isnt fully loaded so the second one fails. If this is the case i recommend you this: https://www.simoahava.com/gtm-tips/add-load-listener-script-elements/

Hope it helps.

Hoarse answered 18/1, 2018 at 13:10 Comment(2)
Problem is that there is code in the body, in fact its embed in the middle of the page using JavaScript, so I need that to 'fire' last but obviously it does first because its on the page while the rest of the scripts are not.Variorum
You should look into a listener so the code on the page only fires after the one on GTM finishes.Hoarse

© 2022 - 2024 — McMap. All rights reserved.