コード例 #1
0
ファイル: Controller.php プロジェクト: nnnnathann/piwik
 function index()
 {
     Piwik::checkUserIsNotAnonymous();
     $view = Piwik_View::factory('Settings');
     $view->isSuperUser = Piwik::isUserIsSuperUser();
     $mobileMessagingAPI = Piwik_MobileMessaging_API::getInstance();
     $view->delegatedManagement = $mobileMessagingAPI->getDelegatedManagement();
     $view->credentialSupplied = $mobileMessagingAPI->areSMSAPICredentialProvided();
     $view->accountManagedByCurrentUser = $view->isSuperUser || $view->delegatedManagement;
     $view->strHelpAddPhone = Piwik_Translate('MobileMessaging_Settings_PhoneNumbers_HelpAdd', array(Piwik_Translate('UserSettings_SubmenuSettings'), Piwik_Translate('MobileMessaging_SettingsMenu')));
     if ($view->credentialSupplied && $view->accountManagedByCurrentUser) {
         $view->provider = $mobileMessagingAPI->getSMSProvider();
         $view->creditLeft = $mobileMessagingAPI->getCreditLeft();
     }
     $view->smsProviders = Piwik_MobileMessaging_SMSProvider::$availableSMSProviders;
     // construct the list of countries from the lang files
     $countries = array();
     foreach (Piwik_Common::getCountriesList() as $countryCode => $continentCode) {
         if (isset(Piwik_MobileMessaging_CountryCallingCodes::$countryCallingCodes[$countryCode])) {
             $countries[$countryCode] = array('countryName' => Piwik_CountryTranslate($countryCode), 'countryCallingCode' => Piwik_MobileMessaging_CountryCallingCodes::$countryCallingCodes[$countryCode]);
         }
     }
     $view->countries = $countries;
     $view->defaultCountry = Piwik_Common::getCountry(Piwik_LanguagesManager::getLanguageCodeForCurrentUser(), true, Piwik_IP::getIpFromHeader());
     $view->phoneNumbers = $mobileMessagingAPI->getPhoneNumbers();
     $this->setBasicVariablesView($view);
     $view->menu = Piwik_GetAdminMenu();
     echo $view->render();
 }
コード例 #2
0
ファイル: Default.php プロジェクト: nomoto-ubicast/piwik
 /**
  * Guesses a visitor's location using a visitor's browser language.
  * 
  * @param array $info Contains 'ip' & 'lang' keys.
  * @return array Contains the guessed country code mapped to LocationProvider::COUNTRY_CODE_KEY.
  */
 public function getLocation($info)
 {
     $enableLanguageToCountryGuess = Piwik_Config::getInstance()->Tracker['enable_language_to_country_guess'];
     $country = Piwik_Common::getCountry($info['lang'], $enableLanguageToCountryGuess, $info['ip']);
     $location = array(parent::COUNTRY_CODE_KEY => $country);
     $this->completeLocationResult($location);
     return $location;
 }
コード例 #3
0
ファイル: GoalManager.php プロジェクト: klando/pgpiwik
 function recordGoals($visitorInformation, $action)
 {
     $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'], 'location_country' => $location_country, 'location_continent' => $location_continent, '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->convertedGoals as $convertedGoal) {
         printDebug("- Goal " . $convertedGoal['idgoal'] . " matched. Recording...");
         $newGoal = $goal;
         $newGoal['idgoal'] = $convertedGoal['idgoal'];
         $newGoal['url'] = $convertedGoal['url'];
         $newGoal['revenue'] = $convertedGoal['revenue'];
         if (!is_null($action)) {
             $newGoal['idaction'] = $action->getIdAction();
             $newGoal['idlink_va'] = $action->getIdLinkVisitAction();
         }
         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();
     }
 }
