Table of Contents
- Overview
- Accessing the User's Session ID
- Setting the Session ID in the Next Page
- Demonstrating and Testing the Correct Setup of the Session ID
Overview
Blue Triangle currently uses on the Web Storage API for storing the unique Session ID for a user's session. The Web Storage API is bound to the origin (the domain / protocol / port triplet) and therefore the Session ID will not transfer across domains. For sites that wish to maintain the user's session ID across domains, the following three methods are available: setting local storage manually, setting a parameter in the URL, and setting a first party cookie.
Accessing the User's Session ID
The Blue Triangle Session ID can be accessed from the JavaScript Tag using the following JavaScript code. The _bttUtil object contains various state variables stored by the JS Tag. Site developer's will need to store and transmit this Session ID across domains using the following techniques listed below.
_bttUtil.sessionID
Setting the Session ID in the Next Page
Setting Local Storage Manually
For situations where the site framework can persists and store the user's Session ID, the local storage value can be set manually with the following JavaScript code.
This code assumes that the unique session ID has been stored and transmitted across domains by the site framework and can be maintained and accessed from the next domain.
SID = '123456789';
EXP = new Date().getTime() + 1800000;
localStorage.setItem('BTT_X0siD', '{"value":"' + bttUtil.sessionID.toString() + '","expires":"' + EXP + '"}');
Setting a Parameter in the URL
The user's unique Session ID can also be set in the URL as a parameter labelled bttid.
The Blue Triangle JS Tag will pick up this parameter automatically and set the Session ID when traversing across domains. The following example shows two URLs that pass the Session ID as a URL parameter.
https://portal.bluetriangle.com/?page=login&bttid=202653636907260513
Setting a First Party Cookie
The user's unique Session ID can also be set with a first party cookie. The Blue Triangle Tag will automatically set the Session ID based on the first party cookie value BTT_X0siD
The following JavaScript example sets a cookie for all bluetriangle.com domains and subdomains. This code must be run from a first party source in order to set a first party cookie.
The domain in the following code example should be changed to reflect the first party domain.
The domain should be changed from [DOMAIN] to the first party domain.
document.cookie = "BTT_X0siD=" + _bttUtil.sessionID.toString() + ";domain=[YOURDOMAIN];path=/";
Demonstrating and Testing the Correct Setup of the Session ID
In this section, we will describe how to set and validate the session ID properly.
Let's assume the following:
- Main page: https://www.bluetriangle.com
- Target page URL: https://subdomain.bluetriangle.com
- bttUtil.sessionID on the original page is 202653636907260513
The Local Storage Method
EXP = new Date().getTime() + 1800000;
localStorage.setItem('BTT_X0siD', '{"value":"' + bttUtil.sessionID.toString() + '","expires":"' + EXP + '"}');
This should result in the following:
BTT_X0siD = “Value”:”202653636907260513”;”expires”: “1718905669838”
The URL Method
https://portal.bluetriangle.com/?page=login&bttid=202653636907260513
The First Party Cookie Method
document.cookie = "BTT_X0siD=" + _bttUtil.sessionID.toString() + ";domain=.bluetriangle.com;path=/";
Comments
0 comments
Please sign in to leave a comment.