Skip to content
This repository was archived by the owner on Apr 9, 2023. It is now read-only.

Commit d8f8b61

Browse files
committed
Improved detection of chrome
1 parent 9f40d7f commit d8f8b61

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

webanalytics.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,25 @@ class web_analytics {
175175
function analyse_user_agent($user_agent) {
176176
$result = array("browser" => array("name" => null, "version" => null), "os" => array("name" => null, "version" => null), "device" => array("name" => null));
177177
$gecko = false;
178-
if(preg_match("/Mozilla\/\d[\d.]* \([A-Za-z0-9_. ;:]*\) Gecko\/\d+/i", $user_agent)) {
178+
if(preg_match("/Mozilla\/\d[\d.]* \([A-Za-z0-9_.\- ;:\/]*\) Gecko\/\d+/i", $user_agent)) {
179179
$gecko = true;
180180
}
181181
$webkit = false;
182-
if(preg_match("/Mozilla\/\d.\d \([A-Za-z0-9_. ;:]*\) AppleWebKit\/\d[\d.]* \(KHTML, like Gecko\)/i", $user_agent)) {
182+
if(preg_match("/Mozilla\/\d[\d.]* \([A-Za-z0-9_.\- ;:\/]*\) AppleWebKit\/\d[\d.]* \(KHTML, like Gecko\)/i", $user_agent)) {
183183
$webkit = true;
184184
}
185185
$trident = false;
186186
if(preg_match_all("/\w+\/\d[\d.]*/", $user_agent, $matches)) {
187187
$browser = preg_split("/\//",$matches[0][array_key_last($matches[0])]);
188188
if($webkit) {
189-
if(preg_match("/safari/i", $browser[0]) && preg_match("/chrome/i", $user_agent)) {
189+
if(preg_match("/safari/i", $browser[0]) && (preg_match("/chrome/i", $user_agent) || preg_match("/crios/i", $user_agent))) {
190190
$browser = preg_split("/\//",$matches[0][2]);
191+
if(preg_match("/version/i", $browser[0])) {
192+
$browser = preg_split("/\//",$matches[0][3]);
193+
}
194+
if(!preg_match("/chrome/i", $browser[0])) {
195+
$browser[0] = "chrome";
196+
}
191197
}
192198
} else if(preg_match("/trident/i", $browser[0]) && !$gecko) {
193199
$trident = true;
@@ -235,6 +241,11 @@ function analyse_user_agent($user_agent) {
235241
$device = preg_split("/ build/i", $platforms[2]);
236242
$result["device"]["name"] = $device[0];
237243
}
244+
} else if(preg_match("/linux/i", $platforms[1])) {
245+
$os = preg_split("/ /",$platforms[1]);
246+
if(preg_match("/x11/i", $platforms[0])) {
247+
$result["device"]["name"] = "pc";
248+
}
238249
} else if(preg_match("/cros/i", $platforms[1])) {
239250
$os = preg_split("/ /",$platforms[1]);
240251
$result["device"]["name"] = "chromebook";

0 commit comments

Comments
 (0)