diff --git a/africanlii/templates/peachjam/layouts/main.html b/africanlii/templates/peachjam/layouts/main.html
index af6f29d5e..fe7b727ab 100644
--- a/africanlii/templates/peachjam/layouts/main.html
+++ b/africanlii/templates/peachjam/layouts/main.html
@@ -5,23 +5,3 @@
href="{% sass_src 'stylesheets/africanlii.scss' %}"
type="text/css"/>
{% endblock %}
-{% block head-js %}
- {{ block.super }}
-
-
-
-{% endblock %}
diff --git a/lawlibrary/templates/peachjam/layouts/main.html b/lawlibrary/templates/peachjam/layouts/main.html
index 309d67338..b8181b3f1 100644
--- a/lawlibrary/templates/peachjam/layouts/main.html
+++ b/lawlibrary/templates/peachjam/layouts/main.html
@@ -5,23 +5,3 @@
href="{% sass_src 'stylesheets/lawlibrary.scss' %}"
type="text/css"/>
{% endblock %}
-{% block head-js %}
- {{ block.super }}
-
-
-
-{% endblock %}
diff --git a/peachjam/js/peachjam.ts b/peachjam/js/peachjam.ts
index a77589f59..e5821f20c 100644
--- a/peachjam/js/peachjam.ts
+++ b/peachjam/js/peachjam.ts
@@ -61,6 +61,7 @@ class PeachJam {
this.setupTooltips();
this.setupPopovers();
this.scrollNavTabs();
+ this.clearGACookies();
}
setupConfig () {
@@ -176,6 +177,21 @@ class PeachJam {
}
});
}
+
+ clearGACookies () {
+ // if window.dataLayer is not set, then Google Analytics is not enabled, but there may be cookies still set; clear them
+ if (!window.dataLayer) {
+ const cookies = document.cookie.split(';');
+ for (let i = 0; i < cookies.length; i++) {
+ const cookie = cookies[i];
+ const eqPos = cookie.indexOf('=');
+ const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
+ if (name.trim().startsWith('_ga')) {
+ document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;domain=.${window.location.hostname}`;
+ }
+ }
+ }
+ }
}
const peachJam = new PeachJam();
diff --git a/peachjam/migrations/0119_matomo.py b/peachjam/migrations/0119_matomo.py
new file mode 100644
index 000000000..9a83027ae
--- /dev/null
+++ b/peachjam/migrations/0119_matomo.py
@@ -0,0 +1,35 @@
+# Generated by Django 3.2.20 on 2024-02-19 13:15
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("peachjam", "0118_auto_20240130_1221"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="peachjamsettings",
+ name="matomo_domain",
+ field=models.CharField(
+ blank=True,
+ help_text="Matomo domain (e.g. mysite.matomo.cloud)",
+ max_length=1024,
+ null=True,
+ verbose_name="matomo domain",
+ ),
+ ),
+ migrations.AddField(
+ model_name="peachjamsettings",
+ name="matomo_site_id",
+ field=models.CharField(
+ blank=True,
+ help_text="Matomo site ID (e.g. 2)",
+ max_length=10,
+ null=True,
+ verbose_name="matomo site ID",
+ ),
+ ),
+ ]
diff --git a/peachjam/models/settings.py b/peachjam/models/settings.py
index 31dc3f0fc..18709fd51 100644
--- a/peachjam/models/settings.py
+++ b/peachjam/models/settings.py
@@ -109,6 +109,20 @@ class PeachJamSettings(SingletonModel):
blank=True,
help_text=_("Enter one or more email addresses separated by spaces."),
)
+ matomo_domain = models.CharField(
+ verbose_name=_("matomo domain"),
+ max_length=1024,
+ null=True,
+ blank=True,
+ help_text=_("Matomo domain (e.g. mysite.matomo.cloud)"),
+ )
+ matomo_site_id = models.CharField(
+ verbose_name=_("matomo site ID"),
+ max_length=10,
+ null=True,
+ blank=True,
+ help_text=_("Matomo site ID (e.g. 2)"),
+ )
class Meta:
verbose_name = verbose_name_plural = _("site settings")
diff --git a/peachjam/templates/peachjam/layouts/main.html b/peachjam/templates/peachjam/layouts/main.html
index d79a266da..0b9ba27cd 100644
--- a/peachjam/templates/peachjam/layouts/main.html
+++ b/peachjam/templates/peachjam/layouts/main.html
@@ -34,6 +34,22 @@
});
{% endif %}
+ {% if PEACHJAM_SETTINGS.matomo_domain and PEACHJAM_SETTINGS.matomo_site_id %}
+
+ {% endif %}
{% endif %}