我只是对谷歌分析有疑问。我有一个使用 php 开发的网站。现在我想把我的网站变成非规范格式。我遵循了以下编码。但谷歌分析仍然无法识别规范 URL。
编码
<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。但它不被谷歌分析识别。谁能告诉我这个编码有什么问题??
最佳答案
您实际上并没有将规范网址传递给 Google Analytics - 为此您需要一个“虚拟网址”,方法是将您想要的值作为第二个参数传递给综合浏览调用:
[...]
_gaq.push(['_trackPageview', <?php echo $url ?> ]);
[...]
关于php - Google Analytics 中的规范 URL 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21309932/