/** * @param Piwik_Event_Notification $notification notification object */ function checkHeader($notification) { if (isset($_SERVER['HTTP_X_DO_NOT_TRACK']) && $_SERVER['HTTP_X_DO_NOT_TRACK'] === '1' || isset($_SERVER['HTTP_DNT']) && substr($_SERVER['HTTP_DNT'], 0, 1) === '1') { $ua = Piwik_Tracker_Visit::getUserAgent($_REQUEST); if (strpos($ua, 'MSIE 10') !== false) { printDebug("INTERNET EXPLORER 10 Enables DNT by default, so Piwik ignores DNT for all IE10 browsers..."); return; } $exclude =& $notification->getNotificationObject(); $exclude = true; printDebug("DoNotTrack found."); $trackingCookie = Piwik_Tracker_IgnoreCookie::getTrackingCookie(); $trackingCookie->delete(); // this is an optional supplement to the site's tracking status resource at: // /.well-known/dnt // per Tracking Preference Expression (draft) header('Tk: 1'); } }
/** * Returns the Tracker_Visit object. * This method can be overwritten to use a different Tracker_Visit object * * @throws Exception * @return Piwik_Tracker_Visit */ protected function getNewVisitObject() { $visit = null; Piwik_PostEvent('Tracker.getNewVisitObject', $visit); if (is_null($visit)) { $visit = new Piwik_Tracker_Visit(self::$forcedIpString, self::$forcedDateTime); $visit->setForcedVisitorId(self::$forcedVisitorId); } elseif (!$visit instanceof Piwik_Tracker_Visit_Interface) { throw new Exception("The Visit object set in the plugin must implement Piwik_Tracker_Visit_Interface"); } return $visit; }
protected function updateCookie() { @parent::updateCookie(); }
/** * Records in the DB the association between the visit and this action. * * @param int idVisit is the ID of the current visit in the DB table log_visit * @param int idRefererActionUrl is the ID of the last action done by the current visit. * @param int timeSpentRefererAction is the number of seconds since the last action was done. * It is directly related to idRefererActionUrl. */ public function record( $idVisit, $visitorIdCookie, $idRefererActionUrl, $idRefererActionName, $timeSpentRefererAction) { $this->loadIdActionNameAndUrl(); $idActionName = in_array($this->getActionType(), array(Piwik_Tracker_Action::TYPE_ACTION_NAME, Piwik_Tracker_Action::TYPE_ACTION_URL)) ? (int)$this->getIdActionName() : null; $insert = array( 'idvisit' => $idVisit, 'idsite' => $this->idSite, 'idvisitor' => $visitorIdCookie, 'server_time' => Piwik_Tracker::getDatetimeFromTimestamp($this->timestamp), 'idaction_url' => (int)$this->getIdActionUrl(), 'idaction_name' => $idActionName, 'idaction_url_ref' => $idRefererActionUrl, 'idaction_name_ref' => $idRefererActionName, 'time_spent_ref_action' => $timeSpentRefererAction ); $customVariables = Piwik_Tracker_Visit::getCustomVariables($scope = 'page', $this->request); $insert = array_merge($insert, $customVariables); // Mysqli apparently does not like NULL inserts? $insertWithoutNulls = array(); foreach($insert as $column => $value) { if(!is_null($value)) { $insertWithoutNulls[$column] = $value; } } $fields = implode(", ", array_keys($insertWithoutNulls)); $bind = array_values($insertWithoutNulls); $values = Piwik_Common::getSqlStringFieldsArray($insertWithoutNulls); $sql = "INSERT INTO ".Piwik_Common::prefixTable('log_link_visit_action'). " ($fields) VALUES ($values)"; Piwik_Tracker::getDatabase()->query( $sql, $bind ); $this->idLinkVisitAction = Piwik_Tracker::getDatabase()->lastInsertId(); $info = array( 'idSite' => $this->idSite, 'idLinkVisitAction' => $this->idLinkVisitAction, 'idVisit' => $idVisit, 'idRefererActionUrl' => $idRefererActionUrl, 'idRefererActionName' => $idRefererActionName, 'timeSpentRefererAction' => $timeSpentRefererAction, ); printDebug($insertWithoutNulls); /* * send the Action object ($this) and the list of ids ($info) as arguments to the event */ Piwik_PostEvent('Tracker.Action.record', $this, $info); }
/** * We have previously tried to detect the campaign variables in the URL * so at this stage, if the referer host is the current host, * or if the referer host is any of the registered URL for this website, * it is considered a direct entry * @return bool */ protected function detectRefererDirectEntry() { if (!empty($this->refererHost)) { // is the referer host the current host? if (isset($this->currentUrlParse['host'])) { $currentHost = mb_strtolower($this->currentUrlParse['host'], 'UTF-8'); if ($currentHost == mb_strtolower($this->refererHost, 'UTF-8')) { $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_DIRECT_ENTRY; return true; } } if (Piwik_Tracker_Visit::isHostKnownAliasHost($this->refererHost, $this->idsite)) { $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_DIRECT_ENTRY; return true; } } return false; }
public function getCustomVariables() { $customVariables = Piwik_Tracker_Visit::getCustomVariables($scope = 'page', $this->request); // Enrich Site Search actions with Custom Variables, overwritting existing values if (!empty($this->searchCategory)) { if (!empty($customVariables['custom_var_k' . self::CVAR_INDEX_SEARCH_CATEGORY])) { printDebug("WARNING: Overwriting existing Custom Variable in slot " . self::CVAR_INDEX_SEARCH_CATEGORY . " for this page view"); } $customVariables['custom_var_k' . self::CVAR_INDEX_SEARCH_CATEGORY] = self::CVAR_KEY_SEARCH_CATEGORY; $customVariables['custom_var_v' . self::CVAR_INDEX_SEARCH_CATEGORY] = Piwik_Tracker_Visit::truncateCustomVariable($this->searchCategory); } if ($this->searchCount !== false) { if (!empty($customVariables['custom_var_k' . self::CVAR_INDEX_SEARCH_COUNT])) { printDebug("WARNING: Overwriting existing Custom Variable in slot " . self::CVAR_INDEX_SEARCH_COUNT . " for this page view"); } $customVariables['custom_var_k' . self::CVAR_INDEX_SEARCH_COUNT] = self::CVAR_KEY_SEARCH_COUNT; $customVariables['custom_var_v' . self::CVAR_INDEX_SEARCH_COUNT] = (int) $this->searchCount; } if (!empty($customVariables)) { printDebug("Page level Custom Variables: "); printDebug($customVariables); } return $customVariables; }