Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 谷歌分析中的规范URL问题_Php_Google Analytics_Seo - Fatal编程技术网

Php 谷歌分析中的规范URL问题

Php 谷歌分析中的规范URL问题,php,google-analytics,seo,Php,Google Analytics,Seo,我只是对谷歌分析有意见。我有一个使用php开发的网站。现在我想把我的网站变成非标准格式。我遵循下面的编码。但谷歌分析仍然无法识别标准URL 编码 <html> <head> <link rel="canonical" href="<?php $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']; echo $url;?>"> <script type="text/javasc

我只是对谷歌分析有意见。我有一个使用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传递给Google Analytics—为此,您需要一个“虚拟url”,将您想要的值作为第二个参数传递给pageview调用:

[...]
  _gaq.push(['_trackPageview', <?php echo $url ?> ]);
[...]
[…]
_gaq.push([''u trackPageview',]);
[...]
根据

谷歌目前支持这些链接头元素用于网络搜索 只是

所以听起来你的分析仍然会告诉你完整的链接,而谷歌搜索你的网站会显示你想要的

如果这是最近的变化,那么我建议在1-2周内检查谷歌搜索结果

如果您正在运行Apache,那么您可能正在寻找的是mod_rewrite


特别是
mod rewrite Regular Expressions
部分

可以显示
我将id传递到此文件的HTML。如果我给出的url是规范格式的,那么我想把我的url转换成规范格式的example.com/file.php?id=10。。就这样。如果你知道怎么做,让我知道,兄弟。我明白了,请看我的回答。我想这会解决我的问题。谷歌分析仍然只识别非规范格式。是的,你的编码现在可以工作了_gaq.push([''u trackPageview','');