Exemplo n.º 1
0
 public function adsProcess()
 {
     $responseType = '';
     $expandFields = array();
     $zoneID = Input::get('zid', 0);
     $publisherID = Input::get('pid', 0);
     $requestType = Input::get('type', Delivery::REQUEST_TYPE_AD);
     $trackingModel = new Tracking();
     $deliveryModel = new Delivery();
     $flightDateModel = new FlightDateBaseModel();
     //ghi log trước khi xử lý
     $logPreProcess = $trackingModel->logPreProcess($requestType);
     if ($logPreProcess) {
         //kiểm tra referrer
         $hostReferer = $trackingModel->getRequestReferer();
         if (empty($zoneID)) {
             $responseType = Delivery::RESPONSE_TYPE_INVALID;
         } elseif (empty($hostReferer)) {
             $responseType = Delivery::RESPONSE_TYPE_EMPTY_REFERRER;
         } elseif ($trackingModel->countLatestRequest(1) < Delivery::ANTI_CHEAT_MAX_REQUEST_PER_1MIN && $trackingModel->countLatestRequest(5) < Delivery::ANTI_CHEAT_MAX_REQUEST_PER_5MIN) {
             $responseType = Delivery::RESPONSE_TYPE_ANTI_MANY_REQUEST;
         }
         //pre validate ok
         if (empty($responseType)) {
             //default invalid
             if ($zoneID && $publisherID) {
                 $adZone = PublisherAdZoneBaseModel::find($zoneID);
                 if ($adZone && $adZone->publisher) {
                     if ($adZone->publisher_id == $publisherID) {
                         $flightPublishers = FlightPublisherBaseModel::where('publisher_id', $publisherID)->with('flightDate', function ($query) {
                             $today = date('Y-m-d');
                             $query->where('start', '<=', $today)->where('end', '>=', $today);
                         })->where('publisher_ad_zone_id', $zoneID)->orderBy('order', 'asc')->get();
                         if ($flightPublishers) {
                             if ($requestType == Delivery::REQUEST_TYPE_AD) {
                                 //lấy ad từ list thỏa điều kiện để trả về
                                 foreach ($flightPublishers as $k => $flightPublisher) {
                                     if ($flightPublisher->flightDate) {
                                         $runningInventory = $trackingModel->runningInventory($flightPublisher->id);
                                         if ($flightPublisher->total_inventory < $runningInventory) {
                                             $deliveryStatus = $deliveryModel->deliveryAd($flightPublisher->ad, $flightPublisher->flight);
                                             if ($deliveryStatus == Delivery::DELIVERY_STATUS_OK) {
                                                 //trả về ad này
                                                 $serveAd = $flightPublisher->ad;
                                                 $expandFields = array('flight_id' => $flightPublisher->flight_id, 'ad_format_id' => $flightPublisher->ad_format_id, 'ad_id' => $flightPublisher->ad_id, 'campaign_id' => $flightPublisher->campaign_id, 'publisher_ad_zone_id' => $flightPublisher->publisher_ad_zone_id, 'flight_publisher_id' => $flightPublisher->id, 'publisher_id' => $flightPublisher->publisher_id, 'flight_publisher_id' => $flightPublisher->id);
                                                 break;
                                             }
                                         }
                                     }
                                 }
                                 //endforeach
                             } elseif ($requestType == Delivery::REQUEST_TYPE_TRACKING_BEACON) {
                                 //tracking beacon TO DO, now : do nothing
                                 if ($trackingModel->isKnownVisitor()) {
                                 } else {
                                     $responseType = Delivery::RESPONSE_TYPE_EMPTY_REFERRER;
                                 }
                             }
                         }
                     }
                     //serve Ad
                     if (!empty($serveAd)) {
                     } else {
                     }
                 }
             }
         }
     }
     if (empty($responseType)) {
         $responseType = Delivery::RESPONSE_TYPE_INVALID;
     }
     //ghi log process
     $trackingModel->logAfterProcess($responseType, $expandFields);
     return $deliveryModel->emptyAd();
 }