コード例 #4
0
ファイル: GoalManager.php プロジェクト: nomoto-ubicast/piwik
 /**
  * Records one or several goals matched in this request.
  * @param int $idSite
  * @param array $visitorInformation
  * @param array $visitCustomVariables
  * @param string $action
  * @param $referrerTimestamp
  * @param string $referrerUrl
  * @param string $referrerCampaignName
  * @param string $referrerCampaignKeyword
  */
 public function recordGoals($idSite, $visitorInformation, $visitCustomVariables, $action, $referrerTimestamp, $referrerUrl, $referrerCampaignName, $referrerCampaignKeyword, $browserLanguage)
 {
     $location_country = isset($visitorInformation['location_country']) ? $visitorInformation['location_country'] : Piwik_Common::getCountry($browserLanguage, $enableLanguageToCountryGuess = Piwik_Config::getInstance()->Tracker['enable_language_to_country_guess'], $visitorInformation['location_ip']);
     $goal = array('idvisit' => $visitorInformation['idvisit'], 'idsite' => $idSite, 'idvisitor' => $visitorInformation['idvisitor'], 'server_time' => Piwik_Tracker::getDatetimeFromTimestamp($visitorInformation['visit_last_action_time']), 'location_country' => $location_country, 'visitor_returning' => $visitorInformation['visitor_returning'], 'visitor_days_since_first' => $visitorInformation['visitor_days_since_first'], 'visitor_days_since_order' => $visitorInformation['visitor_days_since_order'], 'visitor_count_visits' => $visitorInformation['visitor_count_visits']);
     $extraLocationCols = array('location_region', 'location_city', 'location_latitude', 'location_longitude');
     foreach ($extraLocationCols as $col) {
         if (isset($visitorInformation[$col])) {
             $goal[$col] = $visitorInformation[$col];
         }
     }
     // Copy Custom Variables from Visit row to the Goal conversion
     for ($i = 1; $i <= Piwik_Tracker::MAX_CUSTOM_VARIABLES; $i++) {
         if (isset($visitorInformation['custom_var_k' . $i]) && strlen($visitorInformation['custom_var_k' . $i])) {
             $goal['custom_var_k' . $i] = $visitorInformation['custom_var_k' . $i];
         }
         if (isset($visitorInformation['custom_var_v' . $i]) && strlen($visitorInformation['custom_var_v' . $i])) {
             $goal['custom_var_v' . $i] = $visitorInformation['custom_var_v' . $i];
         }
     }
     // Otherwise, set the Custom Variables found in the cookie sent with this request
     $goal += $visitCustomVariables;
     // Attributing the correct Referrer to this conversion.
     // Priority order is as follows:
     // 0) In some cases, the campaign is not passed from the JS so we look it up from the current visit
     // 1) Campaign name/kwd parsed in the JS
     // 2) Referrer URL stored in the _ref cookie
     // 3) If no info from the cookie, attribute to the current visit referrer
     // 3) Default values: current referrer
     $type = $visitorInformation['referer_type'];
     $name = $visitorInformation['referer_name'];
     $keyword = $visitorInformation['referer_keyword'];
     $time = $visitorInformation['visit_first_action_time'];
     // 0) In some (unknown!?) cases the campaign is not found in the attribution cookie, but the URL ref was found.
     //    In this case we look up if the current visit is credited to a campaign and will credit this campaign rather than the URL ref (since campaigns have higher priority)
     if (empty($refererCampaignName) && $type == Piwik_Common::REFERER_TYPE_CAMPAIGN && !empty($name)) {
         // Use default values per above
     } elseif (!empty($referrerCampaignName)) {
         $type = Piwik_Common::REFERER_TYPE_CAMPAIGN;
         $name = $referrerCampaignName;
         $keyword = $referrerCampaignKeyword;
         $time = $referrerTimestamp;
     } elseif (!empty($referrerUrl)) {
         $referrer = new Piwik_Tracker_Visit_Referer();
         $referrer = $referrer->getRefererInformation($referrerUrl, $currentUrl = '', $idSite);
         // if the parsed referer is interesting enough, ie. website or search engine
         if (in_array($referrer['referer_type'], array(Piwik_Common::REFERER_TYPE_SEARCH_ENGINE, Piwik_Common::REFERER_TYPE_WEBSITE))) {
             $type = $referrer['referer_type'];
             $name = $referrer['referer_name'];
             $keyword = $referrer['referer_keyword'];
             $time = $referrerTimestamp;
         }
     }
     $goal += array('referer_type' => $type, 'referer_name' => $name, 'referer_keyword' => $keyword, 'referer_visit_server_date' => date("Y-m-d", $time));
     // some goals are converted, so must be ecommerce Order or Cart Update
     if ($this->requestIsEcommerce) {
         $this->recordEcommerceGoal($goal, $visitorInformation);
     } else {
         $this->recordStandardGoals($goal, $action, $visitorInformation);
     }
 }
