简体   繁体   English

包含页眉和页脚时,我应该将Google Analytics(分析)摘要放在哪里?

[英]Where do I put the Google Analytics snippet when I'm including a header and footer?

So Google tells me to do this: 因此Google告诉我要这样做:

Paste your snippet (unaltered, in it's entirety) into every web page you want to track. 将您的代码段(完整不变)粘贴到您要跟踪的每个网页中。 Paste it immediately before the closing </head> tag. 将其粘贴在结束</head>标记之前。

I understand this part, but as I'm including my header and footer, I guess this is not what I'm supposed to do. 我理解这部分,但是当我包括页眉和页脚时,我想这不是我应该做的。

If you use templates to dynamically generate pages for your site (like if you use PHP, ASP, or a similar technology), you can paste the tracking code snippet into its own file, then include it in your page header. 如果您使用模板为网站动态生成页面(例如,如果您使用PHP,ASP或类似技术),则可以将跟踪代码段粘贴到其自己的文件中,然后将其包含在页面标题中。

So I guess this is what I'm talking about(?), but I don't really get exactly where they want me to put the snippet. 所以我想这就是我在说的(?),但我并没有真正了解他们希望我将代码片段放入哪个位置。 Do I put it in my header.php file once right before the closing </head> tag and then include the header.php file into every page or do I have to put the snippet directly in on every page? 我是否应该在</head>标记之前将其放置在header.php文件中一次,然后将header.php文件包含在每个页面中?还是必须将代码段直接放置在每个页面中? Incase I have to put the snippet in on every page, where exactly do I put it? 如果我必须在每个页面上都插入该代码段,那么我应该将其准确放置在哪里? Could someone please give me an example of this? 有人可以给我一个例子吗?

You can paste the Google Analytics Javascript snippet into its own file, call it ga.js for example. 您可以将Google Analytics(分析)Javascript代码段粘贴到其自己的文件中,例如,将其命名为ga.js。

Then in your header.php file, right before you close the tag, include that Javascript file, like so: 然后在关闭标记之前,在header.php文件中,包括该Javascript文件,如下所示:

<script type="text/javascript" src="ga.js"></script>

This will load the GA code in your head section every time you load the header.php file. 每次加载header.php文件时,这都会在您的头部加载GA代码。 This should happen to every page that you load header.php automatically. 这应该发生在自动加载header.php的每个页面上。

If you already have split your header, that I guess is included into you other html or php files, in it's own file and it includes the </head> tag, then you can put a script right above it. 如果您已经分割了标题,我想它应该包含在其他html或php文件中,在它自己的文件中并且包含</head>标记,那么您可以在其上方放置一个脚本。 This would look something like this: 看起来像这样:

[...]
<script>
    <!-- Your personal google analytics snippet -->
</script>
</head>

Then all sites, that include your header.php, also load the snippet from analytics and get tracked. 然后,包括您的header.php在内的所有站点也会从分析中加载代码段并进行跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该在哪里放置Google Analytics(分析)异步代码段 - Where should I put the Google Analytics asynchronous snippet Google Analytics - 我可以将脚本放在页脚中吗? - Google Analytics - Can I put script in footer? 页眉或页脚中的Google分析? - Google analytics in header or footer? 为了使它们都能正常运行,我必须在哪里放置Google Analytics(分析)代码和Event Tracking(事件跟踪)代码? - Where do I have to put Google Analytics code and Event Tracking code, in order for them both to work correctly? 我该在哪里使用CakePHP将Bootstrap片段中的JavaScript代码放到哪里? - Where do I put JavaScript code from this Bootstrap snippet using CakePHP? 我应将Google Analytics(分析)代码放在.ASPX页面的何处? - Where Do I Place Google Analytics Code Inside .ASPX Page? 我应在哪里添加此Google Analytics(分析)自定义变量代码? - Where do I add this Google Analytics custom variable code? 我可以将Google Analytics(分析)摘要重定向到我的服务器吗? - Can i redirect the google analytics snippet to my Server? 我可以将Google分析放在外部JS吗? - Can I put Google analytics in external JS? 如何在我的Google地图中将这行JS放在哪里? - Where do I put this line of JS for my Google map?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM