from user_agent import parse
user_agent_string = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
user_agent = parse(user_agent_string)
print(user_agent.device)
print(user_agent.os)
print(user_agent.browser)
const userAgent = navigator.userAgent;
const platform = navigator.platform;
console.log(userAgent);
console.log(platform);
Метод 3: библиотеки обнаружения устройств.
Некоторые библиотеки и платформы упрощают извлечение тегов устройств, предоставляя предварительно встроенные функции. Эти библиотеки часто имеют обширные базы данных устройств и регулярно обновляются. Популярными примерами являются WURFL и Mobile Detect. Вот как можно использовать Mobile Detect в PHP:
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
if ($detect->isMobile()) {
echo $detect->getMobileDeviceModel();
} elseif ($detect->isTablet()) {
echo $detect->getTabletDeviceModel();
} else {
echo "Desktop";
}
from google.oauth2.service_account import Credentials
from googleapiclient.discovery import build
credentials = Credentials.from_service_account_file('path/to/service_account.json')
analytics = build('analyticsreporting', 'v4', credentials=credentials)
response = analytics.reports().batchGet(
body={
'reportRequests': [
{
'viewId': '123456789',
'dateRanges': [{'startDate': '2022-01-01', 'endDate': '2022-01-31'}],
'metrics': [{'expression': 'ga:sessions'}],
'dimensions': [{'name': 'ga:deviceCategory'}, {'name': 'ga:operatingSystem'}],
}
]
}
).execute()
print(response)
Не забудьте реализовать соответствующую обработку ошибок и учитывать вопросы конфиденциальности при извлечении тегов устройств в ваших приложениях.