コード例 #5
0
ファイル: Visit.php プロジェクト: BackupTheBerlios/oos-svn
 /**
  * In the case of a new visit, we have to do the following actions:
  * 
  * 1) Insert the new action
  * 
  * 2) Insert the visit information
  */
 protected function handleNewVisit($actionId, $someGoalsConverted)
 {
     printDebug("New Visit.");
     $localTime = Piwik_Common::getRequestVar('h', $this->getCurrentDate("H"), 'numeric', $this->request) . ':' . Piwik_Common::getRequestVar('m', $this->getCurrentDate("i"), 'numeric', $this->request) . ':' . Piwik_Common::getRequestVar('s', $this->getCurrentDate("s"), 'numeric', $this->request);
     $serverTime = $this->getCurrentTimestamp();
     $serverDate = $this->getCurrentDate();
     $idcookie = $this->getVisitorIdcookie();
     $returningVisitor = $this->isVisitorKnown() ? 1 : 0;
     $defaultTimeOnePageVisit = Piwik_Tracker_Config::getInstance()->Tracker['default_time_one_page_visit'];
     $userInfo = $this->getUserSettingsInformation();
     $country = Piwik_Common::getCountry($userInfo['location_browser_lang'], $enableLanguageToCountryGuess = Piwik_Tracker_Config::getInstance()->Tracker['enable_language_to_country_guess']);
     $refererInfo = $this->getRefererInformation();
     // if the referer is Live! or Bing we check if the IP comes from microsoft
     // we don't count their cloak checks requests (which really is "Live referer spam") see #686
     if (in_array($refererInfo['referer_name'], array("Live", "Bing")) && preg_match('/^65\\.55/', long2ip($userInfo['location_ip']))) {
         throw new Piwik_Tracker_Visit_Excluded("Spam Live bot, go away, you're making me cry");
     }
     /**
      * Save the visitor
      */
     $this->visitorInfo = array('idsite' => $this->idsite, 'visitor_localtime' => $localTime, 'visitor_idcookie' => $idcookie, 'visitor_returning' => $returningVisitor, 'visit_first_action_time' => Piwik_Tracker::getDatetimeFromTimestamp($serverTime), 'visit_last_action_time' => Piwik_Tracker::getDatetimeFromTimestamp($serverTime), 'visit_server_date' => $serverDate, 'visit_entry_idaction' => $actionId, 'visit_exit_idaction' => $actionId, 'visit_total_actions' => 1, 'visit_total_time' => $defaultTimeOnePageVisit, 'visit_goal_converted' => $someGoalsConverted ? 1 : 0, 'referer_type' => $refererInfo['referer_type'], 'referer_name' => $refererInfo['referer_name'], 'referer_url' => $refererInfo['referer_url'], 'referer_keyword' => $refererInfo['referer_keyword'], 'config_md5config' => $userInfo['config_md5config'], 'config_os' => $userInfo['config_os'], 'config_browser_name' => $userInfo['config_browser_name'], 'config_browser_version' => $userInfo['config_browser_version'], 'config_resolution' => $userInfo['config_resolution'], 'config_pdf' => $userInfo['config_pdf'], 'config_flash' => $userInfo['config_flash'], 'config_java' => $userInfo['config_java'], 'config_director' => $userInfo['config_director'], 'config_quicktime' => $userInfo['config_quicktime'], 'config_realplayer' => $userInfo['config_realplayer'], 'config_windowsmedia' => $userInfo['config_windowsmedia'], 'config_gears' => $userInfo['config_gears'], 'config_silverlight' => $userInfo['config_silverlight'], 'config_cookie' => $userInfo['config_cookie'], 'location_ip' => $userInfo['location_ip'], 'location_browser_lang' => $userInfo['location_browser_lang'], 'location_country' => $country);
     Piwik_PostEvent('Tracker.newVisitorInformation', $this->visitorInfo);
     $this->saveVisitorInformation();
 }
