Skip to content

Commit

Permalink
analytics: Remove GA nodes if consent removed
Browse files Browse the repository at this point in the history
  • Loading branch information
lentinj committed Jan 21, 2025
1 parent ecf8f52 commit 7eca62a
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions client/lib/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ function ga() {
function statusEvent() {
var el;

if (!this.hasConsented()) {
return;
}
if (this.hasConsented()) {
if (!document.getElementById("script-google-analytics")) {
el = document.createElement("script");
el.setAttribute("id", "script-google-analytics");
el.setAttribute("async", "");
el.setAttribute("src", "https://www.google-analytics.com/analytics.js");

if (!document.getElementById("script-google-analytics")) {
el = document.createElement("script");
el.setAttribute("id", "script-google-analytics");
el.setAttribute("async", "");
el.setAttribute("src", "https://www.google-analytics.com/analytics.js");
document.body.appendChild(el);
}
} else {
window.ga = null;

document.body.appendChild(el);
el = document.getElementById("script-google-analytics");
if (el) {
el.remove();
}
}
}

Expand Down

0 comments on commit 7eca62a

Please sign in to comment.