Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting form factors client hint #136

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
sgiehl marked this conversation as resolved.
Show resolved Hide resolved
]);

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