sessiongoogle-analyticsgoogle-tag-managerevent-tracking

Does Client ID work in concert with Session Unification?


I have a website where users will typically do something like:

  1. Arrive from social media (Browser receives a _ga Client ID cookie)
  2. Look around (GA Pageviews)
  3. Churn (GA Session times out)
  4. Come back days later and sign up (GA Pageviews + CreateUser Event)
  5. Create a project (GA Pageviews + CreateProject Event)

At 4 and 5, my server sends Events which include User ID, e.g.: {ec: "Event Category", ea: "Event Action", uid: '1234'} to GA.

On the Google Analytics website, in a View with User-ID reports enabled, I can then inspect event #5 and (thanks to Session Unification) and see where the user arrived from when returning to the site at #4.

However, what I really want to know is: Where did the user arrive from when visiting my website for the first time, at #1?

This should, at least in theory, be possible since the user accepted a Client ID cookie which has been with the browser ever since #1.

My question is: If I manage to pass the Client ID to the server at #4 and #5, and create those events with the Client ID in addition to the User ID, will I then be able to divine where the user first arrived from?

The reason I'm asking, and not just trying this out, is because getting the Client ID passed to the server (the one which creates the Events) will take me a couple of days to get into production. And understanding things up front is always an advantage.

Any insight greatly appreciated!


Solution

  • If you pass the clientId (in addition to the userId) to Google Analytics in a custom dimension at the user level, you can get everything that user did (or better, that cookie).

    Attention that if the user change the browser or device you lose track of it (because he has a new cookie, so a new user for Google Analytics). You can reconcile their sessions with the userId, but the userId does not reconcile the sessions closed in the past unless the userId has also been previously associated with the same cookie.

    Anyway, you can get clientId in Universal Analytics with this code:

    var trackers = ga.getAll();
    var i, len;
    for (i = 0, len = trackers.length; i < len; i += 1) {
      if (trackers[i].get('trackingId') === 'UA-XXXXXXX-XX') {
        console.log(trackers[i].get('clientId'));
      }
    }
    

    If you are using gtag, it is more simple to pass that information directly in a custom dimension:

    gtag('config', 'UA-XXXXXXX-XX', {
      'custom_map': {
        'dimensionX': 'clientId'
      }
    });
    

    Example about this sentence "the userId does not reconcile the sessions closed in the past unless the userId has also been previously associated with the same cookie" refering to "userId sent to Google Analytics in a custom dimension at the user level (scope)":

    If I have 5 sessions:
    1) in the first I do not send the userId (as custom dimension at the user level)
    2) in the second I do not send it
    3) in the third I send it
    4) in the fourth I do not send it
    5) in the fifth I do not send it
    

    In the report I can see userId value for sessions 3, 4 and 5 but not for 1 and 2 because has not been previously associated.

    For more details about actual userId (not mentioned in my answer), you can read official documentation "Data collection begins after implementation": https://support.google.com/analytics/answer/4574780?hl=en