CLASS
GA4CookieReader
public class GA4CookieReader
Utility class for reading Google Analytics 4 cookie values
Methods
readTrackingId(from:)
public static func readTrackingId(from cookieString: String? = nil) -> String?
Read GA4 tracking ID from cookies - Parameter cookieString: Optional cookie string to parse (if not provided, will attempt to read from system) - Returns: GA4 tracking ID or nil if not found
Parameters
| Name | Description |
|---|---|
| cookieString | Optional cookie string to parse (if not provided, will attempt to read from system) |
readSessionId(from:)
public static func readSessionId(from cookieString: String? = nil) -> String?
Read GA4 session ID from cookies - Parameter cookieString: Optional cookie string to parse (if not provided, will attempt to read from system) - Returns: GA4 session ID or nil if not found
Parameters
| Name | Description |
|---|---|
| cookieString | Optional cookie string to parse (if not provided, will attempt to read from system) |
readClientId(from:)
public static func readClientId(from cookieString: String? = nil) -> String?
Read GA4 client ID from cookies - Parameter cookieString: Optional cookie string to parse (if not provided, will attempt to read from system) - Returns: GA4 client ID or nil if not found
Parameters
| Name | Description |
|---|---|
| cookieString | Optional cookie string to parse (if not provided, will attempt to read from system) |
generateClientId()
public static func generateClientId() -> String
Generate a new GA4-compatible client ID - Returns: New client ID in GA4 format
generateSessionId()
public static func generateSessionId() -> String
Generate a new GA4-compatible session ID - Returns: New session ID in GA4 format