Skip to content

Commit

Permalink
Allow settting form factors client hint
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed Sep 3, 2024
1 parent 4fb8529 commit 7507825
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions MatomoTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string> $formFactors Value of the header 'HTTP_SEC_CH_UA_FORM_FACTORS'
* or an array containing all form factors with structure ["Desktop", "XR"]
*
* @return $this
*/
Expand All @@ -601,7 +604,8 @@ public function setClientHints(
string $platform = '',
string $platformVersion = '',
$fullVersionList = '',
string $uaFullVersion = ''
string $uaFullVersion = '',
$formFactors = ''
) {
if (is_string($fullVersionList)) {
$reg = '/^"([^"]+)"; ?v="([^"]+)"(?:, )?/';
Expand All @@ -617,12 +621,25 @@ public function setClientHints(
$fullVersionList = [];
}

if (is_string($formFactors)) {
$formFactors = explode(',', $formFactors);
$formFactors = 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;
Expand Down Expand Up @@ -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).
Expand Down

0 comments on commit 7507825

Please sign in to comment.