Learn business growth with Google Analytics 4 Forums Google Analytics 4 Google Analytics: gtag log entries not being sent to server

  • Google Analytics: gtag log entries not being sent to server

    Posted by Aniket on 3 June 2023 at 11:40 pm

    Hey, I’ve got some issues with using GA4 gtag and not GTM. I’m calling gtag() and everything’s getting piled into the datalayer, but nope, it’s not reaching the Google Analytics server.

    So, I’ve put the code snippet in the HEAD of my page and it’s running fine. I’ve done the gtag('js', ...) and gtag('config', ...) thing as suggested. I see those popping up in the datalayer. Even the gtm.dom, gtm.load, and gtm.scrollDepth entries are there as they were added automatically.

    The same thing with adding an event like gtag('event', 'some event') – it’s there in the datalayer pile. But, that’s where the story stops. These items in datalayer are just not taking the flight to the GA server. There’s no traffic seen to the GA server in Chrome’s developer network view and the datalayer is not getting cleaned out.

    No errors on the console either.

    Now, I’m sure my GA tag is working as it should because logging events with the gtag SDK is working perfectly well. I see the events in GA. But hey, I want the full gtag thing to work too.

    Anyway, here’s how I’m logging events using the gtag SDK:

    fetch(https://www.google-analytics.com/mp/collect?measurement_id=<span class="hljs-subst">${GATag}</span>&api_secret=<span class="hljs-subst">${ApiSecret}</span>, {
    body: JSON.stringify({ client_id: ClientId, events: [gaEvent], user_id: _userId }),
    method: 'POST',
    });
    

    So, just wondering, do I need to do something specific to get gtag to send the data from dataLayer? Or maybe some tips on figuring this out? This is getting a little frustrating!

    Aaron replied 1 year, 5 months ago 3 Members · 2 Replies
  • 2 Replies
  • Ava

    Member
    8 June 2023 at 9:55 am

    It sounds like there might be a misconfiguration with your GA4 gtag setup. Consider re-checking your gtag code and hosting it on every page to capture the events properly. Also, try using “Tag Assistant” by Google to check if the events are being sent or received. If all else fails, it may possibly be due to a script conflict or a blocking extension in your browser.

  • Aaron

    Administrator
    22 June 2023 at 12:38 pm

    Usually, when you send events directly with gtag(), they’re automatically sent to Google Analytics without you needing to handle the dataLayer yourself. I think there might be a problem with your configuration. Check your code for correct measurement ID (GA xxxxx-x), and that you’re using gtag('config', 'GA_MEASUREMENT_ID') not datalayer.push(). If you’ve already tried that, you might want to reach out to GA’s support, cause this situation sounds unusual. Troubleshooting it might need deeper digging in your code or setup. Hang in there, you got this!

Log in to reply.