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

Add Matomo Tag Manager to core #13402

Merged
merged 19 commits into from Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitmodules
Expand Up @@ -54,6 +54,10 @@
path = plugins/MarketingCampaignsReporting
url = https://github.com/matomo-org/plugin-MarketingCampaignsReporting.git
branch = master
[submodule "plugins/TagManager"]
path = plugins/TagManager
url = https://github.com/matomo-org/tag-manager.git
branch = master

# Add new Plugin submodule above this line ^^
#
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions plugins/CorePluginsAdmin/Controller.php
Expand Up @@ -20,9 +20,11 @@
use Piwik\Notification;
use Piwik\Piwik;
use Piwik\Plugin;
use Piwik\Plugins\CorePluginsAdmin\Model\TagManagerTeaser;
use Piwik\Plugins\Marketplace\Marketplace;
use Piwik\Plugins\Marketplace\Controller as MarketplaceController;
use Piwik\Plugins\Marketplace\Plugins;
use Piwik\Settings\Storage\Backend\PluginSettingsTable;
use Piwik\SettingsPiwik;
use Piwik\Translation\Translator;
use Piwik\Url;
Expand Down Expand Up @@ -144,8 +146,52 @@ public function browseThemes()
$this->redirectToIndex('Marketplace', 'overview', null, null, null, array('show' => 'themes'));
}

public function tagManagerTeaser()
{
$this->dieIfPluginsAdminIsDisabled();
Piwik::checkUserHasSomeAdminAccess();

$tagManagerTeaser = new TagManagerTeaser(Piwik::getCurrentUserLogin());

if (!$tagManagerTeaser->shouldShowTeaser()) {
$this->redirectToIndex('CoreHome', 'index');
return;
}

$nonce = '';
if (Piwik::hasUserSuperUserAccess()) {
$nonce = Nonce::getNonce(static::ACTIVATE_NONCE);
}

$superUsers = Request::processRequest('UsersManager.getUsersHavingSuperUserAccess', [], []);
$emails = implode(',', array_column($superUsers, 'email'));

$view = new View('@CorePluginsAdmin/tagManagerTeaser');
$this->setGeneralVariablesView($view);
$view->superUserEmails = $emails;
$view->nonce = $nonce;
return $view->render();
}

public function disableActivateTagManagerPage()
{
$this->dieIfPluginsAdminIsDisabled();
Piwik::checkUserHasSomeAdminAccess();

$tagManagerTeaser = new TagManagerTeaser(Piwik::getCurrentUserLogin());

if (Piwik::hasUserSuperUserAccess()) {
$tagManagerTeaser->disableGlobally();
tsteur marked this conversation as resolved.
Show resolved Hide resolved
} else {
$tagManagerTeaser->disableForUser();
}

$this->redirectToIndex('CoreHome', 'index');
}

