【发布时间】:2015-02-07 08:05:32
【问题描述】:
我为几个客户管理 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"/>';
?>
【问题讨论】:
标签: php mysql google-ads-api