Skip to content
This repository was archived by the owner on Jun 25, 2024. It is now read-only.

Commit 5e82eac

Browse files
author
stevebagwell
committed
Add in temporary script for Google Analytics 4 ID
1 parent 68b2e5c commit 5e82eac

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,16 @@ The login page looks for `/simplesamlphp/www/logo.png` which is **NOT** provided
3535

3636
Update `/simplesamlphp/config/config.php`:
3737

38+
Google Analytics Project ID (currently Universal Analytics, but transitioning to GA4)
3839
```
3940
'analytics.trackingId' => 'UA-some-unique-id-for-your-site'
4041
```
4142

43+
Temporary New Google Analytics 4
44+
```
45+
'analytics.trackingIdGA4' => 'G-some-unique-id-for-your-site'
46+
```
47+
4248
_[ssp-base](https://github.com/silinternational/ssp-base) provides a convenience by loading this config with whatever is in the environment variable `ANALYTICS_ID`._
4349

4450
### Announcements

themes/material/common-head-elements.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
<?php
99
$trackingId = htmlentities($this->configuration->getValue('analytics.trackingId'));
10+
$hasGATracking = false;
11+
1012
if (! empty($trackingId)) {
13+
$hasGATracking = true;
1114
?>
1215
<script>
1316
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
@@ -16,7 +19,30 @@
1619
</script>
1720
<script async src='https://www.google-analytics.com/analytics.js'></script>
1821
<?php
19-
} else {
22+
}
23+
?>
24+
25+
26+
<?php
27+
// This block of code is intended to be temporary until the transition from
28+
// Google's Universal Analytics to GA4 type projects has been completed
29+
$trackingIdGA4 = htmlentities($this->configuration->getValue('analytics.trackingIdGA4'));
30+
if (! empty($trackingIdGA4)) {
31+
$hasGATracking = true;
32+
?>
33+
<!-- Google tag (gtag.js) -->
34+
<script async src="https://www.googletagmanager.com/gtag/js?id=<?= $trackingIdGA4 ?>"></script>
35+
<script>
36+
window.dataLayer = window.dataLayer || [];
37+
function gtag(){dataLayer.push(arguments);}
38+
gtag('js', new Date());
39+
40+
gtag('config', '<?= $trackingIdGA4 ?>');
41+
</script>
42+
<?php
43+
}
44+
45+
if (! $hasGATracking) {
2046
?>
2147
<script>
2248
window.ga = function () {

0 commit comments

Comments
 (0)