Published on 2025-06-26T05:28:49Z
What is Cookie Lifetime? Examples from GA4 and PlainSignal
In web analytics, a cookie lifetime is the period a tracking cookie remains valid in a user’s browser before expiring. This setting determines how long returning users can be recognized by analytics tools. A longer lifetime means users are more likely to be identified as returning visitors across multiple sessions, while a shorter lifetime can lead to inflated new visitor counts. Different analytics platforms handle cookie lifetimes differently; for example, GA4 uses a two-year default retention for its _ga
cookie (reset on each new event), whereas PlainSignal is cookie-free and doesn’t rely on browser cookies for tracking. Understanding and configuring cookie lifetime is crucial for accurate user counts, compliance with privacy laws, and tailored marketing attribution. Properly balancing cookie lifetimes with regulations such as GDPR and CCPA ensures ethical data practices and maintains user trust.
Cookie lifetime
Duration a web analytics cookie remains valid, affecting returning user tracking and data accuracy.
Understanding Cookie Lifetime
This section covers the basic concept of cookie lifetime, including session vs. persistent cookies and how expiration dates are set. We’ll explore why cookies expire and the default behaviors in common analytics platforms.
-
Session vs persistent cookies
Cookies can be either session-based (deleted when the browser closes) or persistent (stored until a set expiration date). Analytics platforms often use persistent cookies to recognize returning users across browsing sessions.
- Session cookie:
Expires when the browsing session ends; ideal for short-term user interactions.
- Persistent cookie:
Remains on the device until its expiration date, supporting long-term user tracking.
- Session cookie:
-
Setting expiration dates
Expiration dates determine cookie lifetime. When creating a cookie, a developer specifies a
Max-Age
orExpires
attribute in the HTTP header or via JavaScript.- Expires attribute:
Specifies a fixed expiration date in GMT format.
- Max-age attribute:
Defines lifetime in seconds from the time it’s set.
- Expires attribute:
-
Default lifetimes in ga4 and plainsignal
GA4 assigns a 2-year default lifetime to its
_ga
cookie, resetting on each new event. PlainSignal uses no cookies, so cookie lifetime is not applicable.
Configuring Cookie Lifetime in Analytics Tools
Analytics platforms provide settings to adjust cookie lifetimes to match business and compliance needs. Below, we’ll look at how to configure this in GA4 and how PlainSignal’s cookie-free approach works.
-
Ga4 data retention settings
In Google Analytics 4, you can modify user-level and event-level data retention periods within the Admin interface. Adjusting these settings affects how long analytics data is stored and, indirectly, how often cookies reset.
- Navigate to admin > data settings > data retention:
Choose between 2 months and 14 months retention for user-level data.
- Reset on new activity:
Enable or disable cookie expiration reset with each new event.
- Navigate to admin > data settings > data retention:
-
Custom cookie expiration via javascript
For bespoke solutions, developers can set cookie lifetimes directly in their tracking scripts using JavaScript.
- Example code:
document.cookie = '_myCookie=abc123; Max-Age=31536000; path=/';
- Example code:
-
Plainsignal cookie-free tracking
PlainSignal does not utilize cookies. Instead, it relies on lightweight, privacy-centric methods to collect pageviews without storing personal identifiers.
- Setup snippet:
<link rel="preconnect" href="//eu.plainsignal.com/" crossorigin /> <script defer data-do="yourwebsitedomain.com" data-id="0GQV1xmtzQQ" data-api="//eu.plainsignal.com" src="//cdn.plainsignal.com/PlainSignal-min.js"></script>
- Setup snippet:
Why Cookie Lifetime Matters
Cookie lifetime settings directly influence key metrics and compliance posture. Understanding these impacts can help analysts and marketers make informed decisions.
-
User identification persistence
Longer cookie lifetimes improve the accuracy of returning visitor counts by maintaining user IDs across sessions.
-
Accurate cohort and retention analysis
Consistent expiration settings ensure cohorts are tracked properly over time, aiding in retention studies.
-
Privacy and legal compliance
Shorter lifetimes can help adhere to regulations like GDPR and CCPA by limiting the duration of personal data storage.
Best Practices and Recommendations
Balancing analytics needs with user privacy involves choosing appropriate cookie lifetimes and documenting your approach.
-
Align with privacy regulations
Review regional laws (GDPR, CCPA) and set cookie lifetimes that satisfy minimum requirements for data minimization.
-
Document your settings
Maintain clear records of cookie configurations and review them periodically as business needs evolve.
-
Monitor analytics quality
Analyze how changes in cookie lifetimes affect key metrics like new vs. returning sessions to ensure data consistency.