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:
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:25 AM - Session expires (15 minutes after last activity)
If visitor returns at 10:30 AM, a NEW session starts.
What happens:
wpd_ai_session_id - Session identifierwpd_ai_landing_page - Landing URL with query paramswpd_ai_referral_source - HTTP referrerwp_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:
date_updated_gmt set to current timeImportant: Landing page and referral URL do NOT change during a session. They're set once at session start.
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:
What happens at expiration:
date_updated_gmtdate_updated_gmt - date_created_gmtIf visitor returns after expiration:
Reasons for 10-minute timeout:
What 10 minutes means:
Developer note: Timeout can be customized via filter:
// Change to 30 minutes
add_filter('wpd_session_timeout_seconds', function($timeout) {
return 30 * 60; // 30 minutes
});
1. wpd_ai_session_id
| Property | Value |
|---|---|
| Purpose | Unique session identifier |
| Format | wpd + MD5 hash + timestamp |
| Example | wpd5f4dcc3b5aa765a1234567890 |
| Expiry | 10 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 algorithm:
function generate_unique_session_id() {
$random_token = md5($_SERVER['HTTP_USER_AGENT'] . time());
return 'wpd' . $random_token . time();
}
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 | 10 minutes from last activity |
| Set once | Yes (only on first page, value doesn't change) |
| 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 | 10 minutes from last activity |
| Set once | Yes (only on first page) |
| Used for | Traffic source classification |
Special handling:
10: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 (1–30 days). Referral URL and landing page are stored when the visitor first arrives and expire after that many days from first set—they are not updated by later activity. So attribution can extend beyond a single session: if a visitor returns within the window, the original referrer and landing page are still used.
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 (session expired)
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 Direct (new session, new attribution)
Scenario 3: Multiple sessions
Day 1, 10:00 AM - Facebook ad → Browse → Leave (session expires)
Day 1, 3:00 PM - Google search → Browse → Leave (new session, session expires)
Day 2, 9:00 AM - Direct visit → Purchase (new session)
Result: Order attributed to Direct (last session wins - last-click attribution)
Alpha Insights uses last-click attribution:
Why last-click?
Limitations of last-click:
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: Direct (last-click)
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 30 * 60; // 30 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:
Sessions too short:
Sessions not linking to orders:
Multiple sessions for same user: