我为少数客户管理AdWords帐户。我使用自己的自定义跟踪链接,将其放置在客户广告的AdWords目标网址框中(例如:http://www.mywebsite.com/track.php?id=1234567890)。
此链接指向一个简单的PHP页面,该页面记录IP地址,将cookie放在远程计算机上,并将所有内容保存到mysql数据库。然后,它将用户转发到客户端的登录页面。
问题是,AdWords会报告10次点击,但我的PHP跟踪页面仅报告5.为什么我的跟踪页面缺少这么多次点击?
- 过去30天我的服务器上线时间一直是100%。
- 我的服务器启用了错误报告。没有记录错误。
- 我的代码:
<?php
//determine which client/campaign this belongs to by reading get id from URL
if (isset($_GET['id'])) {
$tracker_id = $_GET['id'];
} else {
exit('Sorry, that ID is invalid.');
}
//if referrer is same page we just forwarded to, prevent rest of code from running to prevent redirect loop:
if (isset($_SERVER['HTTP_REFERER'])) {
if ($_SERVER['HTTP_REFERER'] == 'http://www.clientshomepage.com') {
//stop running script and send user back to where they originally came from:
echo '<script type="text/javascript">window.history.go(-1);</script>';
exit();
}
}
//check to see if remote machine already has cookie set:
if (!isset($_COOKIE[$tracker_id])) {
//create tracking id:
$cookie_id = mt_rand(100000000, 999999999);
//insert unique ID into cookie and place on remote machine:
setcookie($tracker_id, $cookie_id, time() + (86400 * 365), "/");
} else {
$cookie_id = $_COOKIE[$tracker_id];
}
//log the IP address of the person clicking:
if (isset($_SERVER['REMOTE_ADDR'])) {
$remote_addr = $_SERVER['REMOTE_ADDR'];
} else {
$remote_addr = '';
}
//include pdo/mysql credentials file:
require('pdo.php');
//insert collected data about this click into the database:
try {
$sql = "INSERT INTO mytable_name (tracker_id, cookie_id, remote_addr, click_time)
VALUES (:tracker_id, :cookie_id, INET_ATON(:remote_addr), :click_time)";
$stmt = $pdo->prepare($sql);
$stmt->execute(
array(
':tracker_id' => $tracker_id,
':cookie_id' => $cookie_id,
':remote_addr' => $remote_addr,
':click_time' => time()
)
);
$stmt = null;
} catch (PDOException $err) {
exit('Error Number: ' . $err->getCode() . '<br>' . 'Sorry, there was a database error. Please notify technical support.');
}
//forward user to landing page:
echo '<script>window.location = "http://www.clientslandingpage.com"</script>';
//in case redirect fails due to disabled javascript, redirect user old school style:
echo '<meta http-equiv="refresh" content="3;url=http://www.clientslandingpage.com"/>';
?>
答案 0 :(得分:1)
可以缓存插入数据库的页面。所以meta重定向到adwords是有效的,因为浏览器缓存了它,但是你的服务器没有被命中,因此无法保存到db。您可以尝试添加一些无缓存标头,如:
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
(这假设你缺少的是来自同一用户的多次点击。)