jquery - jQuery-Google Analytics(分析)未添加页脚

标签 jquery html google-analytics

我正在尝试将Google Anlytics添加到我的所有html页面中。以下页面称为rates.html。

 <html>
  <head>
  <title></title>
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script> 
    $(function(){
    $("#footer").load("footer.html"); 
    });
  </script> 
 </head>
 <body>                                 
   <div id="footer"></div>
 </body>
</html>


在我的footer.html上,我有以下内容:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../css/stylesheet.css" />
<title>Footer</title>
</head>
<body>  
  <p align="center">Numbers: +244 (0) 00000000 | Lodge: +244 (0) 00000000 <br />
  <a href="mailto:lodge@sidney.co.za%20" class="Copy_link1">lodge@sidney.co.za  </a>| <a href="mailto:reservations@sidney.co.za" class="Copy_link1">reservations@samara.co.za</a></p>
  <p align="center">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatibus temporibus sequi saepe eius dolorem iusto deleniti, numquam nemo provident sunt accusantium esse cum similique harum reprehenderit illum, facilis laudantium soluta!.</p>
  <p align="center"><a href="http://www.sidney.com/" class="Copy_link1">SEO Powered by Ruby Digital</a></p>
  <script>
  (function(i,s,o,g,r,a,m)    {   i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new    Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)  [0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-12813356-1', 'auto', {'allowLinker': true});
  ga('require', 'linker');
  ga('send', 'pageview');
 </script>
</body>
</html>


我可以看到这些段落的内容。问题在于,我只是意识到rates.html和其他html页面并未真正提取分析数据,因为当我查看页面源代码时,没有显示分析数据。

如何在我的页面中显示Google Analytics(分析)

最佳答案

将分析结果放在自己的js文件中。您无法使用其中包含js的.load()在文件中进行渲染,仅渲染html,而不渲染文件中的js。

您的rates.html看起来像这样

<html>
    <head>
        <title></title>
        <script src="analytics.js"></script>
    </head>
    <body>                                 
        body content here
    </body>
</html>


然后将您的分析代码放在一个名为analytics.js的文件中

关于jquery - jQuery-Google Analytics(分析)未添加页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38636344/

相关文章:

javascript - 切换类时如何使div缓慢移动?

google-analytics - 使用 Google Analytics 自定义变量进行 A/B 测试

php - 显示投票结果代替投票区

HTML/CSS 将所有内容设置在同一行

javascript - jquery 我应该如何实时搜索多个 html 文件以获取结果

html - rails 的响应 Bootstrap 不起作用

javascript - 捕获传入的 URL 参数,然后使用 Javascript 传递给 iFrame Src

ios - 如何在Google Analytics界面查看userID?

javascript - JS/JQuery 关于按键的正确使用

JQuery 动态更改 CSS 在 IE7 中不起作用