https://github.com/dotkernel/dot-user-agent-sniffer
DotKernel component providing details about a device by parsing a user agent.
https://github.com/dotkernel/dot-user-agent-sniffer
Last synced: about 2 months ago
JSON representation
DotKernel component providing details about a device by parsing a user agent.
- Host: GitHub
- URL: https://github.com/dotkernel/dot-user-agent-sniffer
- Owner: dotkernel
- License: gpl-3.0
- Created: 2019-11-14T11:36:07.000Z (over 5 years ago)
- Default Branch: 3.0
- Last Pushed: 2025-02-21T10:18:01.000Z (4 months ago)
- Last Synced: 2025-04-25T05:38:04.794Z (2 months ago)
- Language: PHP
- Homepage: https://docs.dotkernel.org/dot-user-agent-sniffer/
- Size: 125 KB
- Stars: 3
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# dot-user-agent-sniffer
Dotkernel component based on matomo/device-detector, providing details about a device by parsing a user agent.
> `dotkernel/dot-user-agent-sniffer` is a wrapper on top of [matomo/device-detector](https://github.com/matomo-org/device-detector)
## Documentation
Documentation is available at: https://docs.dotkernel.org/dot-user-agent-sniffer/.
## Badges

[](https://github.com/dotkernel/dot-user-agent-sniffer/issues)
[](https://github.com/dotkernel/dot-user-agent-sniffer/network)
[](https://github.com/dotkernel/dot-user-agent-sniffer/stargazers)
[](https://github.com/dotkernel/dot-user-agent-sniffer/blob/3.0/LICENSE)[](https://github.com/dotkernel/dot-user-agent-sniffer/actions/workflows/continuous-integration.yml)
[](https://codecov.io/gh/dotkernel/dot-user-agent-sniffer)
[](https://github.com/dotkernel/dot-user-agent-sniffer/actions/workflows/static-analysis.yml)## Install
You can install this library by running the following command:
```shell
composer require dotkernel/dot-user-agent-sniffer
```Before adding this library as a dependency to your service, you need to add `Dot\UserAgentSniffer\ConfigProvider::class,` to your application's `config/config.php` file.
## Usage example
```php
deviceService = $deviceService;
}/**
* @param string $userAgent
* @return DeviceData
*/
public function myMethod(string $userAgent)
{
return $this->deviceService->getDetails($userAgent);
}
}
```When called with an `$userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/78.0.3904.84 Mobile/15E148 Safari/604.1'`, `myMethod($userAgent)` returns an object with the following structure:
```php
Dot\UserAgentSniffer\Data\DeviceData::__set_state(array(
'type' => 'smartphone',
'brand' => 'Apple',
'model' => 'iPhone',
'isBot' => false,
'isMobile' => true,
'os' =>
Dot\UserAgentSniffer\Data\OsData::__set_state(array(
'name' => 'iOS',
'version' => '13.2',
'platform' => '',
)),
'client' =>
Dot\UserAgentSniffer\Data\ClientData::__set_state(array(
'type' => 'browser',
'name' => 'Chrome Mobile iOS',
'engine' => 'WebKit',
'version' => '78.0',
)),
))
```The above call can also be chained as `myMethod($userAgent)->getArrayCopy()`, to retrieve the details as an array:
```php
array (
'type' => 'smartphone',
'brand' => 'Apple',
'model' => 'iPhone',
'isMobile' => true,
'isBot' => false,
'os' =>
array (
'name' => 'iOS',
'version' => '13.2',
'platform' => '',
),
'client' =>
array (
'type' => 'browser',
'name' => 'Chrome Mobile iOS',
'engine' => 'WebKit',
'version' => '78.0',
),
)
```