Filter: wpd_session_timeout_seconds
Control the session timeout duration in seconds. Sessions expire after this period of inactivity.
Description
Alpha Insights tracks user sessions for traffic analytics. A session expires after a period of inactivity (no events). This filter allows you to customize the timeout duration to match your business needs or analytics requirements.
Location
File: includes/classes/WPD_Session_Tracking.php
Methods: WPD_Session_Tracking::get_or_create_session() and WPD_Session_Tracking::is_session_expired()
Lines: ~317 and ~405
Parameters
| Parameter | Type | Description |
|---|---|---|
| $timeout_seconds | int | Session timeout in seconds (default: 1800 = 30 minutes) |
Return
Type: int
Description: Modified timeout in seconds (must be a positive integer)
Example Usage
Increase Session Timeout to 1 Hour
add_filter( 'wpd_session_timeout_seconds', 'increase_session_timeout' );
function increase_session_timeout( $timeout_seconds ) {
// 1 hour = 3600 seconds
return 3600;
}
Decrease Session Timeout to 15 Minutes
add_filter( 'wpd_session_timeout_seconds', 'decrease_session_timeout' );
function decrease_session_timeout( $timeout_seconds ) {
// 15 minutes = 900 seconds
return 900;
}
Google Analytics Compatible Timeout
add_filter( 'wpd_session_timeout_seconds', 'ga_compatible_timeout' );
function ga_compatible_timeout( $timeout_seconds ) {
// Google Analytics default: 30 minutes of inactivity
// This matches Alpha Insights default, but explicitly set for compatibility
return 1800;
}
Dynamic Timeout Based on Time of Day
add_filter( 'wpd_session_timeout_seconds', 'time_based_session_timeout' );
function time_based_session_timeout( $timeout_seconds ) {
$current_hour = (int) current_time( 'H' );
// Longer timeout during business hours (9 AM - 5 PM)
if ( $current_hour >= 9 && $current_hour
Mobile vs Desktop Different Timeouts
add_filter( 'wpd_session_timeout_seconds', 'device_based_session_timeout' );
function device_based_session_timeout( $timeout_seconds ) {
// Check if user is on mobile device
if ( wp_is_mobile() ) {
// Mobile users tend to browse in shorter bursts
return 900; // 15 minutes for mobile
}
// Desktop users typically have longer sessions
return 1800; // 30 minutes for desktop
}
Best Practices
- 30 minutes (1800 seconds) is the industry standard
- Shorter timeouts = more accurate session counts
- Longer timeouts = fewer sessions, higher session duration
- Match your analytics platform (Google Analytics, etc.) for consistency
- Consider your typical user behavior patterns
- Don’t set too short (<5 minutes) as it fragments sessions
- Don’t set too long (>2 hours) as it inflates session metrics
Impact on Analytics
Shorter Timeout (e.g., 15 minutes):
- More accurate session counts
- Lower average session duration
- More sessions recorded
- Better for tracking quick visits
Longer Timeout (e.g., 1 hour):
- Fewer total sessions
- Higher average session duration
- Better for tracking engaged users
- May combine separate visits into one session
Important Notes
- Timeout must be a positive integer (seconds)
- Default of 30 minutes (1800 seconds) is recommended
- Changing this affects how sessions are counted
- Historical data is not affected by changes
- Only new sessions use the updated timeout
- This is inactivity timeout, not total session duration
Common Timeout Values
| Duration | Seconds | Use Case |
|---|---|---|
| 15 minutes | 900 | Quick browsing, mobile-focused |
| 30 minutes (default) | 1800 | Standard, matches Google Analytics |
| 1 hour | 3600 | Engaged browsing, research sites |
| 2 hours | 7200 | Long-form content, detailed research |
Debugging
add_filter( 'wpd_session_timeout_seconds', 'debug_session_timeout', 999 );
function debug_session_timeout( $timeout_seconds ) {
error_log( 'Alpha Insights Session Timeout: ' . $timeout_seconds . ' seconds (' . ( $timeout_seconds / 60 ) . ' minutes)' );
return $timeout_seconds;
}
Related Classes
WPD_Session_Tracking– Session tracking and managementWPD_WooCommerce_Events– Event tracking