A GA4 purchase tracking issue appeared when purchase events were sent through the Measurement Protocol. The events were collected, but source and medium attribution were not correctly assigned.
The challenge
For ecommerce and performance marketing reporting, purchase attribution is critical.
When GA4 cannot connect a purchase event to the correct session, source or medium, the business loses visibility into which campaigns and channels are actually driving revenue.
The problem was connected to the session_id. After updating the Consent Mode
template, the previous method used to access the gtag() function was no longer
available, which meant the setup could no longer retrieve the session ID required for proper attribution.
What I investigated
- GA4 purchase events
- Measurement Protocol attribution
session_idavailability- GTM custom templates
- Consent Mode template updates
- DataLayer events
- Source / medium reporting in GA4
The solution
I implemented a new way to retrieve the GA4 session ID using the custom template GTAG GET API.
This template requests the session ID from GTAG through the API and pushes a
gtagApiGet event into the dataLayer.
The event contains gtagApiResult.session_id, which can then be used for the
purchase event attribution flow.
The implementation was adjusted so the session ID could be stored and used correctly for Measurement Protocol purchase events.
Result
After the solution was implemented and tested, GA4 transaction attribution by source / medium returned to the expected level compared with the period before the issue appeared.
This restored confidence in purchase reporting and helped the business make better decisions based on accurate campaign and channel performance.