Location: PHPKode > projects > Stuffed Tracker - Web Traffic Monitoring & Analysis > stuffed-tracker-web-traffic-monitoring-analysis/actions/track.campaign.php
<?
if (!defined("NS_TRACKER_INDEX")) exit;
if (!defined("NS_PHP_TRACKING")) {
	$nsSelf=SELF;
	$nsSys=SYS;
    if (!defined("NS_DB_PFX")) define("NS_DB_PFX", PFX);
    if (!defined("NS_COOKIE_PFX")) define("NS_COOKIE_PFX", COOKIE_PFX);
    if (!defined("NS_TRACKING")) define("NS_TRACKING", true);
	$_NS_TRACK_VARS['QueryClass']="Query";
	$_NS_TRACK_VARS['Version']=$nsProduct->VERSION;
}
if (!defined("NS_TRACKER_DELAYED")) define("NS_TRACKER_DELAYED",false);

require_once $nsSelf."/lib/track/misc.func.php";
require_once $nsSelf."/lib/track/delayed.func.php";
require_once $nsSelf."/lib/track/general.func.php";
require_once $nsSelf."/lib/track/campaign.func.php";
require_once $nsSelf."/lib/track/visitor.func.php";
require_once $nsSelf."/lib/track/page.func.php";
require_once $nsSelf."/lib/track/referer.func.php";
require_once $nsSelf."/lib/track/action.func.php";
require_once $nsSelf."/lib/track/query.func.php";
require $nsSelf."/lib/track/define.vars.php";

$_NS_TRACK_VARS['Db']=&$Db;
$RequestType=4;
$TitleUpdate=false;

$Ref=NS_TRACK_MISC::ValidVar($_GP['ref'],NS_TRACK_MISC::ValidVar($_SERVER['HTTP_REFERER']));
$RUrl= NS_TRACK_MISC::V($_GP['rurl']);
if ($Version!=$TrackerVersion) return NS_TRACK_MISC::Redir($RUrl, 'Wrong tracker version');

$GetVars=&$_NS_TRACK_VARS['GetVars'];
$ClickSubId= NS_TRACK_MISC::V($_GP['cid']);
$StId= NS_TRACK_MISC::V($_GP['st']);
$StTextId=NS_TRACK_MISC::V($_GP['stext']); // Îáÿçàòåëüíûé àéäèøíèê ñàéòà
if (NS_TRACK_MISC::V($_COOKIE['ns_skip'])) $Skip=true;
if (!$RUrl) return NS_TRACK_MISC::Redir($_SERVER['HTTP_REFERER'], 'No redirect URL');
if (!NS_TRACK_MISC::ValidId($ClickSubId)) $Skip=true;

if ($Skip) return NS_TRACK_MISC::Redir($RUrl, 'No campaign id, or ignore cookie');

$Campaign=NS_TRACK_CAMPAIGN::GetCampaignById($ClickSubId);
if (!$Campaign) return NS_TRACK_MISC::Redir($RUrl, 'Campaign not found');

$Current=$RUrl;
//$Ref=NS_TRACK_MISC::V($_SERVER['HTTP_REFERER']);
// Ïîäãîòàâëèâàåì ìàññèâû òåêóùåãî ïóòè è ðåôåðåðà
$CurrentPageArr=NS_TRACK_GENERAL::PreparePathAddr($Current);
$RefPageArr=NS_TRACK_GENERAL::PreparePathAddr($Ref,'ref');
if (!$CurrentPageArr) return NS_TRACK_MISC::Redir($RUrl, 'No current page');
// Âûòàñêèâàåì òåêóùèé ñàéò è íàñòðîéêè
$Site=NS_TRACK_GENERAL::GetCurrentSite($StId,$StTextId);
if (!$Site) return NS_TRACK_MISC::Redir($RUrl, 'Site not found');
$CompanyId=$Site->COMPANY_ID; 
if (NS_TRACK_GENERAL::CheckStopTracking()) return NS_TRACK_MISC::Redir($RUrl, 'Tracking is stopped');