コード例 #6
0
ファイル: Visit.php プロジェクト: ntulip/piwik
 /**
  * In the case of a new visit, we have to do the following actions:
  *
  * 1) Insert the new action
  *
  * 2) Insert the visit information
  */
 protected function handleNewVisit($actionId, $someGoalsConverted)
 {
     printDebug("New Visit.");
     $localTime = Piwik_Common::getRequestVar('h', $this->getCurrentDate("H"), 'int', $this->request) . ':' . Piwik_Common::getRequestVar('m', $this->getCurrentDate("i"), 'int', $this->request) . ':' . Piwik_Common::getRequestVar('s', $this->getCurrentDate("s"), 'int', $this->request);
     $serverTime = $this->getCurrentTimestamp();
     $serverDate = $this->getCurrentDate();
     $idcookie = $this->getVisitorIdcookie();
     $returningVisitor = $this->isVisitorKnown() ? 1 : 0;
     $defaultTimeOnePageVisit = Piwik_Tracker_Config::getInstance()->Tracker['default_time_one_page_visit'];
     $userInfo = $this->getUserSettingsInformation();
     $country = Piwik_Common::getCountry($userInfo['location_browser_lang'], $enableLanguageToCountryGuess = Piwik_Tracker_Config::getInstance()->Tracker['enable_language_to_country_guess']);
     $refererInfo = $this->getRefererInformation();
     /**
      * Save the visitor
      */
     $this->visitorInfo = array('idsite' => $this->idsite, 'visitor_localtime' => $localTime, 'visitor_idcookie' => $idcookie, 'visitor_returning' => $returningVisitor, 'visit_first_action_time' => Piwik_Tracker::getDatetimeFromTimestamp($serverTime), 'visit_last_action_time' => Piwik_Tracker::getDatetimeFromTimestamp($serverTime), 'visit_server_date' => $serverDate, 'visit_entry_idaction' => $actionId, 'visit_exit_idaction' => $actionId, 'visit_total_actions' => 1, 'visit_total_time' => $defaultTimeOnePageVisit, 'visit_goal_converted' => $someGoalsConverted ? 1 : 0, 'referer_type' => $refererInfo['referer_type'], 'referer_name' => $refererInfo['referer_name'], 'referer_url' => $refererInfo['referer_url'], 'referer_keyword' => $refererInfo['referer_keyword'], 'config_md5config' => $userInfo['config_md5config'], 'config_os' => $userInfo['config_os'], 'config_browser_name' => $userInfo['config_browser_name'], 'config_browser_version' => $userInfo['config_browser_version'], 'config_resolution' => $userInfo['config_resolution'], 'config_pdf' => $userInfo['config_pdf'], 'config_flash' => $userInfo['config_flash'], 'config_java' => $userInfo['config_java'], 'config_director' => $userInfo['config_director'], 'config_quicktime' => $userInfo['config_quicktime'], 'config_realplayer' => $userInfo['config_realplayer'], 'config_windowsmedia' => $userInfo['config_windowsmedia'], 'config_gears' => $userInfo['config_gears'], 'config_silverlight' => $userInfo['config_silverlight'], 'config_cookie' => $userInfo['config_cookie'], 'location_ip' => $userInfo['location_ip'], 'location_browser_lang' => $userInfo['location_browser_lang'], 'location_country' => $country);
     Piwik_PostEvent('Tracker.newVisitorInformation', $this->visitorInfo);
     $this->saveVisitorInformation();
 }
