Skip to content

Commit

Permalink
Change no data page logic according to core changes (#684)
Browse files Browse the repository at this point in the history
* Adjustments according to core changes

* Moved SPA/PWA class to TagManager

* apply some review feedback
  • Loading branch information
sgiehl authored Sep 15, 2023
1 parent 052ff16 commit cb826f1
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 12 deletions.
54 changes: 54 additions & 0 deletions SiteContentDetection/SpaPwa.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Plugins\TagManager\SiteContentDetection;

use Piwik\Container\StaticContainer;
use Piwik\Piwik;
use Piwik\Plugins\SitesManager\SiteContentDetection\SiteContentDetectionAbstract;
use Piwik\SiteContentDetector;
use Piwik\View;

class SpaPwa extends SiteContentDetectionAbstract
{
public static function getName(): string
{
return 'SPA / PWA';
}

public static function getContentType(): string
{
return self::TYPE_JS_FRAMEWORK;
}

public static function getPriority(): int
{
return 70;
}

public function isDetected(?string $data = null, ?array $headers = null): bool
{
return false;
}

public function shouldShowInstructionTab(SiteContentDetector $detector = null): bool
{
return true;
}

public function renderInstructionsTab(SiteContentDetector $detector): string
{
$model = StaticContainer::get('Piwik\Plugins\TagManager\Model\Container');
$view = new View("@TagManager/trackingSPA");
$view->action = Piwik::getAction();
$view->showContainerRow = $model->getNumContainersTotal() > 1;
return $view->render();
}
}
19 changes: 8 additions & 11 deletions TagManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function registerEvents()
'SitesManager.addSite.end' => 'onSiteAdded',
'System.addSystemSummaryItems' => 'addSystemSummaryItems',
'Template.endTrackingCodePage' => 'addTagManagerCode',
'Template.siteWithoutDataTab.MatomoTagManager.content' => 'setTagManagerCode',
'Template.endTrackingHelpPage' => 'addTagManagerTrackingCodeHelp',
'Template.endTrackingCodePageTableOfContents' => 'endTrackingCodePageTableOfContents',
'Tracker.PageUrl.getQueryParametersToExclude' => 'getQueryParametersToExclude',
Expand All @@ -69,8 +70,7 @@ public function registerEvents()
'Access.Capability.addCapabilities' => 'addCapabilities',
'TwoFactorAuth.requiresTwoFactorAuthentication' => 'requiresTwoFactorAuthentication',
'Db.getTablesInstalled' => 'getTablesInstalled',
'Template.embedReactTagManagerTrackingCode' => 'embedReactTagManagerTrackingCode',
'Template.embedSPATagManagerTrackingCode' => 'embedSPATagManagerTrackingCode',
'Template.siteWithoutDataTab.ReactJs.content' => 'embedReactTagManagerTrackingCode',
);
}

Expand Down Expand Up @@ -271,21 +271,18 @@ public function addTagManagerCode(&$out)
$out .= $view->render();
}

public function embedReactTagManagerTrackingCode(&$out)
public function setTagManagerCode(&$out)
{
Piwik::checkUserHasSomeViewAccess();
$model = $this->getContainerModel();
$view = new View("@TagManager/trackingCodeReact");
$view->action = Piwik::getAction();
$view->showContainerRow = $model->getNumContainersTotal() > 1;
$out .= $view->render();
$newContent = '';
$this->addTagManagerCode($newContent);
$out = $newContent;
}

public function embedSPATagManagerTrackingCode(&$out)
public function embedReactTagManagerTrackingCode(&$out)
{
Piwik::checkUserHasSomeViewAccess();
$model = $this->getContainerModel();
$view = new View("@TagManager/trackingSPA");
$view = new View("@TagManager/trackingCodeReact");
$view->action = Piwik::getAction();
$view->showContainerRow = $model->getNumContainersTotal() > 1;
$out .= $view->render();
Expand Down
7 changes: 6 additions & 1 deletion templates/trackingSPA.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<p>{{ 'SitesManager_SiteWithoutDataSPADescription'|translate('<a href="https://matomo.org/guide/tag-manager/" target="_blank" rel="noreferrer noopener">', '</a>', '<a href="https://developer.matomo.org/guides/spa-tracking" target="_blank" rel="noreferrer noopener">', '</a>')|raw }}</p>
<br>
<p>{{ 'SitesManager_SiteWithoutDataCloudflareFollowStepsIntro'|translate }}</p>
<div
vue-entry="TagManager.TrackingSPAPage"
current-action="{{ action|json_encode }}"
show-container-row="{{ showContainerRow|json_encode }}"
>
</div>
</div>
<br>
<p>{{ 'SitesManager_SiteWithoutDataSPAFollowStepCompleted'|translate('<strong>','</strong>')|raw }}</p>

0 comments on commit cb826f1

Please sign in to comment.