getBrowserLanguage() public method

Returns the language the visitor is viewing.
public getBrowserLanguage ( ) : string
return string browser language code, eg. "en-gb,en;q=0.5"
Example #1
0
 /**
  * @param Request $request
  * @param Visitor $visitor
  * @param Action|null $action
  * @return mixed
  */
 public function onNewVisit(Request $request, Visitor $visitor, $action)
 {
     $language = $request->getBrowserLanguage();
     if (empty($language)) {
         return '';
     }
     return substr($language, 0, 20);
 }
Example #2
0
 /**
  * Gets the UserSettings information and returns them in an array of name => value
  *
  * @return array
  */
 protected function getUserSettingsInformation()
 {
     // we already called this method before, simply returns the result
     if (is_array($this->userSettingsInformation)) {
         return $this->userSettingsInformation;
     }
     require_once PIWIK_INCLUDE_PATH . '/libs/UserAgentParser/UserAgentParser.php';
     list($plugin_Flash, $plugin_Java, $plugin_Director, $plugin_Quicktime, $plugin_RealPlayer, $plugin_PDF, $plugin_WindowsMedia, $plugin_Gears, $plugin_Silverlight, $plugin_Cookie) = $this->request->getPlugins();
     $resolution = $this->request->getParam('res');
     $userAgent = $this->request->getUserAgent();
     $aBrowserInfo = UserAgentParser::getBrowser($userAgent);
     $browserName = $aBrowserInfo !== false && $aBrowserInfo['id'] !== false ? $aBrowserInfo['id'] : 'UNK';
     $browserVersion = $aBrowserInfo !== false && $aBrowserInfo['version'] !== false ? $aBrowserInfo['version'] : '';
     $os = UserAgentParser::getOperatingSystem($userAgent);
     $os = $os === false ? 'UNK' : $os['id'];
     $browserLang = substr($this->request->getBrowserLanguage(), 0, 20);
     // limit the length of this string to match db
     $configurationHash = $this->getConfigHash($os, $browserName, $browserVersion, $plugin_Flash, $plugin_Java, $plugin_Director, $plugin_Quicktime, $plugin_RealPlayer, $plugin_PDF, $plugin_WindowsMedia, $plugin_Gears, $plugin_Silverlight, $plugin_Cookie, $this->getVisitorIp(), $browserLang);
     $this->userSettingsInformation = array('config_id' => $configurationHash, 'config_os' => $os, 'config_browser_name' => $browserName, 'config_browser_version' => $browserVersion, 'config_resolution' => $resolution, 'config_pdf' => $plugin_PDF, 'config_flash' => $plugin_Flash, 'config_java' => $plugin_Java, 'config_director' => $plugin_Director, 'config_quicktime' => $plugin_Quicktime, 'config_realplayer' => $plugin_RealPlayer, 'config_windowsmedia' => $plugin_WindowsMedia, 'config_gears' => $plugin_Gears, 'config_silverlight' => $plugin_Silverlight, 'config_cookie' => $plugin_Cookie, 'location_browser_lang' => $browserLang);
     return $this->userSettingsInformation;
 }
Example #3
0
 public function getConfigId(Request $request, $ipAddress)
 {
     list($plugin_Flash, $plugin_Java, $plugin_Director, $plugin_Quicktime, $plugin_RealPlayer, $plugin_PDF, $plugin_WindowsMedia, $plugin_Gears, $plugin_Silverlight, $plugin_Cookie) = $request->getPlugins();
     $userAgent = $request->getUserAgent();
     $deviceDetector = DeviceDetectorFactory::getInstance($userAgent);
     $aBrowserInfo = $deviceDetector->getClient();
     if ($aBrowserInfo['type'] != 'browser') {
         // for now only track browsers
         unset($aBrowserInfo);
     }
     $browserName = !empty($aBrowserInfo['short_name']) ? $aBrowserInfo['short_name'] : 'UNK';
     $browserVersion = !empty($aBrowserInfo['version']) ? $aBrowserInfo['version'] : '';
     if ($deviceDetector->isBot()) {
         $os = self::OS_BOT;
     } else {
         $os = $deviceDetector->getOS();
         $os = empty($os['short_name']) ? 'UNK' : $os['short_name'];
     }
     $browserLang = substr($request->getBrowserLanguage(), 0, 20);
     // limit the length of this string to match db
     return $this->getConfigHash($request, $os, $browserName, $browserVersion, $plugin_Flash, $plugin_Java, $plugin_Director, $plugin_Quicktime, $plugin_RealPlayer, $plugin_PDF, $plugin_WindowsMedia, $plugin_Gears, $plugin_Silverlight, $plugin_Cookie, $ipAddress, $browserLang);
 }
