Learn business growth with Google Analytics 4 Forums Google Analytics 4 How to Integrate Google Analytics 4 into a .pug Template

  • How to Integrate Google Analytics 4 into a .pug Template

    Posted by Sofia on 17 June 2022 at 4:49 am

    Hey guys, I’m just trying to get my head around the Google Analytics 4 integration with a .pug template file. You see, this coding thing, including Google Analytics, is all very new to me, so I reckon there’s a chance I’ve missed something glaringly obvious, but the mistake is eluding me for now.

    I’ve been doing my homework and stumbled upon this old conversation from a few years back. I tried to follow the “2019 GTag Update” solution that was shared on August 19, 2016. The thing is, I can’t seem to get Google Analytics to kick off. I’m stuck with this pesky notice popping up in my Google Analytics property telling me that it isn’t collecting any data.

    What’s puzzling me is that when I double-check my site and examine the HTML, everything seems right on the money and looks exactly like what Google Analytics asks for in their tagging instructions.

    Would really appreciate if someone can shed some light on this! Here’s the bit of code:

        // Google tag (gtag.js)
    script(async='' src='https://www.googletagmanager.com/gtag/js?id=G-**********')
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'G-**********');
    title= title


    Brooke replied 10 months, 4 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • Jackson

    28 September 2022 at 4:04 am

    You’re trying to integrate Google Analytics 4 with a .pug template file and despite following the instructions, you’re receiving a notice that Google Analytics isn’t collecting any data. In essence, it sounds like the code you’ve implemented has not activated Google Analytics on your website. This could be due to a variety of reasons. It could be that the code you’ve implemented isn’t firing correctly, or there may be an issue with the settings in your Google Analytics account. It would be beneficial to verify that the Google Analytics ID you have used in your code is correct. Additionally, do more checks with different tools to validate that the GA code is not firing. Sometimes, it might take some time for the data to start appearing in the GA console so ensure that you have waited for enough time as well. If the problem persists, consider reaching out to a professional developer to look at your problem, perhaps there’s something you might have overlooked considering this is a new territory for you.

  • Brooke

    3 March 2023 at 6:21 pm

    The problem seems to be with how Google Analytics is being integrated with your PUG file. If you’re getting a notification from Google Analytics saying it isn’t collecting any data, it’s possible that the tracking code might have been incorrectly installed or isn’t functioning properly. Sometimes, it can take up to 24 hours for data to begin appearing in Google Analytics after the tracking code has been installed. The code you’ve included looks fine, but you may want to double-check the G-********** part, which should represent your Google Analytics’ unique tracking ID. If the problem persists, consider getting further assistance to resolve the error in your coding.

Log in to reply.