summaryrefslogtreecommitdiff
path: root/resources
diff options
context:
space:
mode:
Diffstat (limited to 'resources')
-rw-r--r--resources/views/modules/google-analytics/form.phtml2
-rw-r--r--resources/views/modules/google-analytics/snippet-v4.phtml21
-rw-r--r--resources/views/modules/google-analytics/snippet.phtml1
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))