matomo-org / device-detector

The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.
http://devicedetector.net
GNU Lesser General Public License v3.0
2.9k stars 472 forks source link

$dd->getDeviceName() empty #7829

Closed jcerdan closed 23 hours ago

jcerdan commented 2 days ago

Hello,

sometimes $dd->getDeviceName() returns an empty string. DD detects it's not a bot, but device is empty.

What does that mean? Is it for real a human interaction?

I got the HTTP_USER_AGENT for one of those:

Mozilla/5.0 (iPhone; CPU iPhone OS 17_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/21G93 [FBAN/FBIOS;FBAV/479.1.0.33.109;FBBV/637241220;FBDV/iPhone15,2;FBMD/iPhone;FBSN/iOS;FBSV/17.6.1;FBSS/3;FBID/phone;FBLC/es_ES;FBOP/5;FBRV/639094949;IABMV/1]

Looks like FB app running on an iPhone...

regards

liviuconcioiu commented 2 days ago

HI @jcerdan! This is indeed the Facebook app running on iPhone 14 Pro, and is a human interaction.

In this case, device should have been a phablet. I think you are running an outdated version of Matomo or device-detector. Detection is working as expected:

-
  user_agent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/21G93 [FBAN/FBIOS;FBAV/479.1.0.33.109;FBBV/637241220;FBDV/iPhone15,2;FBMD/iPhone;FBSN/iOS;FBSV/17.6.1;FBSS/3;FBID/phone;FBLC/es_ES;FBOP/5;FBRV/639094949;IABMV/1]'
  os:
    name: iOS
    version: 17.6.1
    platform: ""
  client:
    type: mobile app
    name: Facebook
    version: 479.1.0.33.109
  device:
    type: phablet
    brand: Apple
    model: iPhone 14 Pro
  os_family: iOS
  browser_family: Unknown
jcerdan commented 2 days ago

Hi @liviuconcioiu ,

I'm running version 6.4.0. I have tested the user agent there: https://devicedetector.lw1.at

and I get

{
  "isBot": false,
  "clientInfo": {
    "type": "mobile app",
    "name": "Facebook",
    "version": "479.1.0.33.109"
  },
  "browserFamily": null,
  "isMobileOnlyBrowser": false,
  "osInfo": {
    "name": "iOS",
    "short_name": "IOS",
    "version": "17.6.1",
    "platform": "",
    "family": "iOS"
  },
  "osFamily": "iOS",
  "device": null,
  "deviceName": "",
  "deviceBrand": {
    "name": "Apple",
    "short_name": "AP"
  },
  "model": "",
  "icons": {
    "browser": null,
    "os": "/icons/os/IOS.png",
    "device": null,
    "brand": "/icons/brand/Apple.png"
  },
  "clientHints": {
    "architecture": "",
    "bitness": "",
    "mobile": false,
    "model": "",
    "platform": "",
    "platformVersion": "",
    "uaFullVersion": "",
    "fullVersionList": {}
  },
  "headers": null
}

How do you get the info for device=phablet?

liviuconcioiu commented 2 days ago

I'm running version 6.4.0. I have tested the user agent there: https://devicedetector.lw1.at

How do you get the info for device=phablet?

There's a bug on the website (user agent is wrongly encoded), reported in https://github.com/Findus23/devicedetector.net/issues/4.

If you use the php code, detection works.

<?php

include_once 'path/to/spyc/Spyc.php';
include_once 'path/to/device-detector/autoload.php';

use DeviceDetector\ClientHints;
use DeviceDetector\DeviceDetector;
use DeviceDetector\Parser\Device\AbstractDeviceParser;

AbstractDeviceParser::setVersionTruncation(AbstractDeviceParser::VERSION_TRUNCATION_NONE);

$userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/21G93 [FBAN/FBIOS;FBAV/479.1.0.33.109;FBBV/637241220;FBDV/iPhone15,2;FBMD/iPhone;FBSN/iOS;FBSV/17.6.1;FBSS/3;FBID/phone;FBLC/es_ES;FBOP/5;FBRV/639094949;IABMV/1]';

$result = DeviceDetector::getInfoFromUserAgent($userAgent);

echo Spyc::YAMLDump($result, 2, 0);
jcerdan commented 2 days ago

I have checked commits. Looks like iOS improvement detection has been added after 6.4.0 release. I'll try to get package until last commit and see if that solves the problem. Thanks @liviuconcioiu

jcerdan commented 1 day ago

Hi, I have detected that $dd->getDevice() returns null if Client Hints are passed to DeviceDetector.

So this code returns a null value:

$clientHints = ClientHints::factory($_SERVER);
$dd = new DeviceDetector($userAgent, $clientHints);
$dd->discardBotInformation();
$dd->parse();
dump($dd->getDevice());

while the same without ClientHints return the correct device name.

Is that a bug?

liviuconcioiu commented 1 day ago

Is that a bug?

Yes, it is a bug. It was introduced in https://github.com/matomo-org/device-detector/pull/7807.

@sanchezzzhak can you look again at the code when you have time?

<?php

include_once 'path/to/spyc/Spyc.php';
include_once 'path/to/device-detector/autoload.php';

use DeviceDetector\ClientHints;
use DeviceDetector\DeviceDetector;
use DeviceDetector\Parser\Device\AbstractDeviceParser;

AbstractDeviceParser::setVersionTruncation(AbstractDeviceParser::VERSION_TRUNCATION_NONE);

$userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/21G93 [FBAN/FBIOS;FBAV/479.1.0.33.109;FBBV/637241220;FBDV/iPhone15,2;FBMD/iPhone;FBSN/iOS;FBSV/17.6.1;FBSS/3;FBID/phone;FBLC/es_ES;FBOP/5;FBRV/639094949;IABMV/1]';

$clientHints = ClientHints::factory([]);
$result = DeviceDetector::getInfoFromUserAgent($userAgent, $clientHints);

echo Spyc::YAMLDump($result, 2, 0);

This test should return

---
  user_agent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/21G93 [FBAN/FBIOS;FBAV/479.1.0.33.109;FBBV/637241220;FBDV/iPhone15,2;FBMD/iPhone;FBSN/iOS;FBSV/17.6.1;FBSS/3;FBID/phone;FBLC/es_ES;FBOP/5;FBRV/639094949;IABMV/1]'
  os:
    name: iOS
    version: 17.6.1
    platform: ""
  client:
    type: mobile app
    name: Facebook
    version: 479.1.0.33.109
  device:
    type: phablet
    brand: Apple
    model: iPhone 14 Pro
  os_family: iOS
  browser_family: Unknown

and not

---
user_agent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/21G93 [FBAN/FBIOS;FBAV/479.1.0.33.109;FBBV/637241220;FBDV/iPhone15,2;FBMD/iPhone;FBSN/iOS;FBSV/17.6.1;FBSS/3;FBID/phone;FBLC/es_ES;FBOP/5;FBRV/639094949;IABMV/1]'
os:
  name: iOS
  version: 17.6.1
  platform: ""
client:
  type: mobile app
  name: Facebook
  version: 479.1.0.33.109
device:
  type: ""
  brand: Apple
  model: ""
os_family: iOS
browser_family: Unknown
liviuconcioiu commented 1 day ago

@jcerdan you can check with my change, if you need it working right away, until the commit is merged.

Also, fyi you need to request the headers from browser like this, if you want to fully benefit from client hints detection. Some browsers don't send full headers, if aren't requsted.

<?php

header('Accept-CH: Sec-CH-UA, Sec-CH-UA-Mobile, Sec-CH-UA-Platform, Sec-CH-UA-Platform-Version, Sec-CH-UA-Full-Version, Sec-CH-UA-Full-Version-List, Sec-CH-UA-Arch, Sec-CH-UA-Model, Sec-CH-UA-Form-Factors, Sec-CH-UA-Bitness, Sec-CH-UA-WoW64');

...code...