Understanding how Alpha Insights manages sessions is crucial for accurate attribution and data analysis. This guide explains session lifecycle, cookie management, timeout handling, and how orders are attributed to traffic sources.
A session represents a continuous period of visitor activity on your website. It includes all pages viewed, events triggered, and actions taken from arrival to departure.
Key characteristics:
localStorage, with first-party cookies written at cart/checkout (or immediately)Example session:
10:00 AM - Visitor lands on homepage (session starts)
10:02 AM - Views product category page
10:05 AM - Clicks on product
10:06 AM - Views product page
10:08 AM - Adds to cart
10:10 AM - Leaves site
10:40 AM - Session expires (30 minutes after last activity)
If visitor returns at 10:45 AM, a NEW session starts.
What happens:
localStorage for an existing session ID and last-activity timestamplocalStorage (wpd_ai_v2_* keys). Cookies are written on cart/checkout in Checkout Only mode:
wpd_ai_session_id - Session identifier (30-minute inactivity expiry)wpd_ai_landing_page - Landing URL with query params (attribution window)wpd_ai_referral_source - Document referrer (attribution window)wp_wpd_ai_session_data table)Database record created:
{
"session_id": "wpd5f4dcc3b5aa765a123456789",
"ip_address": "192.168.1.1",
"landing_page": "https://store.com/products?utm_source=facebook&utm_campaign=spring",
"referral_url": "https://www.facebook.com/...",
"user_id": 0,
"date_created_gmt": "2024-03-15 10:00:00",
"date_updated_gmt": "2024-03-15 10:00:00",
"device_category": "mobile",
"operating_system": "iOS",
"browser": "Safari",
"device": "mobile",
"additional_data": "{...}"
}
What happens:
localStorage for a session IDlocalStoragedate_updated_gmt set to current timeImportant: Landing page and referral URL do NOT change during a session. They are set once at the start of the attribution period. A later session can reset them if you use Session Only, the window expires, or Override Attribution on New UTM Visit is on and the URL has campaign parameters. See Attribution Window.
During session, events are tracked:
All events share the same session_id:
// Example events in same session
session_id: wpd5f4dcc3b5aa765a...
- page_view (homepage) - 10:00:00
- page_view (products) - 10:02:15
- product_click (item 123) - 10:05:22
- page_view (product 123) - 10:05:23
- add_to_cart (product 123) - 10:08:14
- page_view (checkout) - 10:09:45
- init_checkout - 10:09:45
- transaction (order 789) - 10:11:30
Session expires when:
localStorage / cookies) manuallylocalStorage typically persists)What happens at expiration:
date_updated_gmtdate_updated_gmt - date_created_gmtIf visitor returns after expiration:
Reasons for 30-minute timeout:
What 30 minutes means:
Developer note: Timeout can be customized via filter:
// Change to 60 minutes
add_filter('wpd_session_timeout_seconds', function($timeout) {
return 60 * 60; // 60 minutes
});
Session identity lives in localStorage first (keys prefixed with wpd_ai_v2_). Cookies below are written on cart/checkout in Checkout Only mode, or on first visit in Immediate mode. See Cache-Safe Event Tracking.
1. wpd_ai_session_id
| Property | Value |
|---|---|
| Purpose | Unique session identifier |
| Format | wpd + timestamp + random string (generated in JavaScript) |
| Example | wpd1712345678901abcxyz |
| Expiry | 30 minutes from last activity |
| Domain | Your site domain |
| Path | / (site-wide) |
| Secure | No (works on HTTP and HTTPS) |
| HttpOnly | No (accessible to JavaScript) |
| SameSite | Lax (default) |
Generation (JavaScript):
function generateSessionId() {
return 'wpd' + Date.now() + Math.random().toString(36).substring(2, 12);
}
2. wpd_ai_landing_page
| Property | Value |
|---|---|
| Purpose | Store first page visited |
| Format | Full URL including query parameters |
| Example | https://store.com/shop?utm_source=facebook |
| Expiry | Attribution window (Session Only, or 1–30 days) |
| Set once | Yes, until the window expires or a reset rule applies |
| Used for | Order attribution, UTM tracking |
Why full URL with query params?
3. wpd_ai_referral_source
| Property | Value |
|---|---|
| Purpose | Store where visitor came from |
| Format | Full referrer URL |
| Example | https://www.google.com/search?q=... |
| Expiry | Attribution window (Session Only, or 1–30 days) |
| Set once | Yes, until the window expires or a reset rule applies |
| Used for | Traffic source classification |
Special handling:
document.referrer in the browser10:00:00 - Visitor lands on site
→ Cookies set with expiry 10:10:00
10:03:00 - Visitor views another page
→ Cookie expiry updated to 10:13:00
10:07:00 - Visitor adds to cart
→ Cookie expiry updated to 10:17:00
10:10:00 - Visitor leaves site
→ Cookies still valid until 10:20:00
10:15:00 - Visitor returns
→ Cookies still exist (within 10 min)
→ SAME session continues
→ Cookie expiry updated to 10:25:00
10:25:00 - Visitor idle
→ Cookies expire at 10:25:00
10:30:00 - Visitor returns
→ Cookies gone (expired)
→ NEW session starts
For complete privacy and GDPR compliance information, see the Privacy & Security guide.
First-party cookies:
GDPR considerations:
Best practice:
When a visitor places an order, Alpha Insights permanently links the order to the session's traffic source. This enables profit tracking by source in reports. To understand profit calculations, see How Alpha Insights Works.
Step-by-step:
woocommerce_checkout_order_processed hook fires_wpd_ai_landing_page = landing URL_wpd_ai_referral_source = referrer URL_wpd_ai_meta_campaign_id = FB campaign ID (if present)_wpd_ai_google_campaign_id = Google campaign ID (if present)Result: Order permanently attributed to traffic source, even if cookies expire or session ends.
How long does attribution last?
Alpha Insights supports a configurable attribution window (Session Only, or 1–30 days). Referral URL and landing page are stored when the visitor first arrives and expire after that period from first set. Multi-day options can extend beyond a single session. Session Only resets them whenever a new session starts.
For full details, see Attribution Window.
Example scenarios:
Scenario 1: Quick purchase (within session)
Day 1, 10:00 AM - Click Facebook ad → Land on product page
Day 1, 10:05 AM - Add to cart → Checkout → Complete purchase
Result: Order attributed to Facebook (original landing page)
Scenario 2: Later purchase inside a 3-day window
Day 1, 10:00 AM - Click Facebook ad → Browse → Leave
Day 3, 2:00 PM - Direct visit (type URL) → Complete purchase
Result: Order attributed to Facebook (first-touch still inside the window)
Scenario 3: New session with campaign parameters (Override on)
Day 1, 10:00 AM - Facebook ad → Browse → Leave (session expires)
Day 2, 9:00 AM - Google ad with gclid → Purchase
Result: Order attributed to Google (new session + tracking params replaced first-touch)
Alpha Insights uses first-touch within the Attribution Window:
Why this model?
Limitations:
Workaround: Multi-session analysis
Use Website Sessions report to see full customer journey:
Example multi-session analysis:
Session 1 (Day 1):
- Source: Facebook
- Landing: product page
- Events: product_page_view, left site
- Order: No
Session 2 (Day 2):
- Source: Organic (Google search)
- Landing: product page
- Events: page_view, add_to_cart, left site
- Order: No
Session 3 (Day 3):
- Source: Direct
- Landing: cart page
- Events: viewed_cart, init_checkout, transaction
- Order: Yes (Order #789)
Attribution with a 3-day first-touch window: Facebook (unless a later UTM session overrode it)
Reality: Facebook awareness → Google consideration → Direct conversion
When Only Track & Report On Engaged Sessions is enabled (Alpha Insights → Settings → General Settings → Alpha Analytics & Event Tracking), Alpha Insights treats a session as “engaged” only after the visitor has interacted with the page (e.g. click, touch, or scroll). This reduces noise from bots and accidental page loads.
Engagement is detected on the frontend by the event tracking script:
As soon as one of these occurs, the session is marked as engaged for the rest of that visit.
page_view event is not sent until the user has engaged. Once they click, touch, or scroll, the page view is sent and the session is marked engaged.wpd_ai_engaged_session is set when engagement is detected (value 1).engaged_session flag (0 or 1). It is set when the first page view is stored (after engagement) and can be updated later if engagement is detected on a subsequent request.When the setting is True:
engaged_session = 1 or duration > 0).When the setting is False, every page load sends a page view immediately and all sessions are tracked regardless of interaction.
| Setting | First page view | Reporting |
|---|---|---|
| Only track engaged = False | Sent on page load | All sessions included |
| Only track engaged = True | Sent after first click/scroll/touch | Only engaged sessions (or sessions with duration > 0) included |
Formula:
session_duration = date_updated_gmt - date_created_gmt
Measured in: Seconds (converted to minutes in reports)
Example:
date_created_gmt: 2024-03-15 10:00:00
date_updated_gmt: 2024-03-15 10:08:30
session_duration: 510 seconds (8 minutes 30 seconds)
Important notes:
Calculating average session duration:
SELECT AVG(TIMESTAMPDIFF(SECOND, date_created_gmt, date_updated_gmt)) as avg_duration_seconds
FROM wp_wpd_ai_session_data
WHERE date_created_gmt >= DATE_SUB(NOW(), INTERVAL 30 DAY);
Unique visitors (users):
Sessions:
Relationship:
Users ≤ Sessions
Example:
- 1 user visiting 3 times = 3 sessions
- 10 users visiting once = 10 sessions
- 5 users visiting twice = 10 sessions
If user is logged in:
user_id field populated in session dataBenefit for repeat customers:
Limitation: Alpha Insights does NOT track cross-device by default
Example:
User on phone:
- Session 1 (mobile, IP: 192.168.1.100)
- Browse, add to cart, leave
User on laptop:
- Session 2 (desktop, IP: 10.0.0.50)
- Different IP, different cookies
- Treated as separate user
Result: Two sessions, two "users" - no connection
Exception: Logged-in users
How long is session data stored?
Cleanup strategies:
DELETE FROM wp_wpd_ai_session_data
WHERE date_created_gmt < DATE_SUB(NOW(), INTERVAL 365 DAY);
What to keep:
Available filters:
Use cases:
Database table: wp_wpd_ai_session_data
Key fields:
session_id VARCHAR(255) - Unique identifier
ip_address VARCHAR(100) - Visitor IP
landing_page TEXT - First page URL
referral_url TEXT - Where they came from
user_id BIGINT - WordPress user ID (0 = guest)
date_created_gmt DATETIME - Session start
date_updated_gmt DATETIME - Last activity
device_category VARCHAR(50) - mobile/desktop/tablet
operating_system VARCHAR(100) - OS name
browser VARCHAR(100) - Browser name
additional_data LONGTEXT - JSON metadata
One-to-Many relationship:
Session (1)
├── Event 1 (page_view)
├── Event 2 (product_click)
├── Event 3 (page_view)
├── Event 4 (add_to_cart)
└── Event 5 (transaction)
All events share same session_id
JOIN events to sessions via session_id
// Modify session timeout
add_filter('wpd_session_timeout_seconds', function($timeout) {
return 60 * 60; // 60 minutes
});
// Modify session data before storage
add_filter('wpd_session_data_before_storage', function($session_data) {
// Custom modifications
return $session_data;
});
// Action after session created/updated
add_action('wpd_session_updated', function($session_data) {
// Custom logic
});
Sessions not being created:
localStorage are enabled in the browserSessions too short:
Sessions not linking to orders:
wpd_ai_v2_landing_page (cookies may be absent until cart/checkout)Multiple sessions for same user: