Skip to content

Commit 0234896

Browse files
Merge pull request #159 from luk27official/main
Fix Google Analytics
2 parents 6f33464 + 8e09268 commit 0234896

2 files changed

Lines changed: 13 additions & 17 deletions

File tree

frontend/build/webpack.common.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,7 @@ function generateGoogleAnalytics() {
124124
if (devMode || ga === undefined || ga === "") {
125125
return "''";
126126
}
127-
return `'
128-
<script async src=\\"https://www.googletagmanager.com/gtag/js?id=${ga}\\"></script>
129-
<script>
130-
window.dataLayer = window.dataLayer || [];
131-
function gtag() {
132-
window.dataLayer.push(arguments);
133-
}
134-
gtag(\\"js\\", new Date());
135-
gtag(\\"config\\", \\"${ga}\\", {\\"anonymize_ip\\": true});
136-
</script>
137-
'`.replaceAll("\n", " ");
138-
// Result must be a one-liner else we get compilation error.
127+
128+
// we return only the GA env variable, the rest is handled in the template file
129+
return `'{ga}'`;
139130
}

frontend/client/partials/ga.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<script type="module" src="./assets/scripts/cookieconsent-config.js"></script>
2-
<script
3-
type="text/plain"
4-
data-category="analytics">
5-
@googleAnalytics()
6-
</script>
2+
<script type="text/plain" data-category="analytics">
3+
window.dataLayer = window.dataLayer || [];
4+
function gtag() {
5+
window.dataLayer.push(arguments);
6+
}
7+
gtag("js", new Date());
8+
gtag("config", "@googleAnalytics()", {"anonymize_ip": true});
9+
</script>
10+
<script type="text/plain" data-category="analytics" async
11+
src="https://www.googletagmanager.com/gtag/js?id=@googleAnalytics()"></script>

0 commit comments

Comments
 (0)