Assigning Purchases to Other Users in Google Analytics UABy Martijn Scheijbeler Published May 10, 2022 Last Modified June 1, 2023
Sometimes, you want to assign specific user interactions to a different user.
There are many cases where you want to send an event for user X while user Y performs the action. But it’s important that you can save this information to the right user.
In our case, we ran into the use case where an RV owner needs to accept a booking. We consider this an actual purchase (transaction in GA) only after the approval takes place. According to regular logic, the RV owner would get the purchase attributed to its session in Google Analytics. In the end, that user goes through the steps in the interface and confirms the transaction.
Marketing <> Google Analytics Logic
This doesn’t work for Marketing, though. We did our best to acquire the renter, and they’re the ones purchasing. According to Google Analytics, we’d fire an e-commerce purchase on behalf of the owner. What this messes up is channel attribution & performance measurement of our campaigns. In this case, the owner’s path is likely not touching any paid or true marketing channels but either direct or email.
In summary, the wrong user would get credit for the conversion, which could cause issues with our ROAS measurement of marketing channels.
Switching Client IDs & Leveraging User IDs
When Google Analytics is loaded, it will set the client ID value in the _ga cookies in your browser. This value (the client id) will tie events → pageviews → sessions together and be seen as one user (in combination with the userId value, obviously).
So what we’re doing is pretty simple to change this behavior:
- Whenever a user goes through the checkout funnel and creates an account, we save their Google Analytics Client IDs (for GA4 and UA) to their profile.
- When user X confirms the purchase, we send an event to Tag Manager with the purchase context, including the impacted data from user Y.
- Instead of directly firing the hit to Google Analytics, we swap out the client ID and userID from user X to user Y so that the actual purchase will get attributed to that hit. You need to mimic a session ID.
- Google Analytics will now stitch this purchase to user Y instead of user X. You can choose what you want to fire for user Y.
→ Setting the Client ID in Google Analytics 4
→ Setting the Client ID in Google Analytics with gtag.js
Where possible, ensure you’re already sending a userID to Google Analytics to ensure the interactions can be truly tied back to the same user.