public function process_business_rules_workflow($logger, $config, $rtb_seat_id, &$no_bid_reason, \model\openrtb\RtbBidRequest &$RtbBidRequest) { $this->config = $config; $this->rtb_seat_id = $rtb_seat_id; // $logger = \rtbbuyv22\RtbBuyV22Logger::get_instance(); $InsertionOrderLineItem_Match_List = array(); $InsertionOrderFactory = \_factory\InsertionOrder::get_instance(); $params = array(); $params["Active"] = 1; $InsertionOrderList = $InsertionOrderFactory->get_cached($this->config, $params); $this->current_time = time(); $InsertionOrderLineItemFactory = \_factory\InsertionOrderLineItem::get_instance(); $InsertionOrderLineItemDomainExclusionFactory = \_factory\InsertionOrderLineItemDomainExclusion::get_instance(); $InsertionOrderLineItemExclusiveInclusionFactory = \_factory\InsertionOrderLineItemDomainExclusiveInclusion::get_instance(); $InsertionOrderLineItemRestrictionsFactory = \_factory\InsertionOrderLineItemRestrictions::get_instance(); $InsertionOrderLineItemVideoRestrictionsFactory = \_factory\InsertionOrderLineItemVideoRestrictions::get_instance(); // match ip against country code \buyrtb\workflows\tasklets\common\insertionorder\GetGeoCodeCountry::execute($logger, $this, $RtbBidRequest); foreach ($InsertionOrderList as $InsertionOrder) { // Check campaign date if (\buyrtb\workflows\tasklets\common\insertionorder\CheckCampaignDate::execute($logger, $this, $RtbBidRequest, $InsertionOrder) === false) { continue; } // Check max spend if (\buyrtb\workflows\tasklets\common\insertionorder\CheckMaxSpend::execute($logger, $this, $RtbBidRequest, $InsertionOrder) === false) { continue; } // Check max impressions if (\buyrtb\workflows\tasklets\common\insertionorder\CheckMaxImpressions::execute($logger, $this, $RtbBidRequest, $InsertionOrder) === false) { continue; } // get markup rate for ad campaign $markup_rate = \util\Markup::getMarkupRate($InsertionOrder, $this->config); // iterate the active banners for this ad campaign $params = array(); $params["InsertionOrderID"] = $InsertionOrder->InsertionOrderID; $params["Active"] = 1; $InsertionOrderLineItemList = $InsertionOrderLineItemFactory->get_cached($this->config, $params); foreach ($RtbBidRequest->RtbBidRequestImpList as $RtbBidRequestImp) { foreach ($InsertionOrderLineItemList as $InsertionOrderLineItem) { if (empty($RtbBidRequestImp->RtbBidRequestVideo) && $InsertionOrderLineItem->ImpressionType == 'video' || !empty($RtbBidRequestImp->RtbBidRequestVideo) && ($InsertionOrderLineItem->ImpressionType == 'banner' || $InsertionOrderLineItem->ImpressionType == 'image')) { continue; } /* * check the business rules against the banner */ // Check PMP if (\buyrtb\workflows\tasklets\common\insertionorderlineitem\CheckPrivateMarketPlace::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem) === false) { continue; } // Check Domain Admin SSP Channel Selections if (\buyrtb\workflows\tasklets\common\insertionorderlineitem\CheckSspChannelSelections::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem) === false) { continue; } // Check banner date if (\buyrtb\workflows\tasklets\common\insertionorderlineitem\CheckBannerDate::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem) === false) { continue; } // Check impression price floor if (\buyrtb\workflows\tasklets\common\insertionorderlineitem\CheckPriceFloor::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem, $markup_rate) === false) { continue; } // Check banner domain exclusive inclusions if (\buyrtb\workflows\tasklets\common\insertionorderlineitem\CheckExclusiveInclusion::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem, $InsertionOrderLineItemExclusiveInclusionFactory) === false) { continue; } // Check banner domain exclusions match if (\buyrtb\workflows\tasklets\common\insertionorderlineitem\CheckDomainExclusion::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem, $InsertionOrderLineItemDomainExclusionFactory) === false) { continue; } if (!empty($RtbBidRequestImp->RtbBidRequestVideo)) { // Video Workflow $VideoWorkflow = new \buyrtb\workflows\VideoWorkflow(); $passed_child_workflow = $VideoWorkflow->process_business_rules_workflow($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem, $InsertionOrderLineItemVideoRestrictionsFactory); } else { // Display Banner Workflow - Default [ banner/ad tag/image creative types ] $DisplayWorkflow = new \buyrtb\workflows\DisplayWorkflow(); $passed_child_workflow = $DisplayWorkflow->process_business_rules_workflow($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $InsertionOrderLineItem, $InsertionOrderLineItemRestrictionsFactory); } if ($passed_child_workflow === false) { continue; } /* * PASSED ALL THE BUSINESS RULES, ADD TO THE RESULTS */ $InsertionOrderLineItemFactory->incrementInsertionOrderLineItemBidsCounterCached($this->config, $rtb_seat_id, $InsertionOrderLineItem->InsertionOrderLineItemID); /* * Adjust the bid rate according to the markup */ $mark_down = floatval($InsertionOrderLineItem->BidAmount) * floatval($markup_rate); $adusted_amount = floatval($InsertionOrderLineItem->BidAmount) - floatval($mark_down); $InsertionOrderLineItem->BidAmount = sprintf("%1.4f", $adusted_amount); // default in config $currency = $this->config['settings']['rtb']['auction_currency']; if (isset($RtbBidRequest->cur[0])) { $currency = $RtbBidRequest->cur[0]; } $InsertionOrderLineItem_Match_List[(string) $InsertionOrderLineItem->UserID][] = array("currency" => $currency, "impid" => $RtbBidRequestImp->id, "InsertionOrderLineItem" => $InsertionOrderLineItem); } } } if (count($InsertionOrderLineItem_Match_List)) { // Check Publisher Score if (\buyrtb\workflows\tasklets\common\thirdparty\CheckPublisherScore::execute($logger, $this, $RtbBidRequest) === false) { $no_bid_reason = NOBID_BAD_PUBLISHER; return array(); } // Check Ad Fraud if (\buyrtb\workflows\tasklets\common\thirdparty\CheckAdFraud::execute($logger, $this, $RtbBidRequest) === false) { $no_bid_reason = NOBID_AD_FRAUD; return array(); } // Check Cookie Match if (\buyrtb\workflows\tasklets\common\thirdparty\CheckCookieMatch::execute($logger, $this, $RtbBidRequest) === false) { $no_bid_reason = NOBID_UNMATCHED_USER; return array(); } } return $InsertionOrderLineItem_Match_List; }
public function process_business_rules_workflow($logger, $config, $rtb_seat_id, &$no_bid_reason, \model\openrtb\RtbBidRequest &$RtbBidRequest) { $this->config = $config; $this->rtb_seat_id = $rtb_seat_id; // $logger = \rtbbuyv22\RtbBuyV22Logger::get_instance(); $AdCampaignBanner_Match_List = array(); $AdCampaignFactory = \_factory\AdCampaign::get_instance(); $params = array(); $params["Active"] = 1; $AdCampaignList = $AdCampaignFactory->get_cached($this->config, $params); $this->current_time = time(); $AdCampaignBannerFactory = \_factory\AdCampaignBanner::get_instance(); $AdCampaignBannerDomainExclusionFactory = \_factory\AdCampaignBannerDomainExclusion::get_instance(); $AdCampaignBannerExclusiveInclusionFactory = \_factory\AdCampaignBannerDomainExclusiveInclusion::get_instance(); $AdCampaignBannerRestrictionsFactory = \_factory\AdCampaignBannerRestrictions::get_instance(); $AdCampaignVideoRestrictionsFactory = \_factory\AdCampaignVideoRestrictions::get_instance(); // match ip against country code \buyrtb\workflows\tasklets\common\adcampaign\GetGeoCodeCountry::execute($logger, $this, $RtbBidRequest); // Check Ad Fraud if (\buyrtb\workflows\tasklets\common\thirdparty\CheckPublisherScore::execute($logger, $this, $RtbBidRequest) === false) { $no_bid_reason = NOBID_BAD_PUBLISHER; return $AdCampaignBanner_Match_List; } // Check Publisher Score if (\buyrtb\workflows\tasklets\common\thirdparty\CheckAdFraud::execute($logger, $this, $RtbBidRequest) === false) { $no_bid_reason = NOBID_AD_FRAUD; return $AdCampaignBanner_Match_List; } // Check Cookie Match if (\buyrtb\workflows\tasklets\common\thirdparty\CheckCookieMatch::execute($logger, $this, $RtbBidRequest) === false) { $no_bid_reason = NOBID_UNMATCHED_USER; return $AdCampaignBanner_Match_List; } foreach ($AdCampaignList as $AdCampaign) { // Check campaign date if (\buyrtb\workflows\tasklets\common\adcampaign\CheckCampaignDate::execute($logger, $this, $RtbBidRequest, $AdCampaign) === false) { continue; } // Check max spend if (\buyrtb\workflows\tasklets\common\adcampaign\CheckMaxSpend::execute($logger, $this, $RtbBidRequest, $AdCampaign) === false) { continue; } // Check max impressions if (\buyrtb\workflows\tasklets\common\adcampaign\CheckMaxImpressions::execute($logger, $this, $RtbBidRequest, $AdCampaign) === false) { continue; } // get markup rate for ad campaign $markup_rate = \util\Markup::getMarkupRate($AdCampaign, $this->config); // iterate the active banners for this ad campaign $params = array(); $params["AdCampaignID"] = $AdCampaign->AdCampaignID; $params["Active"] = 1; $AdCampaignBannerList = $AdCampaignBannerFactory->get_cached($this->config, $params); foreach ($RtbBidRequest->RtbBidRequestImpList as $RtbBidRequestImp) { foreach ($AdCampaignBannerList as $AdCampaignBanner) { if (empty($RtbBidRequestImp->RtbBidRequestVideo) && $AdCampaignBanner->ImpressionType == 'video' || !empty($RtbBidRequestImp->RtbBidRequestVideo) && $AdCampaignBanner->ImpressionType == 'banner') { continue; } /* * check the business rules against the banner */ // Check banner date if (\buyrtb\workflows\tasklets\common\adcampaignbanner\CheckBannerDate::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $AdCampaignBanner) === false) { continue; } // Check to see if this AdCampaginBanner is associated to a contract zone. if (\buyrtb\workflows\tasklets\common\adcampaignbanner\CheckIsContract::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $AdCampaignBanner) === false) { continue; } // Check banner domain exclusive inclusions if (\buyrtb\workflows\tasklets\common\adcampaignbanner\CheckExclusiveInclusion::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $AdCampaignBanner, $AdCampaignBannerExclusiveInclusionFactory) === false) { continue; } // Check banner domain exclusions match if (\buyrtb\workflows\tasklets\common\adcampaignbanner\CheckDomainExclusion::execute($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $AdCampaignBanner, $AdCampaignBannerDomainExclusionFactory) === false) { continue; } if (!empty($RtbBidRequestImp->RtbBidRequestVideo)) { // Video Workflow $VideoWorkflow = new \buyrtb\workflows\VideoWorkflow(); $passed_child_workflow = $VideoWorkflow->process_business_rules_workflow($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $AdCampaignBanner, $AdCampaignVideoRestrictionsFactory); } else { // Display Banner Workflow - Default $DisplayWorkflow = new \buyrtb\workflows\DisplayWorkflow(); $passed_child_workflow = $DisplayWorkflow->process_business_rules_workflow($logger, $this, $RtbBidRequest, $RtbBidRequestImp, $AdCampaignBanner, $AdCampaignBannerRestrictionsFactory); } if ($passed_child_workflow === false) { continue; } /* * PASSED ALL THE BUSINESS RULES, ADD TO THE RESULTS */ $AdCampaignBannerFactory->incrementAdCampaignBannerBidsCounterCached($this->config, $rtb_seat_id, $AdCampaignBanner->AdCampaignBannerID); /* * Adjust the bid rate according to the markup */ $mark_down = floatval($AdCampaignBanner->BidAmount) * floatval($markup_rate); $adusted_amount = floatval($AdCampaignBanner->BidAmount) - floatval($mark_down); $AdCampaignBanner->BidAmount = sprintf("%1.4f", $adusted_amount); // default in config $currency = $this->config['settings']['rtb']['auction_currency']; if (isset($RtbBidRequest->cur[0])) { $currency = $RtbBidRequest->cur[0]; } $AdCampaignBanner_Match_List[(string) $AdCampaignBanner->UserID][] = array("currency" => $currency, "impid" => $RtbBidRequestImp->id, "AdCampaignBanner" => $AdCampaignBanner); } } } return $AdCampaignBanner_Match_List; }
private function process_demand_tag($config, $banner_request) { $banner_request_id = intval($banner_request["demand_banner_id"]); if (isset($banner_request["winning_seat"]) && $banner_request["winning_partner_id"]) { $buyer_id = 'local:' . $banner_request["winning_partner_id"] . ':' . $banner_request["winning_seat"]; } else { $buyer_id = $this->getRequest()->getQuery('buyerid'); } $cache_file_dir = $config['delivery']['cache_file_location'] . 'demand/' . date('m.d.Y') . '/' . date('H') . '/' . date('i') . '/'; if (!file_exists($cache_file_dir)) { mkdir($cache_file_dir, 0777, true); } $tag_type = "default"; if (isset($banner_request["dt"]) && $banner_request["dt"]) { $tag_type = trim($banner_request["dt"]); } $cache_file = $cache_file_dir . $banner_request_id . "." . $tag_type . ".zone.txt"; $InsertionOrderLineItemFactory = \_factory\InsertionOrderLineItem::get_instance(); $params = array(); $params["InsertionOrderLineItemID"] = $banner_request_id; $InsertionOrderLineItem = $InsertionOrderLineItemFactory->get_row_cached($config, $params); if ($InsertionOrderLineItem != null) { $banner_impression_cost = $InsertionOrderLineItem->BidAmount; $spend_increase_gross = floatval($banner_impression_cost) / 1000; $spend_increase_net = $spend_increase_gross; $found_second_price = false; if ($banner_request["winbid"] !== null && !empty($banner_request["winbid"])) { $decrypted_second_price = $this->decrypt_second_price($banner_request["winbid"]); if (floatval($decrypted_second_price)) { $spend_increase_net = floatval($decrypted_second_price) / 1000; $found_second_price = true; } } if ($found_second_price === false) { /* * We already marked down this demand customer's bid when we sent it to the DSP * So at this point we have to get the original bid price set by the demand user * in the demand dashboard and set it to the gross cost for the demand customer. * If we got a second price URL Macro parameter from the DSP, then we are finished. * We set the second price to the net price for the impression. * Otherwise we have to calculate the markup on the demand dashboard bid again * and get the net impression price that way. * * Remember that the RTB bid price sent to the DSP was already marked down by the markup * price in class RtbBuyV22Workflow: * Line 544: $adusted_amount = floatval($InsertionOrderLineItem->BidAmount) - floatval($mark_down); */ $InsertionOrderFactory = \_factory\InsertionOrder::get_instance(); $params = array(); $params["InsertionOrderID"] = $InsertionOrderLineItem->InsertionOrderID; $InsertionOrder = $InsertionOrderFactory->get_row_cached($config, $params); $markup_rate = \util\Markup::getMarkupRate($InsertionOrder, $config); $mark_down = floatval($spend_increase_gross) * floatval($markup_rate); $spend_increase_net = floatval($spend_increase_gross) - floatval($mark_down); } $InsertionOrderLineItemFactory->incrementInsertionOrderLineItemImpressionsCounterAndSpendCached($config, $buyer_id, $banner_request_id, $spend_increase_gross, $spend_increase_net); $InsertionOrderLineItemFactory->incrementBuySideHourlyImpressionsByTLDCached($config, $banner_request_id, $banner_request["tld"]); $is_video_impression = false; if (isset($banner_request["ImpressionType"]) && $banner_request["ImpressionType"] == 'video' || isset($banner_request["video"]) && $banner_request["video"] == 'vast') { $is_video_impression = true; } /* * Video can not be cached */ if (file_exists($cache_file) && $is_video_impression === false) { $cached_tag = file_get_contents($cache_file); if ($banner_request["dt"] == "in") { $this->ad_macros_to_adtag($cached_tag, $banner_request); header("Content-type: application/javascript"); } else { $this->ad_macros_to_adtag($cached_tag, $banner_request); } echo $cached_tag; exit; } $tag_cachable = true; if ($is_video_impression === true) { $adtag = $InsertionOrderLineItem->AdTag; if (\util\ParseHelper::isVastURL($adtag) === true) { $tracker_url = ""; if (isset($banner_request["tracker_url"])) { $tracker_url = $banner_request["tracker_url"]; } $output = $this->get_vast_wrapper_xml($config, $adtag, $tracker_url); $tag_cachable = false; } else { $output = $adtag; } header("Content-type: text/xml"); } elseif ($banner_request["dt"] == "in") { header("Content-type: application/javascript"); $output = "document.write(" . json_encode($InsertionOrderLineItem->AdTag) . ");"; } else { $output = "<!DOCTYPE html>\n<html><head></head><body style=\"margin: 0px; padding: 0px;\">" . $InsertionOrderLineItem->AdTag . "\r\n\r\n</body></html>"; } if ($tag_cachable === true) { $fh = fopen($cache_file, "w"); fwrite($fh, $output); fclose($fh); } if ($is_video_impression === false) { $this->ad_macros_to_adtag($output, $banner_request); } echo $output; exit; } echo "NGINAD"; exit; }
public function process_business_rules_workflow($RtbBid) { $AdCampaignBanner_Match_List = array(); $AdCampaignFactory = \_factory\AdCampaign::get_instance(); $params = array(); $params["Active"] = 1; $AdCampaignList = $AdCampaignFactory->get_cached($RtbBid->config, $params); $current_time = time(); $AdCampaignBannerFactory = \_factory\AdCampaignBanner::get_instance(); $AdCampaignBannerDomainExclusionFactory = \_factory\AdCampaignBannerDomainExclusion::get_instance(); $AdCampaignBannerExclusiveInclusionFactory = \_factory\AdCampaignBannerDomainExclusiveInclusion::get_instance(); $AdCampaignBannerRestrictionsFactory = \_factory\AdCampaignBannerRestrictions::get_instance(); // geocity light $geo_info = null; $maxmind = null; /* * use maxmind incrementally. The geo-Country pay DB we have is only 1 meg * if we need city/state ok, but only load it if absolutely necessary */ if ($RtbBid->bid_request_device_ip !== null && $RtbBid->bid_request_geo === null) { $maxmind = new \geoip\maxmind(); $RtbBid->bid_request_geo["country"] = $maxmind->get_geo_code_country($RtbBid->bid_request_device_ip); } foreach ($AdCampaignList as $AdCampaign) { /* * Check campaign date */ $campaign_startdate = strtotime($AdCampaign->StartDate); $campaign_enddate = strtotime($AdCampaign->EndDate); if ($current_time < $campaign_startdate || $current_time > $campaign_enddate) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check campaign date :: EXPECTED: " . $AdCampaign->StartDate . "->" . $AdCampaign->EndDate . " GOT: " . date('m/d/Y', $current_time); } continue; } /* * Check max spend */ if ($AdCampaign->CurrentSpend >= $AdCampaign->MaxSpend) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Max Campaign Spend Exceeded"; } continue; } /* * Check max impressions */ if ($AdCampaign->ImpressionsCounter >= $AdCampaign->MaxImpressions) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Max Campaign Impressions Exceeded"; } continue; } $markup_rate = \util\Markup::getMarkupRate($AdCampaign, $RtbBid->config); $params = array(); $params["AdCampaignID"] = $AdCampaign->AdCampaignID; $params["Active"] = 1; $AdCampaignBannerList = $AdCampaignBannerFactory->get_cached($RtbBid->config, $params); foreach ($AdCampaignBannerList as $AdCampaignBanner) { /* * check the rules against the banner */ /* * Check banner date */ $banner_startdate = strtotime($AdCampaignBanner->StartDate); $banner_enddate = strtotime($AdCampaignBanner->EndDate); if ($current_time < $banner_startdate || $current_time > $banner_enddate) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner date :: EXPECTED: " . $AdCampaignBanner->StartDate . "->" . $AdCampaignBanner->EndDate . " GOT: " . date('m/d/Y', $current_time); } continue; } /* * Check is mobile web, phone, tablet, native iOS or native Android */ if ($RtbBid->bid_request_mobile != $AdCampaignBanner->IsMobile) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check is mobile web :: EXPECTED: " . $AdCampaignBanner->IsMobile . " GOT: " . $RtbBid->bid_request_mobile; } continue; } /* * Check banner height and width match */ if ($AdCampaignBanner->Height != $RtbBid->bid_request_imp_banner_h || $AdCampaignBanner->Width != $RtbBid->bid_request_imp_banner_w) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner height match :: EXPECTED: " . $AdCampaignBanner->Height . " GOT: " . $RtbBid->bid_request_imp_banner_h; \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner width match :: EXPECTED: " . $AdCampaignBanner->Width . " GOT: " . $RtbBid->bid_request_imp_banner_w; } continue; } /* * Check to see if this AdCampaginBanner is associated to a * contract zone. Contract bound banners are not eligible for * RTB bidding. */ if ($AdCampaignBanner->AdCampaignTypeID == AD_TYPE_CONTRACT) { continue; } elseif ($AdCampaignBanner->AdCampaignTypeID == AD_TYPE_IN_HOUSE_REMNANT && $RtbBid->is_local_request == false) { continue; } elseif ($AdCampaignBanner->AdCampaignTypeID == AD_TYPE_RTB_REMNANT && $RtbBid->is_local_request == true) { continue; } /* * Check banner domain exclusive inclusions * This will narrow the publisher pool down so we * only working with the publishers that the client wants * to advertise on. */ $params = array(); $params["AdCampaignBannerID"] = $AdCampaignBanner->AdCampaignBannerID; $AdCampaignBannerExclusiveInclusionList = $AdCampaignBannerExclusiveInclusionFactory->get_cached($RtbBid->config, $params); foreach ($AdCampaignBannerExclusiveInclusionList as $AdCampaignBannerExclusiveInclusion) { $domain_to_match = strtolower($AdCampaignBannerExclusiveInclusion->DomainName); if ($AdCampaignBannerExclusiveInclusion->InclusionType == "url") { if (strpos(strtolower($RtbBid->bid_request_site_page), $domain_to_match) === false && strpos(strtolower($RtbBid->bid_request_site_domain), $domain_to_match) === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner page url, site exclusive inclusions do not match :: EXPECTED: " . $domain_to_match . " GOT: bid_request_site_page: " . $RtbBid->bid_request_site_page . ", bid_request_site_domain: " . $RtbBid->bid_request_site_domain; } // goto next in the larger enclosing foreach loop continue 2; } } elseif ($RtbBid->bid_request_refurl && $AdCampaignBannerExclusiveInclusion->InclusionType == "referrer") { if (strpos(strtolower($RtbBid->bid_request_refurl), $domain_to_match) === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner page referrer url, site exclusive inclusions do not match :: EXPECTED: " . $domain_to_match . " GOT: " . $RtbBid->bid_request_refurl; } continue 2; } } } /* * Check banner domain exclusions match */ $params = array(); $params["AdCampaignBannerID"] = $AdCampaignBanner->AdCampaignBannerID; $AdCampaignBannerDomainExclusionList = $AdCampaignBannerDomainExclusionFactory->get_cached($RtbBid->config, $params); foreach ($AdCampaignBannerDomainExclusionList as $AdCampaignBannerDomainExclusion) { $domain_to_match = strtolower($AdCampaignBannerDomainExclusion->DomainName); if ($AdCampaignBannerDomainExclusion->ExclusionType == "url") { if (strpos(strtolower($RtbBid->bid_request_site_page), $domain_to_match) !== false || strpos(strtolower($RtbBid->bid_request_site_domain), $domain_to_match) !== false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner page url, site exclusions match :: EXPECTED: " . $domain_to_match . " GOT: bid_request_site_page: " . $RtbBid->bid_request_site_page . ", bid_request_site_domain: " . $RtbBid->bid_request_site_domain; } // goto next in the larger enclosing foreach loop continue 2; } } elseif ($RtbBid->bid_request_refurl && $AdCampaignBannerDomainExclusion->ExclusionType == "referrer") { if (strpos(strtolower($RtbBid->bid_request_refurl), $domain_to_match) !== false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner page referrer url, site exclusions match :: EXPECTED: " . $domain_to_match . " GOT: " . $RtbBid->bid_request_refurl; } continue 2; } } } /* * Check banner restrictions (optional fields) */ $params = array(); $params["AdCampaignBannerID"] = $AdCampaignBanner->AdCampaignBannerID; $AdCampaignBannerRestrictions = $AdCampaignBannerRestrictionsFactory->get_row_cached($RtbBid->config, $params); /* * Check banner restrictions */ if ($AdCampaignBannerRestrictions !== null) { /* * Check banner position on page */ /* * Banner position check not supported by OpenRTB 2.1 */ /* * Check banner system fold position (sFoldPos), I don't think we can trust the user fold position (uFoldPos) */ if ($AdCampaignBannerRestrictions->FoldPos !== null && $RtbBid->bid_request_sFoldPos !== null && $AdCampaignBannerRestrictions->FoldPos != $RtbBid->bid_request_sFoldPos) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner system fold position :: EXPECTED: " . $AdCampaignBannerRestrictions->FoldPos . " GOT: " . $RtbBid->bid_request_sFoldPos; } continue; } /* * Frequency capping not supported by OpenRTB 2.1 */ /* * Time Zone not supported by OpenRTB 2.1 */ /* * IFrame detection not supported by OpenRTB 2.1 */ /* * Multiple nested IFrames detection not supported by OpenRTB 2.1 */ /* * Client's screen resolution detection not supported by OpenRTB 2.1 */ /* * Check browser language */ if ($AdCampaignBannerRestrictions->HttpLanguage !== null && $RtbBid->bid_request_device_language !== null) { $has_http_language = false; $request_language_list = explode(";", strtolower($RtbBid->bid_request_device_language)); $http_language_list = explode(";", strtolower($AdCampaignBannerRestrictions->HttpLanguage)); foreach ($http_language_list as $http_language) { if (in_array(trim($http_language), $request_language_list)) { $has_http_language = true; break; } } if ($has_http_language === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check browser language :: EXPECTED: " . $AdCampaignBannerRestrictions->HttpLanguage . " GOT: " . $RtbBid->bid_request_device_language; } continue; } } /* * Check browser user-agent for string */ if ($AdCampaignBannerRestrictions->BrowserUserAgentGrep !== null && $RtbBid->bid_request_device_ua !== null) { if (strpos(strtolower($RtbBid->bid_request_device_ua), strtolower($AdCampaignBannerRestrictions->BrowserUserAgentGrep)) === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check browser user-agent for string :: EXPECTED: " . $AdCampaignBannerRestrictions->BrowserUserAgentGrep . " GOT: " . $RtbBid->bid_request_device_ua; } continue; } } /* * Check browser cookie for string detection not supported by OpenRTB 2.1 */ /* * Check banner for PMP Enable */ if ($AdCampaignBannerRestrictions->PmpEnable !== null && $RtbBid->bid_request_imp_pmp !== null && $RtbBid->bid_request_imp_pmp != $AdCampaignBannerRestrictions->PmpEnable) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner for PMP Enable :: EXPECTED: " . $AdCampaignBannerRestrictions->PmpEnable . " GOT: " . $RtbBid->bid_request_imp_pmp; } continue; } /* * Check banner for https:// secure */ if ($AdCampaignBannerRestrictions->Secure !== null && $RtbBid->bid_request_secure !== null && $RtbBid->bid_request_secure != $AdCampaignBannerRestrictions->Secure) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner for https:// secure :: EXPECTED: " . $AdCampaignBannerRestrictions->Secure . " GOT: " . $RtbBid->bid_request_secure; } continue; } /* * Check user for Coppa opt out status */ if ($AdCampaignBannerRestrictions->Optout !== null && $RtbBid->bid_request_regs_coppa !== null && $RtbBid->bid_request_regs_coppa != $AdCampaignBannerRestrictions->Optout) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check user for Coppa opt out status :: EXPECTED: " . $AdCampaignBannerRestrictions->Optout . " GOT: " . $RtbBid->bid_request_regs_coppa; } continue; } /* * Check banner for it being in the right vertical */ if ($AdCampaignBannerRestrictions->Vertical !== null && $RtbBid->bid_request_site_publisher_cat !== null) { $has_vertical = false; $vertical_list = explode(",", $AdCampaignBannerRestrictions->Vertical); foreach ($vertical_list as $vertical_id) { if ($RtbBid->bid_request_site_publisher_cat == $vertical_id) { $has_vertical = true; break; } } if ($has_vertical === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner for it being in the right vertical :: EXPECTED: " . $AdCampaignBannerRestrictions->Vertical . " GOT: " . $RtbBid->bid_request_site_publisher_cat; } continue; } } /* * Check banner geography */ if ($RtbBid->bid_request_geo !== null) { if ($AdCampaignBannerRestrictions->GeoCountry !== null && isset($RtbBid->bid_request_geo["country"])) { $has_country = false; $country = strtolower($RtbBid->bid_request_geo["country"]); $geo_country_list = explode(",", $AdCampaignBannerRestrictions->GeoCountry); foreach ($geo_country_list as $geo_country) { if (strtolower($geo_country) == $country) { $has_country = true; break; } } if ($has_country === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner geography : Country :: EXPECTED: " . strtolower($AdCampaignBannerRestrictions->GeoCountry) . " GOT: " . $country; } continue; } else { /* * STATE CHECK */ if ($geo_info === null && $AdCampaignBannerRestrictions->GeoState !== null && !isset($RtbBid->bid_request_geo["state"])) { if ($maxmind === null) { $maxmind = new \geoip\maxmind(); } $geo_info = $maxmind->get_geo_code($RtbBid->bid_request_device_ip); if ($geo_info !== null) { $RtbBid->bid_request_geo["state"] = $geo_info["state"]; $RtbBid->bid_request_geo["city"] = $geo_info["city"]; } } if ($AdCampaignBannerRestrictions->GeoState !== null && isset($RtbBid->bid_request_geo["state"])) { if (!isset($RtbBid->bid_request_geo["state"]) && $geo_info === null) { $geo_info = $maxmind->get_geo_code($this->bid_request_device_ip); $this->bid_request_geo["state"] = $geo_info["state"]; } $has_state = false; $state = strtolower($RtbBid->bid_request_geo["state"]); $geo_state_list = explode(",", $AdCampaignBannerRestrictions->GeoState); foreach ($geo_state_list as $geo_state) { if (strtolower($geo_state) == $state) { $has_state = true; break; } } if ($has_state === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner geography : State :: EXPECTED: " . strtolower($AdCampaignBannerRestrictions->GeoState) . " GOT: " . $state; } continue; } else { /* * CITY CHECK */ if ($geo_info === null && $AdCampaignBannerRestrictions->GeoCity !== null && !isset($RtbBid->bid_request_geo["city"])) { if ($maxmind === null) { $maxmind = new \geoip\maxmind(); } $geo_info = $maxmind->get_geo_code($RtbBid->bid_request_device_ip); $RtbBid->bid_request_geo["state"] = $geo_info["state"]; $RtbBid->bid_request_geo["city"] = $geo_info["city"]; } if ($AdCampaignBannerRestrictions->GeoCity !== null && isset($RtbBid->bid_request_geo["city"])) { $has_city = false; $city = strtolower($RtbBid->bid_request_geo["city"]); $geo_city_list = explode(",", $AdCampaignBannerRestrictions->GeoCity); foreach ($geo_city_list as $geo_city) { if (strtolower($geo_city) == $city) { $has_city = true; break; } } if ($has_city === false) { if (\rtbbuyv22\RtbBuyV22Logger::get_instance()->setting_log === true) { \rtbbuyv22\RtbBuyV22Logger::get_instance()->log[] = "Failed: " . "Check banner geography : City :: EXPECTED: " . strtolower($AdCampaignBannerRestrictions->GeoCity) . " GOT: " . $city; } continue; } } } } } } } } /* * PASSED ALL THE BUSINESS RULES, ADD TO THE RESULTS */ $AdCampaignBannerFactory->incrementAdCampaignBannerBidsCounterCached($RtbBid->config, $RtbBid->rtb_seat_id, $AdCampaignBanner->AdCampaignBannerID); /* * Adjust the bid rate according to the markup */ $mark_down = floatval($AdCampaignBanner->BidAmount) * floatval($markup_rate); $adusted_amount = floatval($AdCampaignBanner->BidAmount) - floatval($mark_down); $AdCampaignBanner->BidAmount = sprintf("%1.4f", $adusted_amount); $AdCampaignBanner_Match_List[] = $AdCampaignBanner; } } return $AdCampaignBanner_Match_List; }