I'm currently working on a Server-Side Google Tag Manager (sGTM) setup where I aim to handle user consent checks on the server side.
Setup Details:
Consent Management: Handled by UserCentrics.
GA4 Configuration: There's a GA4 config tag that sends a
page_viewevent to sGTM on adataLayerupdate event named"consent_status".
Problem Description:
Initial Visit:
When a user arrives at the website, the
dataLayeris initialized with default values, triggering the firstconsent_statusevent.The website sends a
page_viewto sGTM, which fires a tag to send data to an internal API.At this point, no consent has been given yet, and we do not store personalized data.
After Consent is Granted:
When the user gives consent, the GA4 config tag fires a
page_viewevent again without waiting for theconsent_statusevent.However, sGTM fires the tags that should send data to GA4, Google Ads, etc., but there is no outgoing traffic.
Then the
consent_statusevent occurs again, this time with updated consent (all granted).The GA4 config tag sends out the
page_viewevent again, but here the info about thefirst_visitis missing.At this point, the tags on the sGTM side fire as expected.
Conclusion:
- This means that three
page_viewevents arrive at sGTM, but only the first (without consent) and the third (with consent update viadataLayer) are handled appropriately by sGTM by sending outgoing requests to Google Analytics. The secondpage_viewevent fires tags but results in no outgoing traffic.
- This means that three
Attempted Solution:
- The only workaround I've found is to create a trigger that fires the GA4 config tag only when consent has been granted. But this isn't our preferred approach—we want the consent check to occur on the server side, not the client side.
Expected Behavior:
- I expect sGTM to react to every GA4 tag appropriately and send a request to the Google Analytics API, handling consent on the server side.
Questions:
Has anyone faced the same issue and knows how to resolve it?
Could there be something I've missed in my configuration?
Is there any additional information you need that I haven't provided?
Any insights or suggestions would be greatly appreciated!
EDIT:
So we came up with following solution. It seems to work for now.
The Google Tag now fires only on two events
- consent_status - when the consent mode is pushed to the datalayer AND the consent is updated
- normally the consent_status is fired 2 times. 1st when the consent is initialized and 2nd after the user has consent granted oder denied.
- user_engagement - when the datalayer gets the consent->update push. The user_engagement event is the situation when the user clicks the cookie banner.
