alindinca
Hello Alin,
Sorry for the delay -- Its been a busy few weeks in the office.
I am working with our tech wizard to get a stage site set up for you.
In the meantime, I have easily determined that this is indeed a bug, and can help you to recreate it on your end with no further involvement from me.
On line 1871 - 1904:
**$sql = "select `impressions` from #ad_agency_statistics where `entry_date`='".$time_interval."'";
$database->setQuery($sql);**
if(!$database->query()) {
echo $database->stderr();
return;
}
else{
$all_impressions = $database->loadColumn();
$all_impressions = @$all_impressions["0"];
if(isset($all_impressions)){
$all_impressions = json_decode($all_impressions, true);
if(!isset($all_impressions["0"])){
if(isset($all_impressions)){
$all_impressions = array("0"=>$all_impressions);
}
else{
$temp = array("advertiser_id"=>"0", "campaign_id"=>"0", "banner_id"=>"0", "how_many"=>"0");
$all_impressions = array("0"=>$temp);
}
}
if(isset($all_impressions) && count($all_impressions) > 0){
foreach($all_impressions as $key=>$value){
if(isset($value["campaign_id"]) && $value["campaign_id"] == intval($campaingID) && $value["banner_id"] == intval($bannerID)){
**$how_many = $value["how_many"];**
break;
}
}
}
}
}
This block selects the impressions from the ad_agency_statistics table, and then sets the $how_many variable to this value.
Then, the block from lines 1985 - 2023, which is what actually decreases the Campaign Quantity, uses the following statement at line 1985:
if((isset($banners->type)) && ('cpm'==$banners->type) && ($how_many <= $limit_ip)){
This is comparing the $how_many to the $limit_IP variable. As I've discovered and outlined, $how_many is set on Line 1898 to the ad_agency_statistics total impressions for that ad for that date.
You are correct that on Line 1911 - 1930, we do compare the current user IP to the limit IP's and stop the script there. But, that is not where the bug is.
Hypothetical scenario:
Impression Limit
The Limit IP's is set to 10 per day.
User A
User A views the ad 10 times. On his 11th view, and every view thereafter, he gets kicked out of the ImpressionsCalc function between the block from 1911 - 1930 (specifically, the empty return statement on line 1927).
At this point, the impressions for the ad are 10 in the ad_agency_statistics table, and our campaign quantity has decreased by 10. Thus far, the script is working correctly as it should.
User B
User B views the ad. User B hasn't hit the limit impressions yet (its his first view). However, in the impression calc function, when he gets to line 1985, it is comparing the total ad impressions on this day to the IP Limit.
Therefore, the script fails to correctly decrease the campaign quantity, even when it should.
This can easily be tested by outputting these variables at this point in the script to a PHP error log, on say line 2024.
error_log("How many:" . $how_many . " | Limit IP: " . $limit_ip . " Banners Type: " . $banners->type, 0);
Steps to reproduce:
Set Global IP per day Limit to 5.
Set up a CPM style campaign
Create an ad.
View the ad 5 times from one IP.
- Note that the ad_agency_statistics will increase by 5.
- Note that the ad_agency_ips will show 5 impressions for your IP.
- Most important, note that the ad_agency_campaign impressions quantity will have decreased by 5.
At this point, you can modify the ad_agency_statistics table, and set the how_many value for this particular ad ID to an arbitrary number (say 999). This is optional, but will help with testing the error_log output.
Change your IP (use a VPN)
View the ad 5 times from this NEW IP address
- The ad_agency_statistics still will increase. (correct functionality)
- This new IP will be added to the ad_agency_ips table. (correct functionality)
- However, the the ad_agency_campaign impressions quantity does not decrease for this campaign. This is incorrect functionality.
Review your php error log.
You should see that at line 2024, the $how_many variable being output coincides with the ad_agency_statistics value.
This is incorrect, as it has the unintended consequence of limiting the total possible campaign impressions per day to the same value as the global ip limit
I will work on getting a dev site set up for you to test, but I've now recreated this and debugged and have ratified my findings with another developer here, so hopefully I'm not going crazy.