2015-09-29 03:57:26 +02:00
|
|
|
<?php
|
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
class pluginGoogle extends Plugin {
|
2015-09-29 03:57:26 +02:00
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$this->dbFields = array(
|
2017-06-04 21:08:31 +02:00
|
|
|
'google-analytics-tracking-id'=>'',
|
2017-03-18 19:48:34 +01:00
|
|
|
'google-site-verification'=>'',
|
|
|
|
'google-tag-manager'=>''
|
2015-09-29 03:57:26 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function form()
|
|
|
|
{
|
|
|
|
global $Language;
|
|
|
|
|
|
|
|
$html = '<div>';
|
|
|
|
$html .= '<label for="jsgoogle-site-verification">'.$Language->get('Google Webmasters tools').'</label>';
|
|
|
|
$html .= '<input id="jsgoogle-site-verification" type="text" name="google-site-verification" value="'.$this->getDbField('google-site-verification').'">';
|
2017-06-18 22:44:07 +02:00
|
|
|
$html .= '<span class="tip">'.$Language->get('complete-this-field-with-the-google-site-verification').'</span>';
|
2015-09-29 03:57:26 +02:00
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
$html .= '<div>';
|
|
|
|
$html .= '<label for="jstracking-id">'.$Language->get('Google Analytics Tracking ID').'</label>';
|
2017-06-04 21:08:31 +02:00
|
|
|
$html .= '<input id="jsgoogle-analytics-tracking-id" type="text" name="google-analytics-tracking-id" value="'.$this->getDbField('google-analytics-tracking-id').'">';
|
2017-06-18 22:44:07 +02:00
|
|
|
$html .= '<span class="tip">'.$Language->get('complete-this-field-with-the-tracking-id').'</span>';
|
2015-09-29 03:57:26 +02:00
|
|
|
$html .= '</div>';
|
|
|
|
|
2017-03-18 19:48:34 +01:00
|
|
|
$html .= '<div>';
|
|
|
|
$html .= '<label for="jsgoogle-tag-manager">'.$Language->get('Google Tag Manager').'</label>';
|
|
|
|
$html .= '<input id="jsgoogle-tag-manager" type="text" name="google-tag-manager" value="'.$this->getDbField('google-tag-manager').'">';
|
2017-06-18 22:44:07 +02:00
|
|
|
$html .= '<span class="tip">'.$Language->get('complete-this-field-with-the-tracking-id-google-tag').'</span>';
|
2017-03-18 19:48:34 +01:00
|
|
|
$html .= '</div>';
|
|
|
|
|
2015-09-29 03:57:26 +02:00
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function siteHead()
|
|
|
|
{
|
2016-05-05 13:57:47 +02:00
|
|
|
global $Url;
|
2017-06-04 21:08:31 +02:00
|
|
|
global $WHERE_AM_I;
|
2017-05-04 21:32:18 +02:00
|
|
|
|
2017-03-18 19:48:34 +01:00
|
|
|
$html = '';
|
2017-05-04 21:32:18 +02:00
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
// Google HTML tag
|
2017-10-14 19:57:10 +02:00
|
|
|
if ($this->getValue('google-site-verification') && ($WHERE_AM_I=='home')) {
|
2017-06-04 21:08:31 +02:00
|
|
|
$html .= PHP_EOL.'<!-- Google HTML tag -->'.PHP_EOL;
|
|
|
|
$html .= '<meta name="google-site-verification" content="'.$this->getDbField('google-site-verification').'" />'.PHP_EOL;
|
2017-03-18 19:48:34 +01:00
|
|
|
}
|
2017-05-04 21:32:18 +02:00
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
// Google Tag Manager
|
|
|
|
if( $this->getValue('google-tag-manager') ) {
|
2017-03-18 19:48:34 +01:00
|
|
|
$html .= PHP_EOL."<!-- Google Tag Manager -->".PHP_EOL;
|
|
|
|
$html .= "<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':".PHP_EOL;
|
|
|
|
$html .= "new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],".PHP_EOL;
|
|
|
|
$html .= "j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=".PHP_EOL;
|
|
|
|
$html .= "'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);".PHP_EOL;
|
2017-06-04 21:08:31 +02:00
|
|
|
$html .= "})(window,document,'script','dataLayer','".$this->getValue('google-tag-manager')."');</script>".PHP_EOL;
|
2017-03-18 19:48:34 +01:00
|
|
|
$html .= "<!-- End Google Tag Manager -->".PHP_EOL;
|
|
|
|
}
|
2017-05-04 21:32:18 +02:00
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
// Google Analytics
|
2017-10-14 19:57:10 +02:00
|
|
|
if ($this->getValue('google-analytics-tracking-id')) {
|
|
|
|
$html = PHP_EOL.'<!-- Google Analytics -->'.PHP_EOL;
|
|
|
|
$html .= '
|
|
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id='.$this->getValue('google-analytics-tracking-id').'"></script>
|
|
|
|
<script>
|
|
|
|
window.dataLayer = window.dataLayer || [];
|
|
|
|
function gtag(){dataLayer.push(arguments);}
|
|
|
|
gtag("js", new Date());
|
|
|
|
|
|
|
|
gtag("config", "'.$this->getValue('google-analytics-tracking-id').'");
|
|
|
|
</script>'.PHP_EOL;
|
2017-10-22 15:40:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function siteBodyBegin()
|
|
|
|
{
|
|
|
|
// Google Tag Manager
|
|
|
|
if ($this->getValue('google-tag-manager')) {
|
|
|
|
$html = '<!-- Google Tag Manager (noscript) -->'.PHP_EOL;
|
|
|
|
$html .= '<noscript><iframe src="https://www.googletagmanager.com/ns.html?id='.$this->getValue('google-tag-manager').'" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>'.PHP_EOL;
|
|
|
|
$html .= '<!-- End Google Tag Manager (noscript) -->'.PHP_EOL;
|
2017-10-14 19:57:10 +02:00
|
|
|
return $html;
|
2015-09-29 03:57:26 +02:00
|
|
|
}
|
2017-10-14 19:57:10 +02:00
|
|
|
return false;
|
2015-09-29 03:57:26 +02:00
|
|
|
}
|
2017-10-22 15:40:24 +02:00
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
}
|