Skip to content

Commit

Permalink
Show an extra text field if the do not track header is sent.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmolineus committed Aug 21, 2018
1 parent f26e997 commit 2f48ad4
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 5 deletions.
25 changes: 23 additions & 2 deletions src/Resources/contao/dca/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
* Palette definitions
*/

$GLOBALS['TL_DCA']['tl_content']['palettes']['matomo_optout'] = '{type_legend},type,headline'
. ';{matomo_legend},matomo_btn_activate,matomo_btn_deactivate,matomo_status_activated,matomo_status_deactivated'
$GLOBALS['TL_DCA']['tl_content']['palettes']['__selector__'][] = 'matomo_do_not_track';
$GLOBALS['TL_DCA']['tl_content']['palettes']['matomo_optout'] = '{type_legend},type,headline'
. ';{matomo_legend},matomo_btn_activate,matomo_btn_deactivate,matomo_status_activated,matomo_status_deactivated,matomo_do_not_track'
. ';{template_legend:hide},customTpl'
. ';{protected_legend:hide},protected'
. ';{expert_legend:hide},guests,cssID'
. ';{invisible_legend:hide},invisible,start,stop';

$GLOBALS['TL_DCA']['tl_content']['subpalettes']['matomo_do_not_track'] = 'matomo_status_do_not_track';


/*
* Field definitions
Expand Down Expand Up @@ -70,3 +73,21 @@
'eval' => ['tl_class' => 'clr long', 'rte' => 'tinyMCE', 'style' => 'height:80px'],
'sql' => "mediumtext NULL",
];

$GLOBALS['TL_DCA']['tl_content']['fields']['matomo_do_not_track'] = [
'label' => &$GLOBALS['TL_LANG']['tl_content']['matomo_do_not_track'],
'exclude' => true,
'search' => true,
'inputType' => 'checkbox',
'eval' => ['tl_class' => 'w50', 'submitOnChange' => true],
'sql' => "char(1) NOT NULL default ''",
];

$GLOBALS['TL_DCA']['tl_content']['fields']['matomo_status_do_not_track'] = [
'label' => &$GLOBALS['TL_LANG']['tl_content']['matomo_status_do_not_track'],
'exclude' => true,
'search' => true,
'inputType' => 'textarea',
'eval' => ['tl_class' => 'clr long', 'rte' => 'tinyMCE', 'style' => 'height:80px'],
'sql' => "mediumtext NULL",
];
5 changes: 5 additions & 0 deletions src/Resources/contao/languages/de/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@
$GLOBALS['TL_LANG']['tl_content']['matomo_status_deactivated'][0] = 'Beschreibung Tracking deaktiviert';
$GLOBALS['TL_LANG']['tl_content']['matomo_status_deactivated'][1] = 'Die Beschreibung wird angezeigt, wenn das Tracking deaktiviert ist.';

$GLOBALS['TL_LANG']['tl_content']['matomo_do_not_track'][0] = 'Respektiere Do Not Track';
$GLOBALS['TL_LANG']['tl_content']['matomo_do_not_track'][1] = 'In Ihrer Matomo-Installation wird der Do Not Track Header des Nutzers respektiert.';
$GLOBALS['TL_LANG']['tl_content']['matomo_status_do_not_track'][0] = 'Beschreibung für Do Not Track';
$GLOBALS['TL_LANG']['tl_content']['matomo_status_do_not_track'][1] = 'Die Beschreibung wird angezeigt, wenn der Nutzer den Do Not Track Header sendet.';

$GLOBALS['TL_LANG']['tl_content']['matomoAjaxOptoutHint'] = 'Dieses Feature setzt das Plugin <a href="https://plugins.matomo.org/AjaxOptOut" target="_blank"><strong>AjaxOptOut</strong></a> in der Matomo Installation voraus.';
5 changes: 5 additions & 0 deletions src/Resources/contao/languages/en/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@
$GLOBALS['TL_LANG']['tl_content']['matomo_status_deactivated'][0] = 'Description tracking deactivated';
$GLOBALS['TL_LANG']['tl_content']['matomo_status_deactivated'][1] = 'The description is shown when the tracking is deactivated.';

$GLOBALS['TL_LANG']['tl_content']['matomo_do_not_track'][0] = 'Respect do not track';
$GLOBALS['TL_LANG']['tl_content']['matomo_do_not_track'][1] = 'Enable if you respect the do not track setting in your matomo installation.';
$GLOBALS['TL_LANG']['tl_content']['matomo_status_do_not_track'][0] = 'Description for detected do not track';
$GLOBALS['TL_LANG']['tl_content']['matomo_status_do_not_track'][1] = 'The description is shown when the user sends the do not track header.';

$GLOBALS['TL_LANG']['tl_content']['matomoAjaxOptoutHint'] = 'This feature requires the <a href="https://plugins.matomo.org/AjaxOptOut" target="_blank"><strong>AjaxOptOut</strong></a> plugin being installed at your Matomo installation.';
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
data-matomo-url="<?= \StringUtil::specialchars($this->matomoUrl) ?>"
data-label-deactivate="<?= \StringUtil::specialchars($this->matomo_btn_deactivate) ?>"
data-label-activate="<?= \StringUtil::specialchars($this->matomo_btn_activate) ?>"
data-cookie-error="<?= \StringUtil::specialchars($this->cookieError) ?>"></button>
data-cookie-error="<?= \StringUtil::specialchars($this->cookieError) ?>"
data-do-not-track="<?= $this->matomo_do_not_track ?>"></button>
<div id="matomo-status-activated" style="display: none"><?= $this->matomo_status_activated ?></div>
<div id="matomo-status-deactivated" style="display: none"><?= $this->matomo_status_deactivated ?></div>
<?php if ($this->matomo_do_not_track): ?>
<div id="matomo-status-do-not-track" style="display: none"><?= $this->matomo_status_do_not_track ?></div>
<?php endif ?>
<noscript>
<iframe src="<?= $this->matomoUrl ?>index.php?module=CoreAdminHome&action=optOut&language=de&backgroundColor=<?= $this->bgColor ?>&fontColor=<?= $this->fontColor ?>&fontSize=<?= $this->fontSize ?>&fontFamily=<?= $this->fontFamily ?>" class="matomo-optout-iframe"></iframe>
</noscript>
Expand Down
11 changes: 10 additions & 1 deletion src/Resources/public/js/optout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var matomoOptOut = function (options) {
btn: 'matomo-optout-btn',
activatedStatus: 'matomo-status-activated',
deactivatedStatus: 'matomo-status-deactivated',
noNotTrackStatus: 'matomo-status-do-not-track'
},
api: {
uri: 'index.php?module=API&format=json&method=',
Expand All @@ -16,7 +17,15 @@ var matomoOptOut = function (options) {
options || {}
);

this.btn = document.getElementById(this.options.selectors.btn);
this.btn = document.getElementById(this.options.selectors.btn);

if (this.btn.getAttribute('data-do-not-track') === '1' && navigator.doNotTrack) {
this.doNotTrackStatus = document.getElementById(this.options.selectors.noNotTrackStatus);
this.doNotTrackStatus.setAttribute('style', '');

return;
}

this.activatedStatus = document.getElementById(this.options.selectors.activatedStatus);
this.deactivatedStatus = document.getElementById(this.options.selectors.deactivatedStatus);

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/public/js/optout.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2f48ad4

Please sign in to comment.