本文介绍了jQuery和Google跟踪代码管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上实施Google跟踪代码管理器时遇到一些问题.我有一个Google代码,当我在自己的网站上尝试该代码时,会导致很多的JavaScript冲突.

I am having some problems implementing Google Tag Manager on my website. I have a Google code, and when I try it on my site, it makes a lot of javascript conflicts.

因此,我尝试将代码放在单独的文件中,以逐步进行操作,并观察不同脚本的行为.

So I tried to put the code on a seperate file, in order to do it Step by Step and observe the behavior of the different scripts.

这是我非常简单的HTML页面:

So here 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>

此页面在JS控制台中返回错误:

And this very page, returns an error in the JS console:

Uncaught ReferenceError: jQuery is not defined

好吧,这是意外的,jQuery在这里必须做什么?我什至没有在body标签上声明它,Google是否需要jQuery?

Well, this is unexpected, what does jQuery has to do here? I didn't even declare it on my body tag, is Google requiring jQuery?

这很奇怪,第二件事,当我在浏览器中加载后查看生成的HTML页面时:

So that was weird, and the second thing, when I look on my generated HTML page, after loading on a 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错误?

What kind of sorcery is this? Why does Google add a jquery thing at the bottom of my page, and why does my console shows me a jQuery error?

非常感谢您提供任何信息,我完全迷路了...祝你有美好的一天!

Thanks a lot for any kind of information, I am totally lost...And have a nice day!

推荐答案

我终于找到了解决方案,正如它在另一个问题中所说的那样,jQuery是由googletagmanager注入的,它是由配置google标记的Web Agency配置的经理.

I finally found the solution, as it says in an other question, jQuery was injected by the googletagmanager and it was configured by the Web Agency that configured the google tag manager.

因此,如果您遇到同样的问题,请致电您的网络代理商...

So if you have the same problem, call your Web Agency...

如果您已经为自己配置了代码管理器,请在Google跟踪代码管理器界面中签入设置.

And if you have configured yourself the tag manager, check in your settings on Google Tag Manager interface.

这篇关于jQuery和Google跟踪代码管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 20:38