由于想知道自己网站的访问流量等情况,我就安装了这个插件:Google Analytics for WordPress。
安装的方法:
1.到Google Analytics注册一个帐号,如果你有了gmail帐号的话,就可以直接用gmail帐号开通。选择“添加新网站”,填上你的网站的网址,一路下去,最后会生成你的网站的Google Analytics分析代码。在代码中找到一个ID号copy下来就行,ID号位于这样的语句中:“var pageTracker = _gat._getTracker(”UA-9085397-1″);”,其中类似UA-9085397-1这样格式的字符串就是ID号。
2.在wordpress管理后台安装Google Analytics for WordPress插件,然后启用这个插件。
3.在插件管理里设置这个插件,填上你所得到的Analytics Account ID号,其他的选项不用动它,然后点击”Update Setteings”.
正常情况下这样应该就可以了。
但我遇到了问题:设置完成后,显示了一个消息”Warning wp_footer(); not found in your footer.php file, this might mean this plugin will not work!”
我登录我的Google Analytics 帐号,发现看不到任何关于我的网站的流量统计数据,看来这个插件的确not working.
解决问题的过程:用上面的warning message搜索了一下,找到了wordpress support forums里一个相关的问题,有人给出的解决方法是:在你的主题里的footer.php里入一句<?php wp_footer(); ?> ,而且这一句要加在标签</body>之前,不然也是不行的。然后有人回复说他在footer.php里根本找不到</body>,所以问题还是不能解决。我打开了我的博客的主题的footer.php, 很不幸地,我在里面也找不到</body>。
我仔细看了我的wordpress后台里的各个主题的footer.php,发现不同主题的footer.php的代码是不同的。我一开始用的那个wordpress默认主题的footer.php的代码里可以找到</body>,而且“<?php wp_footer(); ?>”也已经在那里了。于是我把博客主题暂时先改回到以前的主题,结果插件设置就一切正常了。但我还想用我现在的主题啊,怎么办? 我研究了我这个主题的footer.php的代码,发现有这样一句:“<?php include(’templates/end.php’); ?> ”,我就猜有</body>的哪一段代码应该是移到了end.php中。打开end.php,果然发现了</body>,而且那一句“<?php wp_footer(); ?>”已经在</body>之前了。
最终的解决方法:我把end.php里的代码都copy下来,然后去代替footer.php里的那一句“<?php include(’templates/end.php’); ?> ”,这回插件设置就正常了,我也可以在我的Google Analytics帐号里看到网站的流量统计数据了。我也把我的解决方法回复在论坛里了:
I met the same problem as you did. I am using the theme “inove” for my blog, and I found that footer.php of this theme has 1 line as below:
<?php include(’templates/end.php’); ?>
I open the end.php and found it do has the codes like this:
<?php wp_footer(); ?>
</body>
</html>So I just copy the content of end.php to replace the line”<?php include(’templates/end.php’); ?>” in footer.php, and the problem is solved.
Related posts:
标签: Google, Google Analytics, wordpress
很好,刚好能用上。