JQuery and google tag manager

I'm having trouble implementing Google Tag Manager on my website. I have google code, and when I try to use it on my site, it makes javascript conflicts a lot .

Therefore, I tried to put the code in a separate file in order to do this step by step and observe the behavior of different scripts.

So here is my very simple HTML page:

<!DOCTYPE html>
<html>
<head>
    <title>Titre</title>
</head>
<body>
    <!-- Google Tag Manager -->
    <noscript>
    <iframe src="http://www.googletagmanager.com/ns.html?id=GTM-XXXXXX" height="0" width="0" style="display:none;visibility:hidden"></iframe>
    </noscript>
    <script type="text/javascript">
        dataLayer = [{'uid':'12'}];
        (function(w,d,s,l,i){
            w[l]=w[l]||[];
            w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});
            var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';
            j.async=true;
            j.src='//www.googletagmanager.com/gtm.js?id='+i+dl;
            f.parentNode.insertBefore(j,f);
        })(window,document,'script','dataLayer','GTM-XXXXXX');
    </script>
    <!-- End Google Tag Manager -->
    hello
</body>
</html>

And this same page returns an error in the JS console:

Uncaught ReferenceError: jQuery is not defined

Well, this is unexpected, what does jQuery do here? I didn’t even post it on my body tag, does Google require jQuery?

So that was weird, and secondly, when I look at my generated HTML page after loading it in the browser:

<body>
... Long stuff here
<script type="text/javascript" id="" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
... some other stuff here
</body>

? Google jQuery jQuery?

, ... !

+4
3

, , : jQuery googletagmanager, -, google.

, , -...

, Google.

+2

Google :

jQuery

, , GTM jQuery .

, GTM, , jQuery .

jQuery , HTML.

+3

, GTM jQuery. , jQuery script, GTM, "Uncaught ReferenceError: jQuery ", .

, , jQuery GTM script. :

  • , , setInterval, jQuery:
var func = function() {
    if (jQuery) {  
        clearInterval(timer);
        // do your stuff
    }
}
var timer = setInterval(func, 1000);
+1

Source: https://habr.com/ru/post/1616204/


All Articles