diff --git a/MatomoTracker.php b/MatomoTracker.php index 0e4f41b..91461cf 100644 --- a/MatomoTracker.php +++ b/MatomoTracker.php @@ -223,7 +223,8 @@ public function __construct(int $idSite, string $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; @@ -593,6 +594,8 @@ public function setUserAgent(string $userAgent) * or an array containing 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 */ @@ -601,7 +604,8 @@ public function setClientHints( string $platform = '', string $platformVersion = '', $fullVersionList = '', - string $uaFullVersion = '' + string $uaFullVersion = '', + $formFactors = '' ) { if (is_string($fullVersionList)) { $reg = '/^"([^"]+)"; ?v="([^"]+)"(?:, )?/'; @@ -617,12 +621,25 @@ public function setClientHints( $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; @@ -810,7 +827,7 @@ public function doTrackPageView(string $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).