managed-components/google-analytics-4

Discussion: Use google measurement protocol for ecommerce events (enhanced compatibility with HTTP Events API)

Opened this issue · 2 comments

agcty commented

Currently, the google managed component doesn't use the measurement protocol for tracking ecommerce events. However, it seems particularly useful for exactly that in server-side environments.

Current state

Right now, when using the HTTP Events API, the MC will return a few client fetch requests which you then have to manually execute on the client side, if you don't do that, the checkouts, etc won't be tracked.

Proposed solution

While you can definitely return the response object of the tracking call and forward it to the client, this seems a little sub-optimal as there is an actual API from Google that you can use for exactly this scenario (and only this scenario, the measurement protocol doesn't allow you to send pageviews for example). Instead of client.fetch, manager.fetch could be called with the ecommerce request payload. This would also be more resilient against ad blockers.

I know that a lot of other questions would have to be answered to assess if this is feasible. This issue is to identify what these are and to start a discussion about using the measurement protocol in general.

Hello @agcty , and thanks for starting this discussion!

Right now, when using the HTTP Events API, the MC will return a few client fetch requests which you then have to manually execute on the client side, if you don't do that, the checkouts, etc won't be tracked.

To which client.fetch() calls are you referring to exactly please? I can see two: one is related to GA Audiences, and the other one for DoubleClick. Both, to my knowledge, could be ignored if you wish to go only serverside, and you should still be able to see data coming in in GA4. It will probably affect anything related to G Ads conversion tracking and retargeting, as these still rely on 3rd party cookies.

Sorry for the delayed response! Yes, there are two fetches that need to be called: GA Audiences and DoubleClick. However, I believe you also need to execute some client side code that the MC sends back for the event to be tracked successfully, the two fetches are not sufficient. Ideally, I wouldn't want to execute that code on the client (e.g via eval), I believe using the measurements api would solve that.

For more context, this is our use case:
We have a checkout page where a customer is redirected to after a successful payment. Ideally, we would use the HTTP Events API to track the purchase event when the success page is sending its response. We do this in conjunction with a cookie "collect" that is set to true when redirecting to the strip checkout and set to false when the user lands on the success page. This way, we make sure the purchase event is recorded exactly once. We also use a few other MCs such as TikTok and Facebook, both of which I believe are fully using their respective server side APIs. We don't experience issues there and tracking fully server side just works out of the box. Google however seems to be a special case and doesn't work, again because I think you actually need to run some client side code as well instead of just a fetch call.

I am not sure what to make of this because I think the MC would potentially need to be rearchitected in parts to use the Measurements Protocol. However this also poses challenged as not everything can be collected over the MP: https://developers.google.com/analytics/devguides/collection/protocol/ga4#full_server-to-server.

I guess you could work around that with blocking triggers and calling the Measurement Protocol directly yourself. Maybe you could even have a property in the MC that forces the MP in some cases. Again, don't know the best solution or if this is even worthy of discussing.