1

How can I glue together two episodes into the one GA4 session starting from add_to_cart and ending with purchase to track as one user journey?

Stages now:

  1. Visitor is on the website with GTM(+GA4) where adds an item to the cart and proceeds to the checkout. I can see both add_to_cart and begin_checkout events in the tag assistant console and GA4 debug view.

  2. Fetch client_id and session_id with gtag function and combine a success link for the acquiring system to return the visitor/customer to our website when payment is completed.

gtag('get', 'G-xxxxxxxxxx', 'session_id', (session_id) => window.ga4_sid = session_id);
gtag('get', 'G-xxxxxxxxxx', 'client_id', (client_id) => window.ga4_cid = client_id);
  1. Redirect to the 3rd party webpage where visitor makes a payment.

  2. Visitor is back within URL combined at the second stage which consists two parameters session_id and client_id.

window.ga4_sid = url_parameters.get('ga4_sid');
window.ga4_cid = url_parameters.get('ga4_cid');

4a) Restore GA4 session and continue original flow.

gtag('config', 'G-xxxxxxxxxx', {'client_id': window.ga4_cid, 'session_id': window.ga4_sid});

4b) Push purchase event to the data layer. I can see the event just in the tag assistant flow but not in the GA4 debug view

Why GA4 does not recognise this purchase as the final event of the same journey?

1 Answer 1

2

Using GTM, and yet still calling gtag directly is not recommended. GTM does the same, but under the hood and you're very likely to conflict with it.

You don't need to do anything to "restore" the user session. The session info is in cookies. When the user's back from the third party, it will use the existing cookies and continue the session and the client properly.

What you may need is cross-domain tracking. Which you configure in your GA4 property. The trick, however, is that the third party you want the purchases from has to load the same GA4 property code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.