/** * 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); }
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; }