public function checkClickFraudProtection(Pap_Contexts_Click $context) { $checkIt = Gpf_Settings::get(Pap_Settings::GEOIP_CLICKS); if($checkIt != Gpf::YES) { $context->debug(' PapGeoip: Check country blacklist is not turned on for clicks'); return; } $context->debug(' PapGeoip: Check country blacklist started'); $blacklistedCountries = str_replace(' ', ',', trim(strtoupper(Gpf_Settings::get(Pap_Settings::GEOIP_CLICKS_BLACKLIST)))); $checkAction = Gpf_Settings::get(Pap_Settings::GEOIP_CLICKS_BLACKLIST_ACTION); if($blacklistedCountries == '') { $context->debug("PapGeoip: No country is blacklisted."); return; } if($checkAction != Pap_Tracking_Click_FraudProtection::ACTION_DECLINE && $checkAction != Pap_Tracking_Click_FraudProtection::ACTION_DONTSAVE) { $context->debug("PapGeoip: Action after check is not correct: '$checkAction'"); return; } $countryCode = strtoupper($context->getCountryCode()); if (!strlen($countryCode)) { $context->debug(" PapGeoip: Origin country was not recognized for IP: " . $context->getVisit()->getIp()); return; } $arrBlacklist = explode(',', $blacklistedCountries); if(in_array($countryCode, $arrBlacklist)) { if($checkAction == Pap_Tracking_Click_FraudProtection::ACTION_DONTSAVE) { $context->debug(" PapGeoip: STOPPING (setting setDoTrackerSave(false), country $countryCode is blacklisted"); $context->setDoTrackerSave(false); $context->debug(' PapGeoip: Check country blacklist endeded'); return; } else { $context->debug(" DECLINING, country $countryCode is blacklisted"); $this->declineClick($context); $context->debug(' PapGeoip: Check country blacklist endeded'); return; } } else { $context->debug(" Country $countryCode is not blacklisted"); } $context->debug(' PapGeoip: Check country blacklist endeded'); }
/** * checks for duplicate records from same IP * * @param Pap_Contexts_Click $context * @return string */ private function checkMultipleClicksFromSameIP(Pap_Contexts_Click $context) { if(Gpf_Settings::get(Pap_Settings::REPEATING_CLICKS_SETTING_NAME) != Gpf::YES) { $context->debug(' Check for duplicate clicks with the same IP is not turned on'); return true; } $context->debug(' Checking duplicate clicks from the same IP started'); $checkPeriod = Gpf_Settings::get(Pap_Settings::REPEATING_CLICKS_SECONDS_SETTING_NAME); $checkAction = Gpf_Settings::get(Pap_Settings::REPEATING_CLICKS_ACTION_SETTING_NAME); if($checkPeriod == '' || $checkPeriod == '0' || !is_numeric($checkPeriod)) { $context->debug("Checking period is not correct: '$checkPeriod'"); return true; } if($checkAction != self::ACTION_DECLINE && $checkAction != self::ACTION_DONTSAVE) { $context->debug("Action after check is not correct: '$checkAction'"); return true; } $ip = $context->getVisit()->getIp(); $clickObject = new Pap_Db_RawClick(); //only clicks on same banner will be fraudulent $bannerId = false; if (Gpf_Settings::get(Pap_Settings::REPEATING_BANNER_CLICKS) == Gpf::YES) { $bannerId = $context->getBannerId(); if (!strlen($bannerId)) { $bannerId = false; } } $recordsCount = $clickObject->getNumberOfClicksFromSameIP($ip, $checkPeriod, $bannerId, $context->getVisitDateTime()); if($recordsCount > 0) { if($checkAction == self::ACTION_DONTSAVE) { $context->debug(" STOPPING (setting setDoTrackerSave(false), found another clicks from the same IP: $ip within $checkPeriod seconds"); $context->setDoTrackerSave(false); $context->debug(' Checking duplicate clicks from the same IP endeded'); return false; } else { $context->debug(" DECLINING, found another clicks from the same IP: $ip within $checkPeriod seconds"); $this->declineClick($context); $context->debug(' Checking duplicate clicks from the same IP endeded'); return true; } } else { $context->debug(" No duplicate clicks from the same IP: $ip found"); } $context->debug(' Checking duplicate clicks from the same IP endeded'); return true; }
/** * processes match and sets userid, campaign, banner, channel */ protected function fillParametersFromMatch(Pap_Contexts_Click $context, $match) { if($match == null || $match == false || !is_array($match) || count($match) != 5) { $context->debug(" Matching data are in incorrect format"); } $userId = $match['userid']; $url = $match['url']; $channelid = $match['channelid']; $campaignid = $match['campaignid']; $bannerid = $match['bannerid']; $context->debug(" Referrer matched '$url' pattern"); // user if ($userId == '') { $context->debug(" DirectLink affiliate Id is empty stopping"); $context->setDoTrackerSave(false); return; } try { $user = Pap_Affiliates_User::loadFromId($userId); } catch (Gpf_Exception $e) { $context->debug(" DirectLink affiliate with id '$userId' doesn't exist"); $context->setDoTrackerSave(false); return; } $context->debug(" Setting affiliate from referrer URL. Affiliate Id: ".$userId.""); $context->setUserObject($user); // banner $banner = null; try { $bannerFactory = new Pap_Common_Banner_Factory(); $banner = $bannerFactory->getBanner($bannerid); $context->debug("Setting banner from referrer URL. Banner Id: ".$bannerid.""); $context->setBannerObject($banner); } catch (Gpf_Exception $e) { $context->debug("Banner parameter in DirectLink is empty"); } // campaign $campaign = $this->getCampaignById($context, $campaignid); if($campaignid != '' && $campaign != null) { $context->debug(" Setting campaign from DirectLink. Campaign Id: ".$campaignid.""); $context->setCampaignObject($campaign); } else { $context->debug(" Campaign parameter in DirectLink is empty"); } if($banner != null) { $context->debug(" Trying to get campaign from banner"); $campaign = $this->getCampaignFromBanner($context, $banner); } if($campaign == null) { $campaign = $this->getDefaultCampaign($context); } if($campaign != null) { $context->setCampaignObject($campaign); } else { $context->setDoTrackerSave(false); $context->debug(" No default campaign defined"); } // channel $channel = $this->getChannelById($context, $channelid); if($channelid != '' && $channel != null) { $context->debug(" Setting channel from referrer URL. Channel Id: ".$channelid.""); $context->setChannelObject($channel); } else { $context->debug(" Channel parameter in DirectLink is empty"); } // account if ($campaign != null) { $context->setAccountId($campaign->getAccountId(), Pap_Contexts_Tracking::ACCOUNT_RECOGNIZED_FROM_CAMPAIGN); } }
private function createContext(Pap_Db_Visit $visit) { $context = new Pap_Contexts_Click(); $context->setDoTrackerSave(true); $context->setVisit($visit); $context->setVisitorId($visit->getVisitorId()); $context->setDateCreated($visit->getDateVisit()); $this->accountRecognizer->recognize($context); $this->visitorAffiliateCache->setAccountId($context->getAccountId()); return $context; }