sessioncookiesgoogle-analyticscheckoutenhanced-ecommerce

Reinitialize Google Analytics session after termination (ecommerce checkout flow interruption)


Okay, here's the deal:

We have an interrupted checkout flow; people get to a certain step, and before we can continue, availability has to be verified. Verification takes 1 day minimum, usually more. After the verification process has been completed, the customer receives an email with an identifiable link (parameterized) to a age with payment options. Customers quite often pay days, weeks, sometimes even months after receiving this email.

Because of the verification stage, the session is cut short, while the follow-up steps are still part of the same checkout process. Now, we can push some sort of identifier into a custom dimension to link the two processes together somehow, but ideally I'd like the measurement to pick up where it left off; from confirmation step to payment page.

So in short:

Part 1: [SESSION START] Browse > Add to cart > Go to checkout > Request availability [SESSION END].

Part 2: [SESSION START] Payment options (landed from email) > Pay > Purchase finalized [SESSION END].

Is there a way to reactivate the terminated session? We'd rather not rely on browser cookies due to the (potentially) prolonged period between part 1 and 2. Could we save (the contents of) the GA cookies serverside and replace them in the browser once the user follows the parameterized link? (does the browser even allow such a thing? 🧐)


Solution

  • You have to save clientId and send the second hit with measurement protocol using clientId saved as value in cid parameter.

    With this JavaScript function you can get the clientId:

    function getClientId() {
      try {
        var trackers = ga.getAll();
        var i, len;
        for (i = 0, len = trackers.length; i < len; i += 1) {
          if (trackers[i].get('trackingId') === 'YOUR_UA-CODE_HERE') {
            return trackers[i].get('clientId');
          }
        }
      } catch(e) {}  
      return 'false';
    }
    
    console.log(getClientId());
    

    Here info about measurement protocol: https://developers.google.com/analytics/devguides/collection/protocol/v1/reference