diff options
| author | Greg Roach <greg@subaqua.co.uk> | 2022-09-29 16:27:31 +0100 |
|---|---|---|
| committer | Greg Roach <greg@subaqua.co.uk> | 2022-09-29 16:27:31 +0100 |
| commit | f9f6fffde9a4ddea74e52e0f4c13cde4ec13f3a4 (patch) | |
| tree | 42abfae9611fc6e3e698ba8dfc260cfec4b44ac2 /resources/views | |
| parent | 4a9a60957058ca2a34e30a0d6f783e1540606590 (diff) | |
| download | webtrees-f9f6fffde9a4ddea74e52e0f4c13cde4ec13f3a4.tar.gz webtrees-f9f6fffde9a4ddea74e52e0f4c13cde4ec13f3a4.tar.bz2 webtrees-f9f6fffde9a4ddea74e52e0f4c13cde4ec13f3a4.zip | |
Fix: #4384, Fix: #3580 - add support for google-analytics V4
Diffstat (limited to 'resources/views')
| -rw-r--r-- | resources/views/modules/google-analytics/form.phtml | 2 | ||||
| -rw-r--r-- | resources/views/modules/google-analytics/snippet-v4.phtml | 21 | ||||
| -rw-r--r-- | resources/views/modules/google-analytics/snippet.phtml | 1 |
3 files changed, 23 insertions, 1 deletions
diff --git a/resources/views/modules/google-analytics/form.phtml b/resources/views/modules/google-analytics/form.phtml index eae68599f8..bd7f91487d 100644 --- a/resources/views/modules/google-analytics/form.phtml +++ b/resources/views/modules/google-analytics/form.phtml @@ -12,6 +12,6 @@ use Fisharebest\Webtrees\I18N; <span class="visually-hidden">Google Analytics</span> </label> <div class="col-sm-9"> - <input type="text" class="form-control" id="GOOGLE_ANALYTICS_ID" name="GOOGLE_ANALYTICS_ID" value="<?= e($GOOGLE_ANALYTICS_ID ?? '') ?>" placeholder="UA-12345-6" maxlength="255" pattern="UA-[0-9]+-[0-9]+"> + <input type="text" class="form-control" id="GOOGLE_ANALYTICS_ID" name="GOOGLE_ANALYTICS_ID" value="<?= e($GOOGLE_ANALYTICS_ID ?? '') ?>" placeholder="UA-12345-6 / G-1A2B3C4D" maxlength="255" pattern="UA-[0-9]+-[0-9]+|G-[0-9A-Z]+"> </div> </div> diff --git a/resources/views/modules/google-analytics/snippet-v4.phtml b/resources/views/modules/google-analytics/snippet-v4.phtml new file mode 100644 index 0000000000..41ac49d32f --- /dev/null +++ b/resources/views/modules/google-analytics/snippet-v4.phtml @@ -0,0 +1,21 @@ +<?php + +declare(strict_types=1); + +/** + * @var string $access_level + * @var string $tree_name + * @var string $GOOGLE_ANALYTICS_ID + */ +?> +<script async src="https://www.googletagmanager.com/gtag/js?id=<?= e($GOOGLE_ANALYTICS_ID ?? '') ?>"></script> +<script> + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + gtag('config', <?= json_encode($GOOGLE_ANALYTICS_ID, JSON_THROW_ON_ERROR) ?>, { + 'custom_map': {'dimension1': 'tree_name', 'dimension2': 'access_level'}, + 'tree_name': <?= json_encode($tree_name, JSON_THROW_ON_ERROR) ?>, + 'access_level': <?= json_encode($access_level, JSON_THROW_ON_ERROR) ?>, + }); +</script> diff --git a/resources/views/modules/google-analytics/snippet.phtml b/resources/views/modules/google-analytics/snippet.phtml index 093f4813c2..c5ad9ab446 100644 --- a/resources/views/modules/google-analytics/snippet.phtml +++ b/resources/views/modules/google-analytics/snippet.phtml @@ -4,6 +4,7 @@ declare(strict_types=1); /** * @var object $dimensions + * @var string $GOOGLE_ANALYTICS_ID */ assert(is_object($dimensions)) |
