简体   繁体   English

Google Analytics(分析)中的规范网址问题

[英]Issue with Canonical URL in Google Analytics

I just have issue with google analytics. 我只是对Google Analytics(分析)有疑问。 I've a website which is developed using php. 我有一个使用php开发的网站。 Now i wanted to make my website into non-canonical format. 现在,我想将我的网站设置为非规范格式。 I followed the below coding. 我按照下面的编码。 but still google analytics fails to recognise canonical URL. 但Google Analytics(分析)仍然无法识别规范网址。

Coding 编码

<html>
<head>
<link rel="canonical" href="<?php $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; echo $url;?>">
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'Tracking ID']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>
<body>
<?php
if(isset($_REQUEST['id']))
{
echo $url;
}
?>
</body>
<html>

when i tried to print the $url it prints url in canonical format. 当我尝试打印$ url时,它将以规范格式打印url。 but its not recognised by google analytics. 但Google Analytics(分析)无法识别。 can anyone tell me whats the problem with this coding?? 谁能告诉我这种编码的问题是什么?

You are not actually passing you canonical url to Google Analytics - for that you need a "virtual url", by passing the value you want as second parameter to the pageview call: 您实际上并没有将规范网址传递给Google Analytics(分析),因为您需要“虚拟网址”,方法是将所需的值作为第二个参数传递给综合浏览量:

[...]
  _gaq.push(['_trackPageview', <?php echo $url ?> ]);
[...]

According to https://support.google.com/webmasters/answer/139394?hl=en 根据https://support.google.com/webmasters/answer/139394?hl=zh-CN

Google currently supports these link header elements for Web Search only. Google当前仅支持Web搜索的这些链接标题元素。

So it sounds like your analytics are still going to tell you the full link whereas Googling your site will show what you desire. 因此,看来您的分析仍将告诉您完整的链接,而Google搜索您的网站将显示您的期望。

If this is a recent change then I would recommend checking Google search results in 1-2 weeks. 如果这是最近的更改,那么我建议您在1-2周内检查Google搜索结果。

If you are running Apache then mod_rewrite might be what you are looking for: 如果您正在运行Apache,那么mod_rewrite可能就是您想要的:

http://www.sitepoint.com/apache-mod_rewrite-examples/ http://www.sitepoint.com/apache-mod_rewrite-examples/

Specifically the mod-rewrite Regular Expressions section 特别是mod-rewrite Regular Expressions部分

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM