基本上我想在服務器上運行Google Analytics,而不是顯示1px .GIF(原因是我想要顯示圖像,而不顯示它在HTML中,但是作爲Content-類型:image/JPEG在圖像上使用Google Analytics
$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映像以更改其映像類型?爲什麼? (它不會工作,無論如何,因爲參考信息將不正確。) – 2010-08-25 08:46:48
不,我想基本上將GA添加到.jpg(我自己的圖像),但它必須是一個PHP文件,以獲得GA運行。所以我猜我必須首先打開並關閉GA .gif文件(在服務器上) – NWhite 2010-08-25 08:55:14