Ga4CookieReader
in package
Utility class to help read GA4 tracking and session IDs from cookies
Table of Contents
Constants
- DEFAULT_GA4_SESSION_COOKIE = '_ga_*'
- DEFAULT_GA4_TRACKING_COOKIE = '_ga'
- Default cookie names for GA4
Methods
- readAll() : array<string|int, mixed>
- Read both GA4 tracking ID and session ID from cookies
- readSessionId() : string
- Read GA4 session ID from cookie
- readTrackingId() : string
- Read GA4 tracking ID from cookie
Constants
DEFAULT_GA4_SESSION_COOKIE
public
mixed
DEFAULT_GA4_SESSION_COOKIE
= '_ga_*'
DEFAULT_GA4_TRACKING_COOKIE
Default cookie names for GA4
public
mixed
DEFAULT_GA4_TRACKING_COOKIE
= '_ga'
Methods
readAll()
Read both GA4 tracking ID and session ID from cookies
public
static readAll([string $trackingCookieName = null ][, string $sessionCookieName = null ]) : array<string|int, mixed>
Parameters
- $trackingCookieName : string = null
-
Optional custom tracking cookie name
- $sessionCookieName : string = null
-
Optional custom session cookie name pattern
Return values
array<string|int, mixed> —An array with 'tracking_id' and 'session_id' keys
readSessionId()
Read GA4 session ID from cookie
public
static readSessionId([string $cookieName = null ]) : string
Parameters
- $cookieName : string = null
-
Optional custom cookie name pattern
Return values
string —The session ID or null if not found
readTrackingId()
Read GA4 tracking ID from cookie
public
static readTrackingId([string $cookieName = null ]) : string
Parameters
- $cookieName : string = null
-
Optional custom cookie name
Return values
string —The tracking ID or null if not found