Skip to content

Commit 6ff5a3a

Browse files
committed
feat: Migrate to gtag and support GA4
Signed-off-by: Sean Young <[email protected]>
1 parent c78bb69 commit 6ff5a3a

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

public/views/shared/ga.ejs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
<% if(typeof GA !== 'undefined' && GA) { %>
2-
<script nonce="<%= cspNonce %>">
3-
(function (i, s, o, g, r, a, m) {
4-
i['GoogleAnalyticsObject'] = r;
5-
i[r] = i[r] || function () {
6-
(i[r].q = i[r].q || []).push(arguments)
7-
}, i[r].l = 1 * new Date();
8-
a = s.createElement(o),
9-
m = s.getElementsByTagName(o)[0];
10-
a.async = 1;
11-
a.src = g;
12-
m.parentNode.insertBefore(a, m)
13-
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
14-
15-
ga('create', '<%= GA %>', 'auto');
16-
ga('send', 'pageview');
2+
<script nonce="<%= cspNonce %>" async src="https://www.googletagmanager.com/gtag/js?id=<%= GA %>">
3+
</script>
4+
<script>
5+
window.dataLayer = window.dataLayer || [];
6+
function gtag(){dataLayer.push(arguments);}
7+
gtag('js', new Date());
8+
gtag('config', '<%= GA %>');
9+
gtag('event', 'page_view');
1710
</script>
1811
<% } %>

0 commit comments

Comments
 (0)