Usage
nebula()->nebula_session_id()
Parameters
This function does not accept any parameters. Is this incorrect?
Additional Notes
t:1502941358;dev:1;r:subscriber;uid:17;s:ffq669njdj9dnmpgcj2de8osp1;cid:1068816418.1487540422;
Default Components
- t – Server-side UTC timestamp of the last pageview in the session.
- d – Debug mode
- p – Prototype mode
- cli – Client user (Matched by IP address or logged-in email domain)
- dev – Developer user (Matched by IP address or logged-in email domain)
- r – Logged-in WordPress user role
- uid – Logged-in WordPress user ID
- bot – Known bot
- l – If the site is not live (using is_site_live()) Note: Only appears if false
- s – Session ID or Unique ID (Note: unique ID is prepended with
!) - cid – Google Analytics CID
- This is parsed from the Google Analytics cookie (two numbers separated by
.) or generated by Nebula (four groups of numbers separated by-) - The first number in the GA cookie is a random ID and the second is a UTC timestamp of the user’s first visit.
- This is an ID tied to the user and can be used to track multiple sessions.
- This is parsed from the Google Analytics cookie (two numbers separated by
Use the filter nebula_session_id to add more values to this session ID. Remember that this value is accessible in the page source, so data may be seen by the visitor. Important: Do not add personally identifiable information to this session ID! This data is stored in Google Analytics where PII is against the Terms of Service.
Follow the Nebula Recommendations to create custom dimensions including one for Session ID so it can provide context to visitor data in Google Analytics.
Tips
- This information can be sent with all Contact Form 7 forms by including a hidden filed with the class
debuginfo. - Use these to create a segment within Google Analytics to focus only on important traffic.
- Create temporary segments or report filters to track individual users with their CID.
- On initial visit, Nebula generates a CID which is replaced via JavaScript when an actual Google Analytics Client ID is generated.
- If the Nebula version remains it indicates that Google Analytics or JavaScript is blocked.
Source File
Located in /libs/Utilities/Utilities.php on line 111.
2 Hooks
Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.
Filters
"nebula_session_id"Need a new filter hook? Request one here.
Actions
"qm/info"Need a new action hook? Request one here.
public function nebula_session_id(){
if ( $this->is_minimal_mode() ){return null;}
$session_cookie_data = $this->prep_new_session_cookie();
//Read and decode the cookie if it exists
if ( isset($this->super->cookie['session']) ){
$session_cookie_data = json_decode(stripslashes($this->super->cookie['session']), true);
if ( !is_array($session_cookie_data) ){
$session_cookie_data = $this->prep_new_session_cookie(); //Fallback in case of invalid JSON
}
}
//Get or create SID Key
if ( isset($session_cookie_data['sid_key']) && is_string($session_cookie_data['sid_key']) ){
$cache_group = sanitize_key($session_cookie_data['sid_key']);
} else {
$cache_group = uniqid('nebula_', true);
$session_cookie_data['sid_key'] = $cache_group;
$this->set_cookie('session', json_encode($session_cookie_data), time()+HOUR_IN_SECONDS*4, false); //Re-encode and set the full session cookie. Needs to be able to be read by JavaScript.
}
//Check object cache
$session_id = wp_cache_get('nebula_session_id', $cache_group);
if ( $session_id !== false ){
return sanitize_textarea_field($session_id);
}
$timer_name = $this->timer('Session ID');
$session_data = array();
//Time
$session_data['t'] = time();
//Debug
if ( $this->is_debug() ){
$session_data['d'] = true;
}
//Client/Developer
if ( $this->is_client() ){
$session_data['cli'] = true;
}
if ( $this->is_dev() ){
$session_data['dev'] = true;
}
//Logged-in user info
if ( is_user_logged_in() ){
$user_info = get_userdata(get_current_user_id());
$session_data['r'] = 'unknown';
if ( !empty($user_info->roles) ){
$session_data['r'] = $user_info->roles[0];
}
$session_data['uid'] = get_current_user_id();
}
//Bot detection
if ( $this->is_bot() ){
$session_data['bot'] = true;
}
//Site live status
if ( !$this->is_site_live() ){
$session_data['l'] = false;
}
//Session ID
$session_data['s'] = $cache_group;
//GA CID
$session_data['cid'] = $this->ga_parse_cookie();
//Custom filter
$all_session_data = apply_filters('nebula_session_id', $session_data);
//Convert to string
$session_id = '';
foreach ( $all_session_data as $key => $value ){
$session_id .= $key . ':' . $value . ';';
}
do_action('qm/info', 'Nebula Session ID: ' . $session_id);
wp_cache_set('nebula_session_id', $session_id, $cache_group, HOUR_IN_SECONDS*4);
$this->timer($timer_name, 'end');
return sanitize_textarea_field($session_id);
}
Override
This function can not be short-circuited with an override filter. Request one?