1

这是我用来跟踪电子邮件打开率的页面 这是一个 php 重定向到 gif 文件

问题是,我在 GA 中使用同一个帐户创建了两个campagin,它只适用于第一个帐户,是我的设置问题吗??谢谢

    <?
$var_utmac = 'UA-id-1'; //enter the new urchin code
$var_utmhn = 'mywebsite2.com'; //enter your domain
$var_utmn = rand(1000000000,9999999999); //random request number
$var_cookie = rand(10000000,99999999); //random cookie number
$var_random = rand(1000000000,2147483647); //number under 2147483647
$var_today = time(); //today
$utm_source = 'newsletter';
$utm_medium = 'email';
$utm_campaign = 'newsletter';
$var_uservar = '-'; //enter your own user defined variable
$var_utmp = 'http://dl.dropbox.com/u/15672207/web.png'; //this example adds a fake file request to the (fake) tracker directory (the image/pdf filename).
$urchinUrl = 'http://www.google-analytics.com/__utm.gif?utmwv=1&utmn='.$var_utmn.'&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn='.$var_utmhn.'&utm_source='.$utm_source.'&utm_medium='.$utm_medium.'&utm_campaign='.$utm_campaign.'&utmp='.$var_utmp.'&utmac='.$var_utmac.'&utmcc=__utma%3D'.$var_cookie.'.'.$var_random.'.'.$var_today.'.'.$var_today.'.'.$var_today.'.2%3B%2B__utmb%3D'.$var_cookie.'%3B%2B__utmc%3D'.$var_cookie.'%3B%2B__utmz%3D'.$var_cookie.'.'.$var_today.'.2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D'.$var_cookie.'.'.$var_uservar.'%3B';
// Now fire off the HTTP request
$handle = fopen ($urchinUrl, "r");
$test = fgets($handle);
fclose($handle);
// Redirect this script as an actual GIF file sitting on this web server
header('Location: http://dl.dropbox.com/u/15672207/web.png');
?>
4

1 回答 1

0

使用 Google Analytics 进行像素跟踪的代码看起来不错,但如果您更改参数,这可能会有所不同。注意对您的请求进行 URL 编码。

您可以使用http_build_query组合 URL 编码和参数包装:

$data['utmac'] = 'UA-2202604-2';
$data['utmhn'] = 'mywebsite.com';
...
$url = 'http://www.google-analytics.com/__utm.gif?' . http_build_query($data, '', '&');
$handle = fopen($url, "r");
$test = fgets($handle);
fclose($handle);
于 2012-04-11T18:20:56.883 回答