Google Analytics中的Canonical URL问题

时间:2014-01-23 13:44:51

标签: php google-analytics seo

我刚刚遇到谷歌分析问题。我有一个使用php开发的网站。现在我想让我的网站变成非规范格式。我按照下面的编码。但谷歌分析仍无法识别规范网址。

编码

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

当我尝试打印$ url时,它会以规范格式打印url。但它不被谷歌分析认可。任何人都可以告诉我这个编码的问题是什么?

2 个答案:

答案 0 :(得分:0)

您实际上并没有将规范网址传递给Google Analytics - 因为您需要一个“虚拟网址”,方法是将您想要的值作为第二个参数传递给网页浏览电话:

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

答案 1 :(得分:0)

根据https://support.google.com/webmasters/answer/139394?hl=en

  

Google目前支持这些用于网页搜索的链接标题元素   仅

所以听起来您的分析仍然会告诉您完整的链接,而Google搜索您的网站会显示您想要的内容。

如果这是最近的更改,那么我建议您在1-2周内检查Google搜索结果。

如果你正在运行Apache,那么 mod_rewrite 可能就是你想要的:

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

特别是mod-rewrite Regular Expressions部分