$Settings=NS_TRACK_MISC::GetSettings($CompanyId, $StId);

if (NS_TRACK_DELAYED::DelayedNeeded()) return NS_TRACK_DELAYED::WriteTempLog($RUrl);

$Item=&$_NS_TRACK_VARS['Item']; // ïðåäìåò äåéñòâèÿ
$KeepVisPath=NS_TRACK_MISC::SetsByPrior($Settings, "KEEP_VISITOR_PATH"); 
$KeepNoRef=NS_TRACK_MISC::SetsByPrior($Settings, "KEEP_NO_REF"); 
$NoDblPageLoad=NS_TRACK_MISC::SetsByPrior($Settings, "STOP_DBL_PAGE_LOAD"); // ïðåäîòâðàùåíèå äâîéíûõ êëèêîâ
$TimeDblPageLoad=NS_TRACK_MISC::TimeDblSettings($Settings, "STOP_DBL_PAGE_LOAD", "TIME_DBL_PAGE_LOAD"); 
$NoDblAdvClick=NS_TRACK_MISC::SetsByPrior($Settings, "STOP_DBL_ADV_CLICK"); // ïðåäîòâðàùåíèå äâîéíûõ êëèêîâ
$TimeDblAdvClick=NS_TRACK_MISC::TimeDblSettings($Settings, "STOP_DBL_ADV_CLICK", "TIME_DBL_ADV_CLICK"); 
$Actions=&$_NS_TRACK_VARS['Actions']; // ìàññèâ ñî ñïèñêîì id ñîâåðøåííûõ äåéñòâèé
$UpdateVisPath=false; // ïåðåêëþ÷àòåëü ñèãíàëèçèðóåò î òîì, ÷òî ïðîèçîøëî ñîáûòèå, êîòîðîå îáÿçàíî áûòü çàïèñàííûì â ïóòè ïî ñàéòó
$Fraud=&$_NS_TRACK_VARS['Fraud'];
$TimeDblPageLoad=&$_NS_TRACK_VARS['TimeDblPageLoad'];
$TimeDblAdvClick=&$_NS_TRACK_VARS['TimeDblAdvClick'];

$VarKw=NS_TRACK_MISC::V($Settings['All']->VAR_KW, "kw");
$VarKeyword=NS_TRACK_MISC::V($Settings['All']->VAR_KEYWORD, "k");


// Ïîëó÷àåì id ïîëüçîâàòåëÿ
$VisId=NS_TRACK_VISITOR::GetVisitorId();
// Åñëè áðàóçåð ïîëüçîâàòåëÿ çàáàíåí, òî âûêëþ÷àåìñÿ


if ($Skip)  return NS_TRACK_MISC::Redir($RUrl, 'No visitor or ignored visitor');

// ñîçäàåì ìàññèâ ñî ñïèñêîì õîñòîâ òåêóùåãî ñàéòà
$HostsArr=NS_TRACK_GENERAL::GetSiteHosts($StId, $Site);
$SiteHostId=NS_TRACK_GENERAL::CurrentSiteHost($HostsArr, $CurrentPageArr, $Site);
if (!$SiteHostId) $Skip=true;
if ($Skip) return NS_TRACK_MISC::Redir($RUrl, 'Site host not found');

// Óçíàåì id çàïðîøåííîé ñòðàíèöû
$PageId=NS_TRACK_PAGE::GetPageId($CurrentPageArr, $StId);
if ($Skip) return NS_TRACK_MISC::Redir($RUrl, 'Page not found or ignored');


// ñîçäàåì ìàññèâ ñ ïåðåìåííûìè çàïðîñà òåêóùåé ñòðàíèöû
$GetVars=NS_TRACK_QUERY::ParseTemplate(NS_TRACK_MISC::V($CurrentPageArr['query']));
$Skip=(NS_TRACK_MISC::ValidId($GetVars[NS_COOKIE_PFX.'skip']))?true:false; 
if ($Skip) return NS_TRACK_MISC::Redir($RUrl, 'Ingored by cookie');

