-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTagManagerExtended.php
More file actions
108 lines (94 loc) · 3.47 KB
/
TagManagerExtended.php
File metadata and controls
108 lines (94 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?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\TagManagerExtended;
class TagManagerExtended extends \Piwik\Plugin
{
public function registerEvents()
{
return array(
'AssetManager.getStylesheetFiles' => 'getStylesheetFiles',
'AssetManager.getJavaScriptFiles' => 'getJavaScriptFiles',
'TagManager.filterTags' => 'filterTags',
'TagManager.filterVariables' => 'filterVariables',
'TagManager.filterTriggers' => 'filterTriggers',
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
);
}
public function getClientSideTranslationKeys(&$translationKeys)
{
$translationKeys[] = 'TagManagerExtended_BulkActions';
$translationKeys[] = 'TagManagerExtended_SelectAll';
$translationKeys[] = 'TagManagerExtended_DeselectAll';
$translationKeys[] = 'TagManagerExtended_Selected';
$translationKeys[] = 'TagManagerExtended_BulkDelete';
$translationKeys[] = 'TagManagerExtended_BulkPause';
$translationKeys[] = 'TagManagerExtended_BulkResume';
$translationKeys[] = 'TagManagerExtended_ConfirmBulkDelete';
$translationKeys[] = 'TagManagerExtended_ConfirmBulkPause';
$translationKeys[] = 'TagManagerExtended_ConfirmBulkResume';
$translationKeys[] = 'TagManagerExtended_BulkSuccess';
$translationKeys[] = 'TagManagerExtended_BulkPartialSuccess';
}
public function getStylesheetFiles(&$files)
{
$files[] = "plugins/TagManagerExtended/stylesheets/style.less";
}
public function getJavaScriptFiles(&$files)
{
$files[] = "plugins/TagManagerExtended/javascripts/script.js";
}
public function filterTags(&$tags)
{
$found = false;
foreach ($tags as $key => &$tag) {
if (in_array($tag->getId(), ['Axeptio', 'CookieYes', 'Cookiebot', 'OneTrust', 'Hotjar', 'GoogleAdsConversion', 'GoogleAnalytics4Event', 'GoogleTag']) && $this->isPartOfTagManagerPlugin($tag)) {
$found = true;
unset($tags[$key]);
}
}
if ($found) {
$tags = array_values($tags);
}
}
public function filterVariables(&$variables)
{
$found = false;
foreach ($variables as $key => &$variable) {
if (in_array($variable->getId(), ['ClickDataAttribute']) && $this->isPartOfTagManagerPlugin($variable)) {
$found = true;
unset($variables[$key]);
}
}
if ($found) {
$variables = array_values($variables);
}
}
public function filterTriggers(&$triggers)
{
$found = false;
foreach ($triggers as $key => &$trigger) {
if (in_array($trigger->getId(), ['CustomEvent']) && $this->isPartOfTagManagerPlugin($trigger)) {
$found = true;
unset($triggers[$key]);
}
}
if ($found) {
$triggers = array_values($triggers);
}
}
private function isPartOfTagManagerPlugin($object): bool
{
$classname = get_class($object);
$parts = explode('\\', $classname);
$pluginName = 'TagManager';
if (count($parts) >= 4 && $parts[1] === 'Plugins') {
$pluginName = $parts[2];
}
return $pluginName === 'TagManager';
}
}