Skip to content

Commit

Permalink
Allow setting form factors client hint (#136)
Browse files Browse the repository at this point in the history
* Allow settting form factors client hint

* update changelog

* Fix handling of some attributes

* Apply review feedback

Co-authored-by: Michal Kleiner <[email protected]>

---------

Co-authored-by: Michal Kleiner <[email protected]>
  • Loading branch information
sgiehl and michalkleiner authored Oct 9, 2024
1 parent 92c2ce6 commit 949259d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 20 additions & 4 deletions MatomoTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<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
*/
public function setClientHints($model = '', $platform = '', $platformVersion = '', $fullVersionList = '', $uaFullVersion = '')
public function setClientHints($model = '', $platform = '', $platformVersion = '', $fullVersionList = '', $uaFullVersion = '', $formFactors = '')
{
if (is_string($fullVersionList)) {
$reg = '/^"([^"]+)"; ?v="([^"]+)"(?:, )?/';
Expand All @@ -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;
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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 = '';

Expand Down

0 comments on commit 949259d

Please sign in to comment.