Learn business growth with Google Analytics 4 Forums Google Analytics 4 How to Monitor GTM Server-Side Response Codes and Bodies in Log Explorer of Google Cloud?

  • How to Monitor GTM Server-Side Response Codes and Bodies in Log Explorer of Google Cloud?

    Posted by Abdul on 11 May 2023 at 9:52 pm

    Hey there! I’m looking to set up an alert system for my GTM Server-Side stuff that flags me down when things go left – particularly keen on responses coming back from the endpoints with error codes.

    While noodling around in the debug view, I can see responses without a fuss. Check this out:

    here

    Jumping to the Log Explorer in Google Cloud, I find myself scratching my head because it’s harder to locate this information there. I do see the requests, though. Give this a look:

    here

    Strangely enough, it seems the response body doesn’t want to show itself. Have you any secret tricks up your sleeve to make this happen? I’m quite keen on having a constant eye on my tags to make sure they’re all pulling their weight properly.

    Roman replied 1 year ago 3 Members · 2 Replies
  • 2 Replies
  • Isaac

    Member
    21 May 2023 at 9:46 am

    If I’m understanding your predicament correctly, you’re keen on tracking the response codes from Google’s data collecting point. But, you know what’s quirky here? In most circumstances, we don’t really tailor our monitoring in this way, especially when they don’t even step into your territory.

    Usually, we keep things simple. We set up custom alerts in Google Analytics and it does the rest, notifying us if anything goes off course. A common alert we use is an unexpected drop in overall traffic compared to typical numbers – this way, we have a little birdie chirping in our ear when something’s amiss. You can find more details on setting up alerts [here](https://support.google.com/analytics/answer/9443595?hl=en).

    However, if you still feel like enhancing your surveillance radar, it’d be more practical to track response codes from your own site, just to see if any error codes pop up for your visitors. Generally, this could be done by tagging error pages that your webserver spits out in response to errors. This works well if you’re coupling server-side GTM with frontend tracking; if you aren’t, then it’s a job for your backend developers to hook you up with.

  • Roman

    Member
    23 May 2023 at 9:22 pm

    Indeed, the response body of your requests doesn’t currently appear on Google Cloud Log Explorer as a default option. This is a standard design due to privacy and costs, regarding logging everything by default. However, you can enable body logging in some Google Cloud services like Google Cloud Functions and Cloud Run by modifying the function’s code according to the function’s documentation.

    For instance, in GTM Server-Side, if the changes you make get compiled into JavaScript and executed, you can add custom logs to your code using the “console” object. After doing this, you’ll be able to see these logs in the Log Explorer under the “textPayload” field. Keep in mind, when adding extra logs, you have to watch out for User Privacy and Google’s usage costs (always depending on the amount of data you’re logging, and how long you retain these logs).

    On the other hand, for the error catching and alerting system, Google Cloud Logging offers the option to create metrics based on the logs and then set up alerts based on these metrics in Google Cloud Monitoring.

    Remember that making these changes should be carefully done, especially when it comes to user privacy and cost management.

Log in to reply.