Example #4
0
 /**
  * @param Request $request
  * @param Visitor $visitor
  * @param Action|null $action
  * @return mixed
  */
 public function onNewVisit(Request $request, Visitor $visitor, $action)
 {
     return substr($request->getBrowserLanguage(), 0, 20);
 }
Example #5
0
 /**
  * Records one or several goals matched in this request.
  *
  * @param int $idSite
  * @param array $visitorInformation
  * @param array $visitCustomVariables
  * @param Action $action
  */
 public function recordGoals($idSite, $visitorInformation, $visitCustomVariables, $action)
 {
     $referrerTimestamp = $this->request->getParam('_refts');
     $referrerUrl = $this->request->getParam('_ref');
     $referrerCampaignName = trim(urldecode($this->request->getParam('_rcn')));
     $referrerCampaignKeyword = trim(urldecode($this->request->getParam('_rck')));
     $browserLanguage = $this->request->getBrowserLanguage();
     $location_country = isset($visitorInformation['location_country']) ? $visitorInformation['location_country'] : Common::getCountry($browserLanguage, $enableLanguageToCountryGuess = Config::getInstance()->Tracker['enable_language_to_country_guess'], $visitorInformation['location_ip']);
     $goal = array('idvisit' => $visitorInformation['idvisit'], 'idsite' => $idSite, 'idvisitor' => $visitorInformation['idvisitor'], 'server_time' => 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
     // Otherwise, set the Custom Variables found in the cookie sent with this request
     $goal += $visitCustomVariables;
     $maxCustomVariables = CustomVariables::getMaxCustomVariables();
     for ($i = 1; $i <= $maxCustomVariables; $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];
         }
     }
     // 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($referrerCampaignName) && $type == Common::REFERRER_TYPE_CAMPAIGN && !empty($name)) {
         // Use default values per above
     } elseif (!empty($referrerCampaignName)) {
         $type = Common::REFERRER_TYPE_CAMPAIGN;
         $name = $referrerCampaignName;
         $keyword = $referrerCampaignKeyword;
         $time = $referrerTimestamp;
     } elseif (!empty($referrerUrl)) {
         $referrer = new Referrer();
         $referrer = $referrer->getReferrerInformation($referrerUrl, $currentUrl = '', $idSite);
         // if the parsed referrer is interesting enough, ie. website or search engine
         if (in_array($referrer['referer_type'], array(Common::REFERRER_TYPE_SEARCH_ENGINE, Common::REFERRER_TYPE_WEBSITE))) {
             $type = $referrer['referer_type'];
             $name = $referrer['referer_name'];
             $keyword = $referrer['referer_keyword'];
             $time = $referrerTimestamp;
         }
     }
     $this->setCampaignValuesToLowercase($type, $name, $keyword);
     $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);
     }
 }
Example #6
0
 /**
  * @param Request $request
  * @param Visitor $visitor
  * @param Action|null $action
  * @return mixed
  */
 public function onNewVisit(Request $request, Visitor $visitor, $action)
 {
     return $this->getSingleLanguageFromAcceptedLanguages($request->getBrowserLanguage());
 }
Example #7
0
 /**
  * @param Request $request
  * @param Visitor $visitor
  * @param Action|null $action
  * @return mixed
  */
 public function onAnyGoalConversion(Request $request, Visitor $visitor, $action)
 {
     $country = $visitor->getVisitorColumn($this->columnName);
     if (isset($country) && false !== $country) {
         return $country;
     }
     $browserLanguage = $request->getBrowserLanguage();
     $enableLanguageToCountryGuess = Config::getInstance()->Tracker['enable_language_to_country_guess'];
     $locationIp = $visitor->getVisitorColumn('location_ip');
     $country = Common::getCountry($browserLanguage, $enableLanguageToCountryGuess, $locationIp);
     return $country;
 }
 private function getLocale(Visitor $visitor, Request $request)
 {
     return \Locale::acceptFromHttp($request->getBrowserLanguage());
 }