コード例 #7
0
ファイル: GoalManager.php プロジェクト: Gninety/Microweber
 function recordGoals($idSite, $visitorInformation, $visitCustomVariables, $action, $referrerTimestamp, $referrerUrl, $referrerCampaignName, $referrerCampaignKeyword)
 {
     $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'], $visitorInformation['location_ip']);
     $location_continent = isset($visitorInformation['location_continent']) ? $visitorInformation['location_continent'] : Piwik_Common::getContinent($location_country);
     $goal = array('idvisit' => $visitorInformation['idvisit'], 'idsite' => $idSite, 'idvisitor' => $visitorInformation['idvisitor'], 'server_time' => Piwik_Tracker::getDatetimeFromTimestamp($visitorInformation['visit_last_action_time']), 'location_country' => $location_country, 'location_continent' => $location_continent, 'visitor_returning' => $visitorInformation['visitor_returning'], 'visitor_days_since_first' => $visitorInformation['visitor_days_since_first'], 'visitor_count_visits' => $visitorInformation['visitor_count_visits']);
     // Attributing the correct Referrer to this conversion.
     // Priority order is as follows:
     // 1) Campaign name/kwd parsed in the JS
     // 2) Referrer URL stored in the _ref cookie
     // 3) If no info from the cookie, attribute to the current visit referrer
     // 3) Default values: current referrer
     $type = $visitorInformation['referer_type'];
     $name = $visitorInformation['referer_name'];
     $keyword = $visitorInformation['referer_keyword'];
     $time = $visitorInformation['visit_first_action_time'];
     // 1) Campaigns from 1st party cookie
     if (!empty($referrerCampaignName)) {
         $type = Piwik_Common::REFERER_TYPE_CAMPAIGN;
         $name = $referrerCampaignName;
         $keyword = $referrerCampaignKeyword;
         $time = $referrerTimestamp;
     } elseif (!empty($referrerUrl)) {
         $referrer = new Piwik_Tracker_Visit_Referer();
         $referrer = $referrer->getRefererInformation($referrerUrl, $currentUrl = '', $idSite);
         // if the parsed referer is interesting enough, ie. website or search engine
         if (in_array($referrer['referer_type'], array(Piwik_Common::REFERER_TYPE_SEARCH_ENGINE, Piwik_Common::REFERER_TYPE_WEBSITE))) {
             $type = $referrer['referer_type'];
             $name = $referrer['referer_name'];
             $keyword = $referrer['referer_keyword'];
             $time = $referrerTimestamp;
         }
     }
     $goal += array('referer_type' => $type, 'referer_name' => $name, 'referer_keyword' => $keyword, 'referer_visit_server_date' => date("Y-m-d", $time));
     $goal += $visitCustomVariables;
     foreach ($this->convertedGoals as $convertedGoal) {
         printDebug("- Goal " . $convertedGoal['idgoal'] . " matched. Recording...");
         $newGoal = $goal;
         $newGoal['idgoal'] = $convertedGoal['idgoal'];
         $newGoal['url'] = $convertedGoal['url'];
         $newGoal['revenue'] = $convertedGoal['revenue'];
         if (!is_null($action)) {
             $newGoal['idaction_url'] = $action->getIdActionUrl();
             $newGoal['idlink_va'] = $action->getIdLinkVisitAction();
         }
         // If multiple Goal conversions per visit, set a cache buster
         $newGoal['buster'] = $convertedGoal['allow_multiple'] == 0 ? '0' : $visitorInformation['visit_last_action_time'];
         $newGoalDebug = $newGoal;
         $newGoalDebug['idvisitor'] = bin2hex($newGoalDebug['idvisitor']);
         printDebug($newGoalDebug);
         $fields = implode(", ", array_keys($newGoal));
         $bindFields = substr(str_repeat("?,", count($newGoal)), 0, -1);
         $sql = "INSERT IGNORE INTO " . Piwik_Common::prefixTable('log_conversion') . "\t\n\t\t\t\t\t({$fields}) VALUES ({$bindFields}) ";
         $bind = array_values($newGoal);
         Piwik_Tracker::getDatabase()->query($sql, $bind);
     }
 }
