diff --git a/CHANGELOG.md b/CHANGELOG.md index 5afde19..02396e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ This is the Developer Changelog for Matomo PHP Tracker. All breaking changes or new features are listed below. +## Matomo PHP Tracker 3.3.2 +### Changed +- Support for formFactors client hint parameter, supported as of Matomo 5.2.0 + ## Matomo PHP Tracker 3.3.1 ### Fixed - closed curl connection diff --git a/MatomoTracker.php b/MatomoTracker.php index 234c6bf..d85807b 100644 --- a/MatomoTracker.php +++ b/MatomoTracker.php @@ -223,7 +223,8 @@ public function __construct($idSite, $apiUrl = '') !empty($_SERVER['HTTP_SEC_CH_UA_PLATFORM']) ? $_SERVER['HTTP_SEC_CH_UA_PLATFORM'] : '', !empty($_SERVER['HTTP_SEC_CH_UA_PLATFORM_VERSION']) ? $_SERVER['HTTP_SEC_CH_UA_PLATFORM_VERSION'] : '', !empty($_SERVER['HTTP_SEC_CH_UA_FULL_VERSION_LIST']) ? $_SERVER['HTTP_SEC_CH_UA_FULL_VERSION_LIST'] : '', - !empty($_SERVER['HTTP_SEC_CH_UA_FULL_VERSION']) ? $_SERVER['HTTP_SEC_CH_UA_FULL_VERSION'] : '' + !empty($_SERVER['HTTP_SEC_CH_UA_FULL_VERSION']) ? $_SERVER['HTTP_SEC_CH_UA_FULL_VERSION'] : '', + !empty($_SERVER['HTTP_SEC_CH_UA_FORM_FACTORS']) ? $_SERVER['HTTP_SEC_CH_UA_FORM_FACTORS'] : '' ); if (!empty($apiUrl)) { self::$URL = $apiUrl; @@ -574,10 +575,12 @@ public function setUserAgent($userAgent) * all brands with the structure * [['brand' => 'Chrome', 'version' => '10.0.2'], ['brand' => '...] * @param string $uaFullVersion Value of the header 'HTTP_SEC_CH_UA_FULL_VERSION' + * @param string|array $formFactors Value of the header 'HTTP_SEC_CH_UA_FORM_FACTORS' + * or an array containing all form factors with structure ["Desktop", "XR"] * * @return $this */ - public function setClientHints($model = '', $platform = '', $platformVersion = '', $fullVersionList = '', $uaFullVersion = '') + public function setClientHints($model = '', $platform = '', $platformVersion = '', $fullVersionList = '', $uaFullVersion = '', $formFactors = '') { if (is_string($fullVersionList)) { $reg = '/^"([^"]+)"; ?v="([^"]+)"(?:, )?/'; @@ -593,12 +596,25 @@ public function setClientHints($model = '', $platform = '', $platformVersion = ' $fullVersionList = []; } + if (is_string($formFactors)) { + $formFactors = explode(',', $formFactors); + $formFactors = array_filter(array_map( + function ($item) { + return trim($item, '" '); + }, + $formFactors + )); + } elseif (!is_array($formFactors)) { + $formFactors = []; + } + $this->clientHints = array_filter([ 'model' => $model, 'platform' => $platform, 'platformVersion' => $platformVersion, 'uaFullVersion' => $uaFullVersion, 'fullVersionList' => $fullVersionList, + 'formFactors' => $formFactors, ]); return $this; @@ -777,7 +793,7 @@ public function doTrackPageView($documentTitle) return $this->sendRequest($url); } - + /** * Override PageView id for every use of `doTrackPageView()`. Do not use this if you call `doTrackPageView()` * multiple times during tracking (if, for example, you are tracking a single page application). @@ -2021,7 +2037,7 @@ protected function sendRequest($url, $method = 'GET', $data = null, $force = fal curl_setopt_array($ch, $options); ob_start(); $response = @curl_exec($ch); - + try { $header = '';