top of page

Session ID is missing from the Google Analytics's Big Query default data?

  • Writer: Data Variables
    Data Variables
  • Jul 10, 2023
  • 2 min read

Updated: Aug 15, 2023


In Google Analytics 4, the session ID is a unique identifier that is generated for each user on each visit to your website. The session ID is used to track the user's activity during a session. The session ID is also used to associate events with the same user across multiple devices and browsers.


The session ID is a 12-character hexadecimal string. The first 8 characters of the session ID are random, and the last 4 characters are a timestamp. The timestamp is in the format YYYYMMDDHHMMSS.

The session ID is stored in a cookie named _ga_. The cookie is set by the Google Analytics JavaScript library. The cookie is valid for 30 minutes.


If the user leaves your website and then comes back within 30 minutes, the same session ID will be used. This allows Google Analytics to track the user's activity as a single session.


If the user leaves your website and then comes back after 30 minutes, a new session ID will be generated. This is because Google Analytics considers each visit to your website as a new session.


You can use the session ID to track the user's progress through your website through Google Tag Manager. For example, you could use the session ID to track the pages that the user visited, the events that the user triggered, and the time that the user spent on each page.




  function () {
    //var sessionID = document.cookie.match(/ga_session_id\=([a-zA-Z0-9\-]+)/)[1];
    var pattern = /_ga_KSNTXXXXX=GS\d\.\d\.(.+?)(?:;|$)/;
	var match = document.cookie.match(pattern);
	var parts = match ? match[1].split(".") : [];
     console.log('parts: ' + parts)
    return parts.shift();
}


This code first creates a regular expression pattern to match the Google Analytics session ID cookie. The pattern looks for a cookie named _ga_ followed by a 12-character ID, two digits, and a period. The two digits after the period represent the session number.


Then create a Custom Dimension in GA4 console so that we can pass it through Google Tag Manager and it will be captured in the Google Big Query




I hope this helps!


Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page