コード例 #8
0
ファイル: Visit.php プロジェクト: nnnnathann/piwik
 /**
  * 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 $idActionUrl
  * @param $idActionName
  * @param $actionType
  * @param $visitIsConverted
  */
 protected function handleNewVisit($idActionUrl, $idActionName, $actionType, $visitIsConverted)
 {
     printDebug("New Visit (IP = " . Piwik_IP::N2P($this->getVisitorIp()) . ")");
     $localTimes = array('h' => (string) Piwik_Common::getRequestVar('h', $this->getCurrentDate("H"), 'int', $this->request), 'i' => (string) Piwik_Common::getRequestVar('m', $this->getCurrentDate("i"), 'int', $this->request), 's' => (string) Piwik_Common::getRequestVar('s', $this->getCurrentDate("s"), 'int', $this->request));
     foreach ($localTimes as $k => $time) {
         if (strlen($time) == 1) {
             $localTimes[$k] = '0' . $time;
         }
     }
     $localTime = $localTimes['h'] . ':' . $localTimes['i'] . ':' . $localTimes['s'];
     $idcookie = $this->getVisitorIdcookie();
     $defaultTimeOnePageVisit = Piwik_Config::getInstance()->Tracker['default_time_one_page_visit'];
     // Days since first visit
     $cookieFirstVisitTimestamp = Piwik_Common::getRequestVar('_idts', 0, 'int', $this->request);
     if (!$this->isTimestampValid($cookieFirstVisitTimestamp)) {
         $cookieFirstVisitTimestamp = $this->getCurrentTimestamp();
     }
     $daysSinceFirstVisit = round(($this->getCurrentTimestamp() - $cookieFirstVisitTimestamp) / 86400, $precision = 0);
     if ($daysSinceFirstVisit < 0) {
         $daysSinceFirstVisit = 0;
     }
     // Number of Visits
     $visitCount = Piwik_Common::getRequestVar('_idvc', 1, 'int', $this->request);
     if ($visitCount < 1) {
         $visitCount = 1;
     }
     // Days since last visit
     $daysSinceLastVisit = 0;
     $lastVisitTimestamp = Piwik_Common::getRequestVar('_viewts', 0, 'int', $this->request);
     if ($this->isTimestampValid($lastVisitTimestamp)) {
         $daysSinceLastVisit = round(($this->getCurrentTimestamp() - $lastVisitTimestamp) / 86400, $precision = 0);
         if ($daysSinceLastVisit < 0) {
             $daysSinceLastVisit = 0;
         }
     }
     $daysSinceLastOrder = 0;
     $isReturningCustomer = false;
     $lastOrderTimestamp = Piwik_Common::getRequestVar('_ects', 0, 'int', $this->request);
     if ($this->isTimestampValid($lastOrderTimestamp)) {
         $daysSinceLastOrder = round(($this->getCurrentTimestamp() - $lastOrderTimestamp) / 86400, $precision = 0);
         if ($daysSinceLastOrder < 0) {
             $daysSinceLastOrder = 0;
         }
         $isReturningCustomer = true;
     }
     // User settings
     $userInfo = $this->getUserSettingsInformation();
     $country = Piwik_Common::getCountry($userInfo['location_browser_lang'], $enableLanguageToCountryGuess = Piwik_Config::getInstance()->Tracker['enable_language_to_country_guess'], $this->getVisitorIp());
     // Referrer data
     $referrer = new Piwik_Tracker_Visit_Referer();
     $refererUrl = Piwik_Common::getRequestVar('urlref', '', 'string', $this->request);
     $currentUrl = Piwik_Common::getRequestVar('url', '', 'string', $this->request);
     $refererInfo = $referrer->getRefererInformation($refererUrl, $currentUrl, $this->idsite);
     /**
      * Save the visitor
      */
     $this->visitorInfo = array('idsite' => $this->idsite, 'visitor_localtime' => $localTime, 'idvisitor' => $idcookie, 'visitor_returning' => $isReturningCustomer ? 2 : ($visitCount > 1 || $this->isVisitorKnown() ? 1 : 0), 'visitor_count_visits' => $visitCount, 'visitor_days_since_last' => $daysSinceLastVisit, 'visitor_days_since_order' => $daysSinceLastOrder, 'visitor_days_since_first' => $daysSinceFirstVisit, 'visit_first_action_time' => Piwik_Tracker::getDatetimeFromTimestamp($this->getCurrentTimestamp()), 'visit_last_action_time' => Piwik_Tracker::getDatetimeFromTimestamp($this->getCurrentTimestamp()), 'visit_entry_idaction_url' => (int) $idActionUrl, 'visit_entry_idaction_name' => (int) $idActionName, 'visit_exit_idaction_url' => (int) $idActionUrl, 'visit_exit_idaction_name' => (int) $idActionName, 'visit_total_actions' => in_array($actionType, array(Piwik_Tracker_Action::TYPE_ACTION_URL, Piwik_Tracker_Action::TYPE_DOWNLOAD, Piwik_Tracker_Action::TYPE_OUTLINK)) ? 1 : 0, 'visit_total_time' => $defaultTimeOnePageVisit, 'visit_goal_converted' => $visitIsConverted ? 1 : 0, 'visit_goal_buyer' => $this->goalManager->getBuyerType(), 'referer_type' => $refererInfo['referer_type'], 'referer_name' => $refererInfo['referer_name'], 'referer_url' => $refererInfo['referer_url'], 'referer_keyword' => $refererInfo['referer_keyword'], 'config_id' => $userInfo['config_id'], 'config_os' => $userInfo['config_os'], 'config_browser_name' => $userInfo['config_browser_name'], 'config_browser_version' => $userInfo['config_browser_version'], 'config_resolution' => $userInfo['config_resolution'], 'config_pdf' => $userInfo['config_pdf'], 'config_flash' => $userInfo['config_flash'], 'config_java' => $userInfo['config_java'], 'config_director' => $userInfo['config_director'], 'config_quicktime' => $userInfo['config_quicktime'], 'config_realplayer' => $userInfo['config_realplayer'], 'config_windowsmedia' => $userInfo['config_windowsmedia'], 'config_gears' => $userInfo['config_gears'], 'config_silverlight' => $userInfo['config_silverlight'], 'config_cookie' => $userInfo['config_cookie'], 'location_ip' => $this->getVisitorIp(), 'location_browser_lang' => $userInfo['location_browser_lang'], 'location_country' => $country);
     // Add Custom variable key,value to the visitor array
     $this->visitorInfo = array_merge($this->visitorInfo, $this->visitorCustomVariables);
     Piwik_PostEvent('Tracker.newVisitorInformation', $this->visitorInfo);
     $debugVisitInfo = $this->visitorInfo;
     $debugVisitInfo['idvisitor'] = bin2hex($debugVisitInfo['idvisitor']);
     $debugVisitInfo['config_id'] = bin2hex($debugVisitInfo['config_id']);
     printDebug($debugVisitInfo);
     $this->saveVisitorInformation();
 }
