Skip to content

Commit

Permalink
Fix various problems related to GDPR tools (#22975)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl authored Jan 24, 2025
1 parent b512927 commit 13b46eb
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 58 deletions.
6 changes: 5 additions & 1 deletion plugins/API/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,11 @@ public function getSuggestedValuesForSegment($segmentName, $idSite)
$suggestedValuesCallbackRequiresTable = false;

if (!empty($segment['suggestedValuesApi']) && is_string($segment['suggestedValuesApi']) && !Rules::isBrowserTriggerEnabled()) {
$now = Date::now()->setTimezone(Site::getTimezoneFor($idSite));
if ($idSite === 'all') {
$now = Date::now()->setTimezone(\Piwik\Plugins\SitesManager\API::getInstance()->getDefaultTimezone());
} else {
$now = Date::now()->setTimezone(Site::getTimezoneFor($idSite));
}
if (self::$_autoSuggestLookBack != 60) {
// in Auto suggest tests we need to assume now is in 2018...
// we do - 20 to make sure the year is still correct otherwise could end up being 2017-12-31 and the recorded visits are over several days in the tests we make sure to select the last day a visit was recorded
Expand Down
2 changes: 1 addition & 1 deletion plugins/CoreHome/Columns/UserId.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct()
public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory)
{
// Configure userId segment only if visitor profile is available
if (Live::isVisitorProfileEnabled() || \Piwik\API\Request::getRootApiRequestMethod() === 'API.getSegmentsMetadata') {
if (Live::isVisitorProfileEnabled()) {
parent::configureSegments($segmentsList, $dimensionSegmentFactory);
}
}
Expand Down
12 changes: 12 additions & 0 deletions plugins/Live/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ public function getVisitorProfile($idSite, $visitorId = false, $segment = false,
return $result;
}

/**
* Returns if the visitor profile is enabled for the given site(s))
*
* @param string|int|array $idSite
* @return bool
* @internal
*/
public function isVisitorProfileEnabled($idSite): bool
{
return Live::isVisitorProfileEnabled($idSite);
}

/**
* Returns the visitor ID of the most recent visit.
*
Expand Down
9 changes: 5 additions & 4 deletions plugins/Live/Live.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Piwik\API\Request;
use Piwik\Common;
use Piwik\Container\StaticContainer;
use Piwik\Site;

/**
*
Expand Down Expand Up @@ -68,11 +69,11 @@ public static function checkIsVisitorLogEnabled($idSite = null): void
}

if (empty($idSite)) {
$idSite = Common::getRequestVar('idSite', 0, 'int');
$idSite = Common::getRequestVar('idSite', '', 'string');
}

if (!empty($idSite)) {
$idSites = is_array($idSite) ? $idSite : [$idSite];
$idSites = Site::getIdSitesFromIdSitesString($idSite);

foreach ($idSites as $idSite) {
$settings = new MeasurableSettings($idSite);
Expand Down Expand Up @@ -117,11 +118,11 @@ public static function checkIsVisitorProfileEnabled($idSite = null): void
}

if (empty($idSite)) {
$idSite = Common::getRequestVar('idSite', 0, 'int');
$idSite = Common::getRequestVar('idSite', '', 'string');
}

if (!empty($idSite)) {
$idSites = is_array($idSite) ? $idSite : [$idSite];
$idSites = Site::getIdSitesFromIdSitesString($idSite);

foreach ($idSites as $idSite) {
$settings = new MeasurableSettings($idSite);
Expand Down
43 changes: 31 additions & 12 deletions plugins/Live/javascripts/visitorProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,46 @@
* @param {String} idSite The ID of the site.
*/
VisitorProfileControl.showPopover = function (visitorId, idSite) {

if (!piwik.visitorProfileEnabled) {
var showProfile = function(visitorId, idSite, visitorProfileEnabled) {
if (!piwik.visitorProfileEnabled && (!idSite || piwik.idSite == idSite)) {
console.error('Visitor Profile was disabled in website settings');
return;
}
}

var url = 'module=Live&action=getVisitorProfilePopup&visitorId=' + encodeURIComponent(visitorId);
if (idSite) {
var url = 'module=Live&action=getVisitorProfilePopup&visitorId=' + encodeURIComponent(visitorId);
if (idSite) {
url += '&idSite=' + idSite;
}
}

// if there is already a map shown on the screen, do not show the map in the popup. kartograph seems
// to only support showing one map at a time.
if ($('.RealTimeMap').length > 0) {
// if there is already a map shown on the screen, do not show the map in the popup. kartograph seems
// to only support showing one map at a time.
if ($('.RealTimeMap').length > 0) {
url += '&showMap=0';
}

var ajaxRequest = new ajaxHelper();
ajaxRequest.removeDefaultParameter('segment');

Piwik_Popover.createPopupAndLoadUrl(url, _pk_translate('Live_VisitorProfile'), 'visitor-profile-popup', ajaxRequest);
}

if (idSite && idSite != piwik.idSite) {
var ajax = new ajaxHelper();
ajax.addParams({
module: 'API',
method: 'Live.isVisitorProfileEnabled',
format: 'json',
idSite: idSite
}, 'GET');
ajax.setCallback(function (response) {
showProfile(visitorId, idSite, response && response.value);
});
ajax.send();
} else {
showProfile(visitorId, idSite, piwik.visitorProfileEnabled);
}

var ajaxRequest = new ajaxHelper();
ajaxRequest.removeDefaultParameter('segment');

Piwik_Popover.createPopupAndLoadUrl(url, _pk_translate('Live_VisitorProfile'), 'visitor-profile-popup', ajaxRequest);
};

$.extend(VisitorProfileControl.prototype, UIControl.prototype, {
Expand Down
Loading

0 comments on commit 13b46eb

Please sign in to comment.