Google Analytics with EU GDPR
This commit is contained in:
parent
b3ed00f45d
commit
c855c2fc88
14
bl-plugins/google-analytics/languages/en.json
Normal file
14
bl-plugins/google-analytics/languages/en.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"plugin-data":
|
||||
{
|
||||
"name": "Google Analytics",
|
||||
"description": "This plugin generates the necessary code for the following Google tools: Google Analytics, Google Tag Manager and Google Site Verification HTML Tag."
|
||||
},
|
||||
|
||||
"google-webmasters-tools": "Google Webmasters tools",
|
||||
"google-analytics-tracking-id": "Google Analytics Tracking ID",
|
||||
"google-tag-manager": "Google Tag Manager",
|
||||
"complete-this-field-with-the-google-site-verification": "Complete this field with the Google Site verification to verify the site owner.",
|
||||
"complete-this-field-with-the-tracking-id": "Complete this field with the Tracking ID to generate the Javascript tracking code for Google Analytics.",
|
||||
"complete-this-field-with-the-tracking-id-google-tag": "Complete this field with the Tracking ID to generate the Javascript tracking code for Google Tag Manager."
|
||||
}
|
10
bl-plugins/google-analytics/metadata.json
Normal file
10
bl-plugins/google-analytics/metadata.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"author": "Bludit",
|
||||
"email": "",
|
||||
"website": "https://plugins.bludit.com",
|
||||
"version": "2.3",
|
||||
"releaseDate": "2018-01-23",
|
||||
"license": "MIT",
|
||||
"compatible": "2.3",
|
||||
"notes": ""
|
||||
}
|
113
bl-plugins/google-analytics/plugin.php
Normal file
113
bl-plugins/google-analytics/plugin.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
class pluginGoogleAnalytics extends Plugin {
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->dbFields = array(
|
||||
'EUGDPR'=>true,
|
||||
'trackingID'=>''
|
||||
);
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
global $Language;
|
||||
|
||||
$html = '<div>';
|
||||
$html .= '<label for="jstrackingID">'.$Language->get('Google Analytics Tracking ID').'</label>';
|
||||
$html .= '<input id="jstrackingID" type="text" name="trackingID" value="'.$this->getValue('trackingID').'">';
|
||||
$html .= '<span class="tip">'.$Language->get('complete-this-field-with-the-tracking-id').'</span>';
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '<div>';
|
||||
$html .= '<label>EU General Data Protection</label>';
|
||||
$html .= '<select name="EUGDPR">';
|
||||
$html .= '<option value="true" '.($this->getValue('EUGDPR')===true?'selected':'').'>'.$Language->get('Enabled').'</option>';
|
||||
$html .= '<option value="false" '.($this->getValue('EUGDPR')===false?'selected':'').'>'.$Language->get('Disabled').'</option>';
|
||||
$html .= '</select>';
|
||||
$html .= '<span class="tip">Show the consent to the user before loading the script of Google Analytics. The user can reject be tracked for Google Analytics.</span>';
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function siteHead()
|
||||
{
|
||||
$html = '<style>
|
||||
#pluginGoogleAnalytics {
|
||||
display: block;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
background: #eee;
|
||||
padding: 2px 10px;
|
||||
font-size: 1em;
|
||||
color: #555;
|
||||
z-index: 2000;
|
||||
width: 100%;
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
border-bottom: 1px solid #999;
|
||||
}
|
||||
|
||||
#pluginGoogleAnalytics div.buttons {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
#pluginGoogleAnalytics button {
|
||||
margin-right: 10px;
|
||||
}
|
||||
}
|
||||
</style>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function siteBodyBegin()
|
||||
{
|
||||
$script = '
|
||||
<script>
|
||||
function executeGoogleAnalytics() {
|
||||
|
||||
var s = document.createElement("script");
|
||||
s.src = "https://www.googletagmanager.com/gtag/js?id='.$this->getValue('trackingID').'";
|
||||
document.body.appendChild(s);
|
||||
|
||||
var s = document.createElement("script");
|
||||
s.text = \'window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag("js", new Date()); gtag("config", "'.$this->getValue('trackingID').'");\';
|
||||
document.body.appendChild(s);
|
||||
|
||||
hideGoogleAnalyticsDialog();
|
||||
}
|
||||
|
||||
function hideGoogleAnalyticsDialog() {
|
||||
document.getElementById("pluginGoogleAnalytics").style.display = "none";
|
||||
}
|
||||
|
||||
</script>
|
||||
';
|
||||
|
||||
if ($this->getValue('EUGDPR')) {
|
||||
$html = '<div id="pluginGoogleAnalytics">';
|
||||
$html .= '<div>Allow to Google Analytics tracking you?</div>';
|
||||
$html .= '<div class="buttons">';
|
||||
$html .= '<button id="pluginGoogleAnalytics_allowButton">Allow</button>';
|
||||
$html .= '<button id="pluginGoogleAnalytics_denyButton">Deny</button>';
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
} else {
|
||||
$html = '<script> window.onload=function() { executeGoogleAnalytics(); }</script>';
|
||||
}
|
||||
|
||||
$script .= '
|
||||
<script>
|
||||
window.onload=function() {
|
||||
document.getElementById("pluginGoogleAnalytics_allowButton").addEventListener("click", executeGoogleAnalytics);
|
||||
document.getElementById("pluginGoogleAnalytics_denyButton").addEventListener("click", hideGoogleAnalyticsDialog);
|
||||
}
|
||||
</script>
|
||||
';
|
||||
|
||||
return $script.$html;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user