Skip to content

Commit 7bd4709

Browse files
Add Google analytics to website
1 parent 5ecb190 commit 7bd4709

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

website/eleventy.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ export default function(eleventyConfig) {
134134
.replace("Disallow: /assets/", "Allow: /assets/images/\nDisallow: /assets/js/\nDisallow: /assets/css/");
135135
});
136136

137+
eleventyConfig.addTransform("googleAnalytics", function(content) {
138+
if (!this.page.outputPath?.endsWith(".html")) {
139+
return content;
140+
}
141+
const gaSnippet = [
142+
' <!-- Google tag (gtag.js) -->',
143+
' <script async src="https://www.googletagmanager.com/gtag/js?id=G-F1RPEMKELY"></script>',
144+
' <script>',
145+
' window.dataLayer = window.dataLayer || [];',
146+
' function gtag(){dataLayer.push(arguments);}',
147+
" gtag('js', new Date());",
148+
" gtag('config', 'G-F1RPEMKELY');",
149+
' </script>',
150+
'',
151+
].join("\n");
152+
return content.replace("</head>", gaSnippet + "</head>");
153+
});
154+
137155
eleventyConfig.addTransform("customScripts", function(content) {
138156
if (!this.page.outputPath?.endsWith(".html")) {
139157
return content;

0 commit comments

Comments
 (0)