コード例 #9
0
ファイル: Visit.php プロジェクト: Doluci/tomatocart
 /**
  * In the case of a new visit, we have to do the following actions:
  * 
  * 1) Insert the new action
  * 
  * 2) Insert the visit information
  */
 private function handleNewVisit()
 {
     printDebug("New Visit.");
     /**
      * Get the variables from the REQUEST 
      */
     // Configuration settings
     $userInfo = $this->getUserSettingsInformation();
     // General information
     $localTime = Piwik_Common::getRequestVar('h', $this->getCurrentDate("H"), 'numeric') . ':' . Piwik_Common::getRequestVar('m', $this->getCurrentDate("i"), 'numeric') . ':' . Piwik_Common::getRequestVar('s', $this->getCurrentDate("s"), 'numeric');
     $serverTime = $this->getCurrentTimestamp();
     $serverDate = $this->getCurrentDate();
     if ($this->isVisitorKnown()) {
         $idcookie = $this->visitorInfo['visitor_idcookie'];
         $returningVisitor = 1;
     } else {
         $idcookie = $this->getVisitorUniqueId();
         $returningVisitor = 0;
     }
     $defaultTimeOnePageVisit = Piwik_LogStats_Config::getInstance()->LogStats['default_time_one_page_visit'];
     // Location information
     $country = Piwik_Common::getCountry($userInfo['location_browser_lang']);
     $continent = Piwik_Common::getContinent($country);
     //Referer information
     $refererInfo = $this->getRefererInformation();
     /**
      * Init the action
      */
     $action = $this->getActionObject();
     $actionId = $action->getActionId();
     printDebug("idAction = {$actionId}");
     /**
      * Save the visitor
      */
     $informationToSave = array('idsite' => $this->idsite, 'visitor_localtime' => $localTime, 'visitor_idcookie' => $idcookie, 'visitor_returning' => $returningVisitor, 'visit_first_action_time' => $this->getDatetimeFromTimestamp($serverTime), 'visit_last_action_time' => $this->getDatetimeFromTimestamp($serverTime), 'visit_server_date' => $serverDate, 'visit_entry_idaction' => $actionId, 'visit_exit_idaction' => $actionId, 'visit_total_actions' => 1, 'visit_total_time' => $defaultTimeOnePageVisit, 'referer_type' => $refererInfo['referer_type'], 'referer_name' => $refererInfo['referer_name'], 'referer_url' => $refererInfo['referer_url'], 'referer_keyword' => $refererInfo['referer_keyword'], 'config_md5config' => $userInfo['config_md5config'], 'config_os' => $userInfo['config_os'], 'config_browser_name' => $userInfo['config_browser_name'], 'config_browser_version' => $userInfo['config_browser_version'], 'config_resolution' => $userInfo['config_resolution'], 'config_color_depth' => $userInfo['config_color_depth'], 'config_pdf' => $userInfo['config_pdf'], 'config_flash' => $userInfo['config_flash'], 'config_java' => $userInfo['config_java'], 'config_director' => $userInfo['config_director'], 'config_quicktime' => $userInfo['config_quicktime'], 'config_realplayer' => $userInfo['config_realplayer'], 'config_windowsmedia' => $userInfo['config_windowsmedia'], 'config_cookie' => $userInfo['config_cookie'], 'location_ip' => $userInfo['location_ip'], 'location_browser_lang' => $userInfo['location_browser_lang'], 'location_country' => $country, 'location_continent' => $continent);
     Piwik_PostEvent('LogStats.newVisitorInformation', $informationToSave);
     $fields = implode(", ", array_keys($informationToSave));
     $values = substr(str_repeat("?,", count($informationToSave)), 0, -1);
     $this->db->query("INSERT INTO " . $this->db->prefixTable('log_visit') . " ({$fields}) VALUES ({$values})", array_values($informationToSave));
     $idVisit = $this->db->lastInsertId();
     // Update the visitor information attribute with this information array
     $this->visitorInfo = $informationToSave;
     $this->visitorInfo['idvisit'] = $idVisit;
     // we have to save timestamp in the object properties, whereas mysql eats some other datetime format
     $this->visitorInfo['visit_first_action_time'] = $serverTime;
     $this->visitorInfo['visit_last_action_time'] = $serverTime;
     /**
      * Save the action
      */
     $action->record($idVisit, 0, 0);
 }
