Skip to content

Commit

Permalink
Use https for urls in visitor details if host is defined with https i…
Browse files Browse the repository at this point in the history
…n site
  • Loading branch information
sgiehl committed Jan 27, 2021
1 parent c8959ca commit 1c44aad
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions plugins/Actions/VisitorDetails.php
Expand Up @@ -16,6 +16,7 @@
use Piwik\Piwik;
use Piwik\Plugin;
use Piwik\Plugins\Live\VisitorDetailsAbstract;
use Piwik\Plugins\SitesManager\API as APISitesManager;
use Piwik\Site;
use Piwik\Tracker\Action;
use Piwik\Tracker\PageUrl;
Expand Down Expand Up @@ -160,6 +161,12 @@ public function extendActionDetails(&$action, $nextAction, $visitorDetails)
unset($action['url_prefix']);
}

if (array_key_exists('url', $action) && preg_match('/^http:\/\/([^\/]+)\//i', $action['url'], $host)) {
if ($this->shouldUseHttpsHost($visitorDetails['idSite'], $host[1])) {
$action['url'] = 'https://' . substr($action['url'], 7);
}
}

switch ($action['type']) {
case 'goal':
$action['icon'] = 'plugins/Morpheus/images/goal.png';
Expand Down Expand Up @@ -252,6 +259,29 @@ public function extendActionDetails(&$action, $nextAction, $visitorDetails)
unset($action['idlink_va']);
}

private function shouldUseHttpsHost($idSite, $host)
{
static $siteUrlCache = [];
static $hostSiteCache = [];

if (empty($siteUrlCache[$idSite])) {
$siteUrlCache[$idSite] = APISitesManager::getInstance()->getSiteUrlsFromId($idSite);
}

if (!isset($hostSiteCache[$idSite][$host])) {
$hostSiteCache[$idSite][$host] = false;

foreach ($siteUrlCache[$idSite] as $siteUrl) {
if (strpos(strtolower($siteUrl), strtolower('https://' . $host)) === 0) {
$hostSiteCache[$idSite][$host] = true;
break;
}
}
}

return $hostSiteCache[$idSite][$host];
}

/**
* @param $idVisit
* @return array
Expand Down

0 comments on commit 1c44aad

Please sign in to comment.