在哪里把谷歌分析代码 [英] where to put google analytics code

查看:97
本文介绍了在哪里把谷歌分析代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

谷歌分析在头?或结束?


谷歌分析代码必须放在头标签。
如果我的jsp文件中没有HEAD标记,我可以告诉我在哪里放置ga代码?

解决方案

这里的正确答案是将头标签添加到文件中。您应该使用有效的html标记来标记所有页面,并且包含头标记(即使为空) - 尽管头标记中的某些其他标记是必需的,具体取决于您提供的文档类型。Like..title标记和一些元标记...)是有效标记文件的一部分。更不用说,它会伤害你的搜索引擎优化努力没有它(与相关信息,如前述的标题和元标签..)。然而,如果您坚持在您的文档中没有头标,您可以将GA代码放在任何地方;根据一些人的说法,头部标签只是最佳的地方。

更高级的逻辑是给它一个跟踪的机会,即使一个人在完成加载之前试图离开页面(关闭浏览器,点击重定向按钮,也许在页面上的JS重定向,等等......)。但是,根据我的经验,我不认为这些是将跟踪代码放在页面上的正确理由。

实际上,我会争论追踪像这样的命中。我的主要问题/想法是......如果用户立即离开它,甚至在它被完全加载之前,你怎么能正确地说出一个用户浏览过该页面?但那只是IMO。

Possible Duplicate:
google analytics at head? or end of body?

The google analytics code has to be put before the HEAD tag. Can anyone tell where do i put the ga code if there is no HEAD tag present in my jsp file?

解决方案

The correct answer here would be to add head tags to your file. You should be using valid html markup for all your pages, and including head tags (even if empty - though certain other tags within head tag are required, depending on what type of document you are serving. Like..title tag and some meta tags...) is part of a validly marked up document. Not to mention that it hurts your SEO efforts not to have it (with relevant info, like aforementioned title and meta tags..).

However if you insist on not having a head tag in your document, you can place the GA code anywhere; in the head tag is just the optimal place - according to some people.

The logic behind putting it higher up is to give it a chance to track, even if a person tries to leave the page before it is done loading (closing the browser, clicking the redirect button, maybe js on the page redirects, etc...).. However, in my experience, I do not really think these are valid reasons for putting the tracking code high up on the page.

In fact, I would argue against tracking hits such as those. My main question/thought about that is...how can you rightfully say a user viewed the page if they immediately left it, even before it was fully loaded? But that's just IMO.

这篇关于在哪里把谷歌分析代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