Пример #1
0
 function recordGoals($visitorInformation)
 {
     $location_country = isset($visitorInformation['location_country']) ? $visitorInformation['location_country'] : Piwik_Common::getCountry(Piwik_Common::getBrowserLanguage(), $enableLanguageToCountryGuess = Piwik_Tracker_Config::getInstance()->Tracker['enable_language_to_country_guess']);
     $location_continent = isset($visitorInformation['location_continent']) ? $visitorInformation['location_continent'] : Piwik_Common::getContinent($location_country);
     $goal = array('idvisit' => $visitorInformation['idvisit'], 'idsite' => $visitorInformation['idsite'], 'visitor_idcookie' => $visitorInformation['visitor_idcookie'], 'server_time' => Piwik_Tracker::getDatetimeFromTimestamp($visitorInformation['visit_last_action_time']), 'visit_server_date' => $visitorInformation['visit_server_date'], 'idaction' => $this->action->getIdAction(), 'idlink_va' => $this->action->getIdLinkVisitAction(), 'location_country' => $location_country, 'location_continent' => $location_continent, 'url' => $this->action->getActionUrl(), 'visitor_returning' => $this->cookie->get(Piwik_Tracker::COOKIE_INDEX_VISITOR_RETURNING));
     $referer_idvisit = $this->cookie->get(Piwik_Tracker::COOKIE_INDEX_REFERER_ID_VISIT);
     if ($referer_idvisit !== false) {
         $goal += array('referer_idvisit' => $referer_idvisit, 'referer_visit_server_date' => date("Y-m-d", $this->cookie->get(Piwik_Tracker::COOKIE_INDEX_REFERER_TIMESTAMP)), 'referer_type' => htmlspecialchars_decode($this->cookie->get(Piwik_Tracker::COOKIE_INDEX_REFERER_TYPE)), 'referer_name' => htmlspecialchars_decode($this->cookie->get(Piwik_Tracker::COOKIE_INDEX_REFERER_NAME)), 'referer_keyword' => htmlspecialchars_decode($this->cookie->get(Piwik_Tracker::COOKIE_INDEX_REFERER_KEYWORD)));
     }
     foreach ($this->matchedGoals as $matchedGoal) {
         printDebug("- Goal " . $matchedGoal['idgoal'] . " matched. Recording...");
         $newGoal = $goal;
         $newGoal['idgoal'] = $matchedGoal['idgoal'];
         $newGoal['revenue'] = $matchedGoal['revenue'];
         printDebug($newGoal);
         $fields = implode(", ", array_keys($newGoal));
         $bindFields = substr(str_repeat("?,", count($newGoal)), 0, -1);
         try {
             Piwik_Tracker::getDatabase()->query("INSERT INTO " . Piwik_Common::prefixTable('log_conversion') . "\t({$fields}) \n\t\t\t\t\tVALUES ({$bindFields}) ", array_values($newGoal));
         } catch (Exception $e) {
             if (strpos($e->getMessage(), '1062') !== false) {
                 // integrity violation when same visit converts to the same goal twice
                 printDebug("--> Goal already recorded for this (idvisit, idgoal)");
             } else {
                 throw $e;
             }
         }
         //$idlog_goal = Piwik_Tracker::getDatabase()->lastInsertId();
     }
 }