我在使用 PHP 和 Google Analytics 时遇到问题。基本上我想做的是当用户从我的电子邮件 <img src='path/to/image' />
访问此图像时计算一次访问来自 Google Analytics 中他的电子邮件客户端。
// If is a view then just show an image
if($mysqlAction == "VIEW")
{
// Create a blank image and add some text
header('Content-Type: image/jpeg');
readfile('image.jpg');
?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-35932495-2']);
_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>
<?php
}
我的问题是之后
// Create a blank image and add some text
header('Content-Type: image/jpeg');
readfile('image.jpg');
输入任何代码都是没有用的,因为 script.php
的输出就像访问 image.jpg
,但我确实需要计算谷歌分析中的观看次数。
我想要什么:
- 我该如何解决这个问题?
- 不要给我类似 Sendblaster 的 TrackReports 之类的替代方案……或任何类似的解决方案。
我的想法是:
- 我的想法是使用双缓冲区,例如首先显示 analitycs 代码,然后
ob_flush()
图像 - 通过
CURL
获取另一页或其他东西... - 对 PHP 使用 Analitics ...
有什么解决办法吗?
最佳答案
我想你可以在这篇文章中找到解决方案:http://techpad.co.uk/content.php?sid=186
作者实现了 PHP 类来从服务器端而不是客户端 JS 访问 google 分析服务。
希望对您有所帮助。
关于php - 使用 Google Analytics 统计图像中的用户访问次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13177402/