private function dieIfPluginsAdminIsDisabled()
{
Piwik::checkUserIsNotAnonymous();
if (!CorePluginsAdmin::isPluginsAdminEnabled()) {
throw new \Exception('Enabling, disabling and uninstalling plugins has been disabled by Piwik admins.
Please contact your Piwik admins with your request so they can assist you.');
Expand Down Expand Up @@ -395,6 +441,8 @@ public function activate($redirectAfter = true)
$redirectTo = Common::getRequestVar('redirectTo', '', 'string');
if (!empty($redirectTo) && $redirectTo === 'marketplace') {
$this->redirectToIndex('Marketplace', 'overview');
} elseif (!empty($redirectTo) && $redirectTo === 'tagmanager') {
$this->redirectToIndex('TagManager', 'gettingStarted');
} elseif (!empty($redirectTo) && $redirectTo === 'referrer') {
$this->redirectAfterModification($redirectAfter);
} else {
Expand Down
13 changes: 12 additions & 1 deletion plugins/CorePluginsAdmin/CorePluginsAdmin.php
Expand Up @@ -12,6 +12,7 @@
use Piwik\Piwik;
use Piwik\Plugin;
use Piwik\Plugins\CoreHome\SystemSummary;
use Piwik\Plugins\CorePluginsAdmin\Model\TagManagerTeaser;

class CorePluginsAdmin extends Plugin
{
Expand All @@ -24,10 +25,20 @@ public function registerEvents()
'AssetManager.getJavaScriptFiles' => 'getJsFiles',
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'System.addSystemSummaryItems' => 'addSystemSummaryItems',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys'
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
'PluginManager.pluginActivated' => 'onPluginActivated'
);
}

public function onPluginActivated($pluginName)
{
if ($pluginName === 'TagManager') {
// make sure once activated once, it won't appear when disabling Tag Manager later
$tagManagerTeaser = new TagManagerTeaser(Piwik::getCurrentUserLogin());
$tagManagerTeaser->disableGlobally();
}
}

public function addSystemSummaryItems(&$systemSummary)
{
$numPlugins = Plugin\Manager::getInstance()->getNumberOfActivatedPluginsExcludingAlwaysActivated();
Expand Down
12 changes: 12 additions & 0 deletions plugins/CorePluginsAdmin/Menu.php
Expand Up @@ -10,7 +10,10 @@

use Piwik\Container\StaticContainer;
use Piwik\Menu\MenuAdmin;
use Piwik\Menu\MenuTop;
use Piwik\Piwik;
use Piwik\Plugin;
use Piwik\Plugins\CorePluginsAdmin\Model\TagManagerTeaser;
use Piwik\Plugins\Marketplace\Marketplace;
use Piwik\Plugins\Marketplace\Plugins;

Expand All @@ -32,6 +35,15 @@ public function __construct($marketplacePlugins = null)
}
}

public function configureTopMenu(MenuTop $menu)
{
$tagManagerTeaser = new TagManagerTeaser(Piwik::getCurrentUserLogin());

if ($tagManagerTeaser->shouldShowTeaser()) {
$menu->addItem('Tag Manager', null, $this->urlForAction('tagManagerTeaser'));
}
}

public function configureAdminMenu(MenuAdmin $menu)
{
$hasSuperUserAcess = Piwik::hasUserSuperUserAccess();
Expand Down
85 changes: 85 additions & 0 deletions plugins/CorePluginsAdmin/Model/TagManagerTeaser.php
@@ -0,0 +1,85 @@
<?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\CorePluginsAdmin\Model;

use Piwik\Plugin;
use Piwik\Option;
use Piwik\Piwik;
use Piwik\Plugins\CorePluginsAdmin\CorePluginsAdmin;
use Piwik\Settings\Storage\Backend\PluginSettingsTable;

class TagManagerTeaser
{
const DISABLE_GLOBALLY_KEY = 'CorePluginsAdmin.disableTagManagerTeaser';

/**
* @var string
*/
private $login;

public function __construct($login)
{
$this->login = $login;
}

public function shouldShowTeaser()
{
$pluginManager = Plugin\Manager::getInstance();

return CorePluginsAdmin::isPluginsAdminEnabled()
&& (!$pluginManager->isPluginActivated('TagManager')
|| !$pluginManager->isPluginLoaded('TagManager'))
&& $pluginManager->isPluginInFilesystem('TagManager')
&& Piwik::isUserHasSomeAdminAccess()
&& $this->isEnabledGlobally()
&& $this->isEnabledForUser();
}

public function disableForUser()
{
$table = $this->getTable();
$settings = $table->load();
$settings['disable_activate_tag_manager_page'] = 1;
$table->save($settings);
}

public function isEnabledForUser()
{
$pluginSettingsTable = $this->getTable();
$settings = $pluginSettingsTable->load();

return empty($settings['disable_activate_tag_manager_page']);
}

public function disableGlobally()
{
$this->reset();
Option::set(self::DISABLE_GLOBALLY_KEY, 1, true);
}

public function reset()
{
Option::delete(self::DISABLE_GLOBALLY_KEY);

// no need to keep any old login entries
$this->getTable()->save(array());
}

public function isEnabledGlobally()
{
$value = Option::get(self::DISABLE_GLOBALLY_KEY);
return empty($value);
}

private function getTable()
{
return new PluginSettingsTable('CorePluginsAdmin', $this->login);
}

}
19 changes: 19 additions & 0 deletions plugins/CorePluginsAdmin/config/test.php
@@ -0,0 +1,19 @@
<?php

return array(
'observers.global' => DI\add(array(
array('Request.dispatchCoreAndPluginUpdatesScreen', function () {
$pluginName = 'TagManager';
$unloadTagManager = \Piwik\Container\StaticContainer::get('test.vars.unloadTagManager');
$tagManagerTeaser = new \Piwik\Plugins\CorePluginsAdmin\Model\TagManagerTeaser(\Piwik\Piwik::getCurrentUserLogin());
if ($unloadTagManager) {
$pluginManager = \Piwik\Plugin\Manager::getInstance();
if ($pluginManager->isPluginActivated($pluginName)
&& $pluginManager->isPluginLoaded($pluginName)) {
$pluginManager->unloadPlugin($pluginName);
}
$tagManagerTeaser->reset();
}
}),
))
);
18 changes: 18 additions & 0 deletions plugins/CorePluginsAdmin/lang/en.json
Expand Up @@ -57,6 +57,24 @@
"TeaserExtendPiwikByPlugin": "Extend Matomo by %1$sinstalling plugins from the Marketplace%2$s or %3$supload a plugin in .zip format%4$s.",
"TeaserExtendPiwikByTheme": "Enjoy another look & feel by %1$sinstalling a new theme%2$s.",
"InstallingNewPluginViaMarketplaceOrUpload": "You may automatically install plugins from the Marketplace or %1$supload a plugin%2$s in .zip format.",
"TagManagerNowAvailableTitle": "Matomo Tag Manager is now available",
"TagManagerNowAvailableSubtitle": "Manage all your tags easily through one platform to get the insights you want, the opportunities are endless!",
"ActivateTagManagerNow": "Activate Tag Manager now",
"TagManagerEmailSuperUserToActivate": "Email Super Users to activate this new feature",
"TagManagerTeaserHideSuperUser": "Do not show this page to any user",
"TagManagerTeaserHideNonSuperUser": "Not interested, do not show this page again",
"TagManagerTeaserEmailSuperUserBody": "Hi,%1$sMatomo Tag Manager is now available within Matomo and I would love to use this new feature. As you have Super User access, could you activate this feature through the Tag Manager page in the top menu?%2$sThe Matomo URL is %3$s.%4$sThanks",
"WhatIsTagManager": "What is a Tag Manager?",
"WhatIsTagManagerDetails1": "Similar to how a Content Management System (CMS) brings you all the flexibility to publish content for your website without having the technical HTML/CSS knowledge, a Tag Management System (TMS) is your go-to for simplifying the process of embedding first and third-party application tracking tags (also known as snippets or pixels) on your website.",
"WhatIsTagManagerDetails2": "Say you want to see the results of your conversions/goals, newsletter signups, social widgets, exit popups and remarketing campaigns; what was once a highly technical and time consuming process is now easily done within the TMS and takes only a few clicks to implement.",
"TagManagerLearnMoreInUserGuide": "Learn more in the Tag Manager User Guide",
"WhyUsingATagManager": "Why a Tag Manager?",
"WhyUsingATagManagerDetails1": "A Tag Manager makes your life easier! You no longer need to wait on a developer to modify any first or third-party snippets on your website as the Tag Manager gives you a stress-free experience to make these changes and deploy your website yourself.",
"WhyUsingATagManagerDetails2": "It couldn't be more convenient and it not only lets you bring changes to the market faster, but also reduces cost.",
"WhyUsingATagManagerDetails3": "This keeps the marketing teams, digital teams and the IT guys happy... It’s a win-win for everyone!",
"AreThereAnyRisks": "Are there any risks?",
"AreThereAnyRisksDetails1": "When you activate the Tag Manager, users with admin access will be able to create custom HTML tags, triggers, and variables that may execute JavaScript on your website. These custom templates could be misused to steal, for example, sensitive information from your website visitors (known as %1$sXSS%2$s).",
"AreThereAnyRisksDetails2": "You can disable these custom templates under \"Administration => General Settings\" once you have activated the Tag Manager. Alternatively, you can also restrict the usage of these templates to specific users or super users only.",
"Theme": "Theme",
"Themes": "Themes",
"ThemesDescription": "Themes can change the appearance of Matomo user interface, and provide a completely new visual experience to enjoy your analytics reports.",
Expand Down
7 changes: 7 additions & 0 deletions plugins/CorePluginsAdmin/stylesheets/plugins_admin.less
Expand Up @@ -142,3 +142,10 @@ table.entityTable tr td a.uninstall {
margin-left: 20px;
}
}


.activateTagManager {
.dontShowAgainBtn {
background-color: @theme-color-text-lighter;
}
}
73 changes: 73 additions & 0 deletions plugins/CorePluginsAdmin/templates/tagManagerTeaser.twig
@@ -0,0 +1,73 @@
{% extends 'dashboard.twig' %}

{% block topcontrols %}
{% endblock %}

{% block content %}
<div class="activateTagManager">
<div class="row">
<div class="col s12" style="text-align: center;">
<h2>{{ 'CorePluginsAdmin_TagManagerNowAvailableTitle'|translate }}</h2>
<p>{{ 'CorePluginsAdmin_TagManagerNowAvailableSubtitle'|translate }}</p>
</div>
</div>
{% set actionBlock %}
<div class="row">
<div class="col s12">
<div style="text-align: center;">
{% if isSuperUser %}
<a href="{{ linkTo({'module': 'CorePluginsAdmin', 'action': 'activate', 'nonce': nonce, 'pluginName': 'TagManager', 'redirectTo': 'tagmanager'}) }}"
class="btn activateTagManagerPlugin"><span class="icon-rocket"></span> {{ 'CorePluginsAdmin_ActivateTagManagerNow'|translate }} <span class="icon-rocket"></span></a>
{% else %}
<a href="mailto:{{ superUserEmails|e('url') }}?subject={{ 'CorePluginsAdmin_TagManagerNowAvailableTitle'|translate|e('url') }}&body={{ 'CorePluginsAdmin_TagManagerTeaserEmailSuperUserBody'|translate("\n\n", "\n\n", piwikUrl, "\n\n")|e('url') }}"
class="btn activateTagManagerPlugin"><span class="icon-rocket"></span> {{ 'CorePluginsAdmin_TagManagerEmailSuperUserToActivate'|translate }} <span class="icon-rocket"></span></a>
{% endif %}

<a href="{{ linkTo({'module': 'CorePluginsAdmin', 'action': 'disableActivateTagManagerPage'}) }}"
class="btn dontShowAgainBtn"><span class="icon-hide"></span>
{% if isSuperUser %}{{ 'CorePluginsAdmin_TagManagerTeaserHideSuperUser'|translate }}{% else %}{{ 'CorePluginsAdmin_TagManagerTeaserHideNonSuperUser'|translate }}{% endif %}
</a>
</div>
</div>
</div>
{% endset %}
{{ actionBlock|raw }}
<div class="row">
<div class="col {% if isSuperUser %}l4{% else %}l6{% endif %} m12 s12">
<div piwik-content-block content-title="{{ 'CorePluginsAdmin_WhatIsTagManager'|translate }}">
<p>
{{ 'CorePluginsAdmin_WhatIsTagManagerDetails1'|translate }}<br /><br />
{{ 'CorePluginsAdmin_WhatIsTagManagerDetails2'|translate }}<br /><br />
<a href="https://matomo.org/docs/tag-manager" rel="noreferrer noopener">{{ 'CorePluginsAdmin_TagManagerLearnMoreInUserGuide'|translate }}</a>
</p>
</div>
</div>
<div class="col {% if isSuperUser %}l4{% else %}l6{% endif %} m12 s12">
<div piwik-content-block content-title="{{ 'CorePluginsAdmin_WhyUsingATagManager'|translate }}">
<p>
{{ 'CorePluginsAdmin_WhyUsingATagManagerDetails1'|translate }}
<br /><br />
{{ 'CorePluginsAdmin_WhyUsingATagManagerDetails2'|translate }}
<br /><br />
{{ 'CorePluginsAdmin_WhyUsingATagManagerDetails3'|translate }}
<br /><br /><br />
<a href="https://matomo.org/docs/tag-manager" rel="noreferrer noopener">{{ 'CorePluginsAdmin_TagManagerLearnMoreInUserGuide'|translate }}</a>
</p>
</div>
</div>
{% if isSuperUser %}
<div class="col l4 m12 s12">
<div piwik-content-block content-title="{{ 'CorePluginsAdmin_AreThereAnyRisks'|translate }}">

{{ 'CorePluginsAdmin_AreThereAnyRisksDetails1'|translate('<a rel="noreferrer noopener" href="https://en.wikipedia.org/wiki/Cross-site_scripting">', '</a>')|raw }}
<br /><br />
{{ 'CorePluginsAdmin_AreThereAnyRisksDetails2'|translate }}
<br /><br /><br />
<a href="https://matomo.org/docs/tag-manager/#website-security" rel="noreferrer noopener">{{ 'CorePluginsAdmin_TagManagerLearnMoreInUserGuide'|translate }}</a>
</div>
</div>
{% endif %}
</div>
{{ actionBlock|raw }}
</div>
{% endblock %}