【发布时间】:2010-08-25 08:41:37
【问题描述】:
基本上我想在服务器上运行 Google Analytics,而不是显示 1px .GIF(原因是我想显示一个图像而不是 HTML,而是作为内容类型:image/jpeg
$GA_ACCOUNT = "MO-3845491-5";
$GA_PIXEL = "ga.php";
function googleAnalyticsGetImageUrl() {
global $GA_ACCOUNT, $GA_PIXEL;
$url = "";
$url .= $GA_PIXEL . "?";
$url .= "utmac=" . $GA_ACCOUNT;
$url .= "&utmn=" . rand(0, 0x7fffffff);
$referer = $_SERVER["HTTP_REFERER"];
$query = $_SERVER["QUERY_STRING"];
$path = $_SERVER["REQUEST_URI"];
if (empty($referer)) {
$referer = "-";
}
$url .= "&utmr=" . urlencode($referer);
if (!empty($path)) {
$url .= "&utmp=" . urlencode($path);
}
$url .= "&guid=ON";
return $url;
}
$googleAnalyticsImageUrl = googleAnalyticsGetImageUrl();
//echo '<img src="' . $googleAnalyticsImageUrl . '" />';
//open the google script with all our settings to generate the 1px x 1px blank gif which reports to GA
$handle = fopen ($googleAnalyticsImageUrl, "r");
$test = fgets($handle);
echo $test;
fclose($handle);
//Pretend this page was a jpg image all along and get the jpg and return it.
$imageurl = fopen ('http://www.default.com/test.jpg', "r"); //this is where the real file should be located
while (!feof ($imageurl)) {
$image = fgets($imageurl, 4096);
header('Content-type: image/jpeg');
echo $image;
}
fclose($imageurl);
任何帮助将不胜感激,因为我是 GA 的新手
【问题讨论】:
-
我不明白你在做什么。您是否正在代理 GA 图像以更改其图像类型?为什么? (无论如何,它不会起作用,因为 REFERER 信息将不正确。)
-
不,我想基本上将 GA 添加到 .jpg(我自己的图像)上,但是它必须是一个 php 文件才能让 GA 运行。所以我猜我必须先打开和关闭 GA .gif 文件(在服务器上)
标签: php google-analytics