コード例 #10
0
	/**
	 * Records one or several goals matched in this request.
	 */
	public function recordGoals($idSite, $visitorInformation, $visitCustomVariables, $action, $referrerTimestamp, $referrerUrl, $referrerCampaignName, $referrerCampaignKeyword)
	{
		$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'], $visitorInformation['location_ip'] 
							);
							
		$location_continent = isset($visitorInformation['location_continent']) 
								? $visitorInformation['location_continent'] 
								: Piwik_Common::getContinent($location_country);

		$goal = array(
			'idvisit' 			=> $visitorInformation['idvisit'],
			'idsite' 			=> $idSite,
			'idvisitor' 		=> $visitorInformation['idvisitor'],
			'server_time' 		=> Piwik_Tracker::getDatetimeFromTimestamp($visitorInformation['visit_last_action_time']),
			'location_country'  => $location_country,
			'location_continent'=> $location_continent,
			'visitor_returning' => $visitorInformation['visitor_returning'],
			'visitor_days_since_first' => $visitorInformation['visitor_days_since_first'],
			'visitor_days_since_order' => $visitorInformation['visitor_days_since_order'],
			'visitor_count_visits' => $visitorInformation['visitor_count_visits'],
		
		);

		// Attributing the correct Referrer to this conversion. 
		// Priority order is as follows:
		// 1) Campaign name/kwd parsed in the JS
		// 2) Referrer URL stored in the _ref cookie
		// 3) If no info from the cookie, attribute to the current visit referrer
		
		// 3) Default values: current referrer
        $type = $visitorInformation['referer_type'];
        $name = $visitorInformation['referer_name'];
        $keyword = $visitorInformation['referer_keyword'];
        $time = $visitorInformation['visit_first_action_time'];
        
        // 1) Campaigns from 1st party cookie
		if(!empty($referrerCampaignName))
		{
			$type = Piwik_Common::REFERER_TYPE_CAMPAIGN;
			$name = $referrerCampaignName;
			$keyword = $referrerCampaignKeyword;
			$time = $referrerTimestamp;
		}
		// 2) Referrer URL parsing
		elseif(!empty($referrerUrl))
		{
			$referrer = new Piwik_Tracker_Visit_Referer();  
            $referrer = $referrer->getRefererInformation($referrerUrl, $currentUrl = '', $idSite);
            
            // if the parsed referer is interesting enough, ie. website or search engine 
            if(in_array($referrer['referer_type'], array(Piwik_Common::REFERER_TYPE_SEARCH_ENGINE, Piwik_Common::REFERER_TYPE_WEBSITE)))
            {
            	$type = $referrer['referer_type'];
            	$name = $referrer['referer_name'];
            	$keyword = $referrer['referer_keyword'];
				$time = $referrerTimestamp;
            }
		}
		$goal += array(
			'referer_type' 				=> $type,
			'referer_name' 				=> $name,
			'referer_keyword' 			=> $keyword,
			// this field is currently unused
			'referer_visit_server_date' => date("Y-m-d", $time),
		);

		$goal += $visitCustomVariables;
		
		// some goals are converted, so must be ecommerce Order or Cart Update 
		if($this->requestIsEcommerce)
		{
			$this->recordEcommerceGoal($goal, $visitorInformation);
		}
		else
		{
			$this->recordStandardGoals($goal, $action, $visitorInformation);
		}
	}