File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments