/**
     * returns user object from forced parameter AffiliateID
     * parameter name is dependent on track.js, where it is used.
     *
     * @return Pap_Common_Banner
     * @throws Gpf_Exception
     */
    private function getBannerFromForcedParameter(Pap_Contexts_Click $context) {
        $id = $context->getForcedBannerId();

        if($id == '') {
            $message = 'Banner id not found in forced parameter';
            $context->debug($message);
            throw new Pap_Tracking_Exception($message);
        }

        $context->debug("Getting banner from forced request parameter. Banner Id: ".$id);
        return $this->getBannerById($context, $id);
    }
    /**
     * returns user object from standard parameter from request
     *
     * @return string
     */
    protected function getUserFromParameter(Pap_Contexts_Click $context) {
        $parameterName = Pap_Tracking_Request::getAffiliateClickParamName();
        if($parameterName == '') {
            $context->debug("  Cannot get name of request parameter for affiliate ID");
            return null;
        }
         
        $context->debug("  Trying to get affiliate from request parameter '$parameterName'");

        $userId = $context->getAffiliateId();
        if($userId != '') {
            $context->debug("    Setting affiliate from request parameter. Affiliate Id: ".$userId);
            return $this->getUserById($context, $userId);
        }

        $context->debug("    Affiliate not found in parameter");
        return null;
    }
示例#3
0
    public function saveRotatorClick(Pap_Contexts_Click $context) {
        $context->debug('FEATURE BannerRotator: saveRotatorClick started');

        if($context->getDoTrackerSave()) {
            $banner = $context->getBannerObject();
            if($banner != null && is_object($banner) && $banner->getParentBanner()!=null){
                $context->debug('  FEATURE BannerRotator: Saving rotator click');
                $this->saveChildClick($banner, $context);
            } else {
                $context->debug('  FEATURE BannerRotator: Banner is not in rotator, skipping');
            }
        } else {
            $context->debug('FEATURE BannerRotator: Saving in Tracker is disabled (getDoTrackerSave() returned false), continuing without saving');
        }

        $context->debug('FEATURE BannerRotator: saveRotatorClick ended');
        $context->debug('');
        return Gpf_Plugins_Engine::PROCESS_CONTINUE;
    }
示例#4
0
    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');
    }
    private function getCampaignFromBanner(Pap_Contexts_Click $context, $banner) {
        $campaignId = $banner->getCampaignId();
        if($campaignId != '') {
            $context->debug("    Setting campaign. Campaign Id: ".$campaignId);
            return $this->getCampaignById($context, $campaignId);
        }

        $context->debug("    Campaign not found");
        return null;
    }
    /**
     * 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;
    }
示例#7
0
	private function saveClick(Pap_Contexts_Click $context, Pap_Db_Click $clickPrototype,
	                            Pap_Common_Banner $banner=null, Pap_Db_RawClick $rawClick) {
	    $context->debug('Saving click (as object, not rawclick)');
		$clickParams = $this->getClickParamsArray($clickPrototype, $context, $banner);
		$hash = $this->hashClick($clickPrototype, $clickParams);
        if (!array_key_exists($hash, $this->clicks)) {
            $this->clicks[$hash] = $this->initClick($clickPrototype, $clickParams);
        }

        $click = $this->clicks[$hash];
        $context->debug('click type=' . $rawClick->getType());
        switch ($rawClick->getType()) {
            case Pap_Db_ClickImpression::STATUS_DECLINED:
                $click->addDeclined();
                break;
            case Pap_Db_ClickImpression::STATUS_UNIQUE:
                $click->addUnique();
            default:
                $click->addRaw();
                break;
        }
        $context->debug('Saving done');
	}
示例#8
0
    public function setSaveClickCommission(Pap_Contexts_Click $context) {
        $context->debug('MaxCommission per referral checking.');
        $commissionTypeId = $this->getCommissionTypeId($context);
        if ($commissionTypeId == null) {
            $context->debug('MaxCommission Commission type is null. Ended.');
            return;
        }

        try {
            $maxReferralNumber = $this->getMaxReferralLimitNumber($commissionTypeId);
        } catch (Gpf_DbEngine_NoRowException $e) { 
            $context->debug('MaxCommission limit per referral is not defined. Ended.');
            return;
        }

        if ($maxReferralNumber == '' || $maxReferralNumber <= -1) {
            $context->debug('MaxCommission limit is not set.');
            return;
        }

        try {
            $maxReferralTimePeriod = $this->getMaxReferralLimitTimePeriod($commissionTypeId);
        } catch (Gpf_DbEngine_NoRowException $e) {
            $maxReferralTimePeriod = -1;
        }

        $numberOfCommission = $this->getNumberOfAllTransactionPerClickCommission($context->getUserObject()->getId(), $commissionTypeId, $maxReferralTimePeriod);
        if ($numberOfCommission < $maxReferralNumber) {
            $context->debug('MaxCommission per referral limit is not full ('.$numberOfCommission.'/ '.$maxReferralNumber.'). Saved. Ended.');
            return;
        }

        $context->setDoCommissionsSave(false);
        $context->debug('MaxCommission per referral is full (' . $numberOfCommission . '). Commission will be NOT SAVED. Ended.');
    }
    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");
    }
 /**
  * @return Pap_Db_Channel
  * @throws Gpf_Exception
  */
 private function getChannelFromParameter(Pap_Contexts_Click $context) {
     $context->debug('Trying to get channel from parameter');
     return $this->getChannelById($context, $context->getChannelId());
 }