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'); }
protected function isClickUnique(Pap_Contexts_Click $context) { return $context->getVisit()->isNewVisitor(); }
/** * 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; }
private function initTransactionObject(Pap_Contexts_Click $context) { $transaction = new Pap_Common_Transaction(); $transaction->setTotalCost(''); $transaction->generateNewTransactionId(); $transaction->setData1($context->getExtraDataFromRequest(1)); $transaction->setData2($context->getExtraDataFromRequest(2)); $transaction->set(Pap_Db_Table_Transactions::REFERER_URL, $context->getReferrerUrl()); $transaction->set(Pap_Db_Table_Transactions::IP, $context->getIp()); $transaction->set(Pap_Db_Table_Transactions::BROWSER, $context->getUserAgent()); $transaction->setType(Pap_Common_Constants::TYPE_CLICK); $transaction->setDateInserted($context->getVisitDateTime()); if ($context->getVisit()!= null && $context->getVisit()->getCountryCode() != '') { $transaction->setCountryCode($context->getVisit()->getCountryCode()); } $context->setTransactionObject($transaction); $context->debug("Transaction object set"); }