Seite 7 von 13
Schritt 4 – Datei erstellen
In diesem Ordner neue Datei erstellen: ga.php
Diese Datei gehört in den Pfad: /plugins/system/ga/ga.php
Inhalt:
<?php
defined('_JEXEC') or die;use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;class PlgSystemGa extends CMSPlugin
{
public function onBeforeCompileHead()
{
$app = Factory::getApplication(); if ($app->isClient('administrator')) {
return;
} $doc = $app->getDocument(); $script = "
<script async src=\"https://www.googletagmanager.com/gtag/js?id=G-XXXXXX\"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXX');
</script>
"; $doc->addCustomTag($script);
}
}
defined('_JEXEC') or die;use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;class PlgSystemGa extends CMSPlugin
{
public function onBeforeCompileHead()
{
$app = Factory::getApplication(); if ($app->isClient('administrator')) {
return;
} $doc = $app->getDocument(); $script = "
<script async src=\"https://www.googletagmanager.com/gtag/js?id=G-XXXXXX\"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXX');
</script>
"; $doc->addCustomTag($script);
}
}
Speichern.