Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php AdWords大量误报点击次数-第三方跟踪页面缺少50%的点击_Php_Mysql_Google Ads Api - Fatal编程技术网

Php AdWords大量误报点击次数-第三方跟踪页面缺少50%的点击

Php AdWords大量误报点击次数-第三方跟踪页面缺少50%的点击,php,mysql,google-ads-api,Php,Mysql,Google Ads Api,我为一些客户管理AdWords账户。我使用自己的自定义跟踪链接,将其放置在客户广告的AdWords目标URL框中(示例:) 这个链接指向一个简单的PHP页面,该页面记录IP地址,在远程机器上放置cookie,并将所有内容保存到mysql数据库。然后它将用户转发到客户端的登录页 问题是,AdWords将报告10次点击,但我的PHP跟踪页面只报告5次。为什么我的跟踪页面缺少这么多点击 -在过去的30天里,我的服务时间是100% -我的服务器已启用错误报告。没有记录错误 -我的代码: <?php

我为一些客户管理AdWords账户。我使用自己的自定义跟踪链接,将其放置在客户广告的AdWords目标URL框中(示例:)

这个链接指向一个简单的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"/>';

?>

插入数据库的页面可能被缓存。因此,对adwords的元重定向是有效的,因为浏览器缓存了它,但您的服务器没有被命中,因此无法保存到数据库。您可以尝试添加一些无缓存标头,如:

header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");

(这假设您缺少的是来自同一用户的多次单击。)

Hmmm…有趣的想法和一些我从未考虑过的东西。我只是查看了一下数据库,我有一个IP地址(67.168.102.122),据报道在一个24小时内点击了我的广告三次。所以我假设这意味着缓存不是问题所在?