$ReqArr=NS_TRACK_GENERAL::PreparePathAddr('http://'.$_SERVER['HTTP_HOST'].@$_SERVER['REQUEST_URI']);
$ReqVars=NS_TRACK_QUERY::ParseTemplate(NS_TRACK_MISC::V(@$ReqArr['query']));

$KeyId=(NS_TRACK_MISC::ValidId($_GP[$VarKeyword]))?$_GP[$VarKeyword]:0;
$Keyword=NS_TRACK_REFERER::FindReqKeyword($ReqVars,$VarKw);
if (!$Keyword) $Keyword=NS_TRACK_REFERER::FindReqKeyword($GetVars,$VarKw); 
if ($Keyword) $KeyId=NS_TRACK_REFERER::GetKeywordId($Keyword);

// Ïðîáóåì óçíàòü èëè ñîçäàòü referer set äëÿ ïóòè ïî ñàéòó
$RefSet=NS_TRACK_REFERER::GetRefererSet($RefPageArr, $Ref);
// äîñòàåì àéäèøíèê äëÿ ñòðîêè ïîñëå ?
$QueryId=NS_TRACK_QUERY::GetQueryId($CurrentPageArr['query']);
$PqId=NS_TRACK_PAGE::SetPage2QueryRelation();

//if (!$KeepNoRef&&$RefSet==0) $Skip=true;
if ($Skip) return NS_TRACK_MISC::Redir($RUrl, 'Ignored referer or ignored page');
if ($NoDblPageLoad) NS_TRACK_GENERAL::CheckPathDblClick();
if ($NoDblAdvClick) NS_TRACK_GENERAL::CheckAdvDblClick();
if ($Skip) return NS_TRACK_MISC::Redir($RUrl, 'Double click protection');
$Fraud=NS_TRACK_GENERAL::CheckClickFraud($Settings, $VisId, $ClickSubId);


// îáíîâëÿåì êëèêè
if (NS_TRACK_MISC::ValidId($ClickSubId)&&$ClickSubId>0) NS_TRACK_GENERAL::UpdateVisitorClick();
// åñëè íàäî, ïèøåì ïóòè ïî ñàéòó
if ($UpdateVisPath||$KeepVisPath) NS_TRACK_GENERAL::UpdateVisitorPath();
NS_TRACK_GENERAL::TrackingCookie(NS_COOKIE_PFX.'tmp_skip', md5(NS_TRACK_GENERAL::TmpCurrentPath($RUrl)), 0, '/', $_NS_TRACK_VARS['COOKIE_DOMAIN']);

if ($CookieLogSet && NS_TRACK_GENERAL::CheckTrackingMode()) $CookieLogSet=false;
if ($CookieLogSet) NS_TRACK_GENERAL::SetCookieLog();
if ($FindLastNode) NS_TRACK_VISITOR::FindLastNode($VisId);

if (defined("TRACK_ERRORS")&&TRACK_ERRORS &&  !defined("NS_PHP_TRACKING") && !NS_TRACKER_DELAYED) {
	$ResTime=NS_TRACK_MISC::GetMicrotime()-$StartTime;
	$Query = "INSERT INTO track_time (TRACK_TIME) VALUES ('$ResTime')";
	$Db->Query($Query);
	if (!empty($_SESSION['__Errors'])) foreach ($_SESSION['__Errors'] as $err) {
		$Db->Query("INSERT INTO track_error (ERROR) VALUES ('".addslashes($err)."')");
	}
}

return NS_TRACK_MISC::Redir($RUrl, 'Successfully tracked. :)');
?>
Return current item: Stuffed Tracker - Web Traffic Monitoring & Analysis