-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.php
95 lines (88 loc) · 3.13 KB
/
action.php
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
<?php
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
/**
* DokuWiki Plugin googleconsentmananger (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author i-net /// software <[email protected]>
*/
class action_plugin_googleconsentmananger extends ActionPlugin
{
const GTMID = 'GTMID';
/** @inheritDoc */
public function register(EventHandler $controller)
{
$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleTplMetaheaderOutput');
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'handleDokuwikiStarted');
}
/**
* Event handler for DOKUWIKI_STARTED
*
* @see https://www.dokuwiki.org/devel:events:DOKUWIKI_STARTED
* @param Event $event Event object
* @param mixed $param optional parameter passed when event was registered
* @return void
*/
public function handleDokuwikiStarted(Event $event, $param)
{
global $JSINFO;
global $conf;
$JSINFO['plugins']['googleconsent'] = array (
'template' => $conf['template'],
);
$this->addConfig( 'acceptBody' );
$this->addConfig( 'acceptButton' );
$this->addConfig( 'declineButton' );
$this->addConfig( 'policyButton' );
$this->addConfig( 'policyURL' );
$this->addConfig( 'acceptOnContinue' );
$this->addConfig( 'acceptOnScroll' );
$this->addConfig( 'acceptAnyClick' );
$this->addConfig( 'expireDays' );
$this->addConfig( 'renewOnVisit' );
$this->addConfig( 'forceShow' );
}
private function addConfig( $valueName ) {
global $JSINFO;
$value = $this->getConf($valueName);
if ( !empty( $value ) ) {
$JSINFO['plugins']['googleconsent'][$valueName] = $value;
}
}
/**
* Event handler for TPL_METAHEADER_OUTPUT
*
* @see https://www.dokuwiki.org/devel:events:TPL_METAHEADER_OUTPUT
* @param Event $event Event object
* @param mixed $param optional parameter passed when event was registered
* @return void
*/
public function handleTplMetaheaderOutput(Event $event, $param)
{
$GTMID = $this->getConf(self::GTMID);
if(!$GTMID) {
return;
}
$event->data['noscript'][] = array (
'_data' => '<iframe src="//www.googletagmanager.com/ns.html?id='.$this->getConf(self::GTMID).'" height="0" width="0" style="display:none;visibility:hidden"></iframe>',
);
$event->data['script'][] = array (
'type' => 'text/javascript',
'_data' => "
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('config', '${GTMID}');
gtag('consent', 'default', {
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'ad_storage': 'denied',
'analytics_storage': 'denied',
'wait_for_update': 500,
});
gtag('js', new Date());
",
);
}
}