Google Analytics on head

This commit is contained in:
Diego Najar 2017-10-22 15:40:24 +02:00
parent 44696f115f
commit 25d2a113fd
1 changed files with 14 additions and 18 deletions

View File

@ -60,6 +60,20 @@ class pluginGoogle extends Plugin {
$html .= "<!-- End Google Tag Manager -->".PHP_EOL;
}
// Google Analytics
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;
}
return $html;
}
@ -75,22 +89,4 @@ class pluginGoogle extends Plugin {
return false;
}
public function siteBodyEnd()
{
// Google Analytics
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;
return $html;
}
return false;
}
}