/** * In the case of a new visit, we have to do the following actions: * * 1) Insert the new action * * 2) Insert the visit information * * @param Action $action * @param bool $visitIsConverted */ protected function handleNewVisit($action, $visitIsConverted) { Common::printDebug("New Visit (IP = " . IP::N2P($this->getVisitorIp()) . ")"); $this->visitorInfo = $this->getNewVisitorInformation($action); // Add Custom variable key,value to the visitor array $this->visitorInfo = array_merge($this->visitorInfo, $this->visitorCustomVariables); $this->visitorInfo['visit_goal_converted'] = $visitIsConverted ? 1 : 0; $this->visitorInfo['referer_name'] = substr($this->visitorInfo['referer_name'], 0, 70); $this->visitorInfo['referer_keyword'] = substr($this->visitorInfo['referer_keyword'], 0, 255); $this->visitorInfo['config_resolution'] = substr($this->visitorInfo['config_resolution'], 0, 9); /** * Triggered before a new [visit entity](/guides/persistence-and-the-mysql-backend#visits) is persisted. * * This event can be used to modify the visit entity or add new information to it before it is persisted. * The UserCountry plugin, for example, uses this event to add location information for each visit. * * @param array &$visit The visit entity. Read [this](/guides/persistence-and-the-mysql-backend#visits) to see * what information it contains. * @param \Piwik\Tracker\Request $request An object describing the tracking request being processed. */ Piwik::postEvent('Tracker.newVisitorInformation', array(&$this->visitorInfo, $this->request)); $this->request->overrideLocation($this->visitorInfo); $this->printVisitorInformation(); $idVisit = $this->insertNewVisit($this->visitorInfo); $this->visitorInfo['idvisit'] = $idVisit; $this->visitorInfo['visit_first_action_time'] = $this->request->getCurrentTimestamp(); $this->visitorInfo['visit_last_action_time'] = $this->request->getCurrentTimestamp(); }