Exemplo n.º 2
0
 public function trackEvent()
 {
     ignore_user_abort(true);
     $this->layout = null;
     $response = null;
     $responseType = '';
     $expandFields = array();
     $deliveryStatus = '';
     $event = strtolower(Input::get('evt', ''));
     $requestType = Input::get('rt', Delivery::REQUEST_TYPE_TRACKING_BEACON);
     $checksum = Input::get('cs', '');
     $flightWebsiteID = Input::get('fpid', 0);
     $zoneID = Input::get('zid', 0);
     $isOverReport = Input::get('ovr');
     //custom code for VIB 068 Relaunch form complete tracking
     if (Input::get('wid') == 48 && $event == 'complete') {
         $flightWebsiteID = 172;
         $event = "impression";
     }
     $trackingModel = new Tracking();
     $deliveryModel = new Delivery();
     //ghi log trước khi xử lý
     $logPreProcess = $trackingModel->logPreProcess($requestType, Input::get());
     if ($logPreProcess) {
         //kiểm tra referrer
         $hostReferer = $trackingModel->getRequestReferer();
         $responseType = $trackingModel->checkPreProcess($requestType, $hostReferer, $zoneID);
         if (empty($responseType)) {
             $adZone = $deliveryModel->getAdzone($zoneID);
             if ($adZone) {
                 if (isSameDomain($hostReferer, getWebDomain($adZone->site->url)) || isLocal()) {
                     $flightWebsite = $deliveryModel->getFullFlightWebsite($flightWebsiteID);
                     if ($flightWebsite) {
                         //checksum
                         if ($flightWebsite->flight->ad_format_id == Delivery::TRACKING_CODE_ADID) {
                             $responseType = Delivery::RESPONSE_TYPE_TRACKING_BEACON_SUCCESS;
                         } elseif ($trackingModel->isValidTrackingBeacon($checksum, $event)) {
                             $responseType = Delivery::RESPONSE_TYPE_TRACKING_BEACON_SUCCESS;
                             //set cookie for retargeting
                             $trackingModel->rememberRetarget($flightWebsite->flight->campaign_id, $event);
                         } else {
                             $responseType = Delivery::RESPONSE_TYPE_CHECKSUM_ERROR;
                         }
                     }
                     //else invalid
                 }
             }
         }
         if (empty($responseType)) {
             $responseType = Delivery::RESPONSE_TYPE_INVALID;
         } elseif ($responseType == Delivery::RESPONSE_TYPE_TRACKING_BEACON_SUCCESS) {
             $expandFields = array('flight_id' => $flightWebsite->flight_id, 'ad_format_id' => $adZone->ad_format_id, 'ad_id' => $flightWebsite->flight->ad_id, 'campaign_id' => $flightWebsite->flight->campaign_id, 'publisher_ad_zone_id' => $adZone->id, 'flight_website_id' => $flightWebsite->id, 'website_id' => $flightWebsite->website_id);
             $expandFields['checksum'] = $checksum;
             $eventChecksum = $event;
             $trackingModel->setChecksumTrackingEvent($checksum, $event);
             //udpate inventory
             //$inventoryMetric = $trackingModel->getTrackingEventType($flightWebsite->flight->cost_type);
             $inventoryMetric = $trackingModel->getTrackingEventType($flightWebsite->flight->cost_type);
             if ($event == $inventoryMetric) {
                 $trackingModel->updateInventory($flightWebsite->flight->id, $flightWebsite->id, $inventoryMetric, $isOverReport);
             }
             if (isset($flightWebsite->flight->event) && $flightWebsite->flight->event != '') {
                 $flightEvent = $flightWebsite->flight->event;
             } else {
                 // Truong hop nhung flight truoc day khong co setting event
                 $flightEvent = $inventoryMetric;
             }
             if ($event == $flightEvent) {
                 //incre today capped this ad by 1
                 $trackingModel->incFreCap($flightWebsite->flight);
             }
             //update tracking summary
             $rawTrackingSummary = new RawTrackingSummary();
             $rawTrackingSummary->addSummary($event, $flightWebsite->website_id, $adZone->id, $adZone->ad_format_id, $flightWebsite->flight_id, $flightWebsite->id, $flightWebsite->flight->ad_id, $flightWebsite->flight->campaign_id);
             $uniqueEvent = '';
             //unique impression
             if ($event == 'impression') {
                 $uniqueEvent = 'unique_impression';
                 $expandFields['unique_impression'] = $trackingModel->isUniqueImpression($flightWebsite->id);
             }
             //unique click
             if ($event == 'click') {
                 $uniqueEvent = 'unique_click';
                 $expandFields['unique_click'] = $trackingModel->isUniqueClick($flightWebsite->id);
             }
             //add summary unique click or impression
             if (!empty($expandFields[$uniqueEvent])) {
                 $rawTrackingSummary->addSummary($uniqueEvent, $flightWebsite->website_id, $adZone->id, $adZone->ad_format_id, $flightWebsite->flight_id, $flightWebsite->id, $flightWebsite->flight->ad_id, $flightWebsite->flight->campaign_id);
             }
         }
     }
     //ghi log process
     $logAfterProcess = $trackingModel->logAfterProcess($responseType, $expandFields, $logPreProcess);
     //response to client
     pr($expandFields);
     pr($responseType, 1);
     if ($event == 'click' && Input::get('to')) {
         //redirect to ad's destination url on click event
         return Redirect::to(urldecode(Input::get('to')));
     } else {
         //return 1x1 transparent GIF
         $response = $trackingModel->outputTransparentGif();
         // exit();
     }
 }