How to set up a Custom Variable based on a Query String value

SessionCam does not capture query string data as part of the page name. 

This means that  you will see the page -  ‘www.domain.com/load.aspx?PageA’ 
recorded as -www.domain.com/load.aspx

Some websites will have their page URLs structured to make use of the query string value in differentiating pages. In order for us to achieve this within Sessioncam we can make use of a custom page names.

Capture the entire query string

The below JavaScript will extract the full query string and add it to the end of the path as a page name:

function getQueryString() {
    return [location.pathname.slice(1), location.search.slice(1)];
}
(function setPageName(){
    if (!window.sessioncamConfiguration) { window.sessioncamConfiguration = new Object(); }
    var scValues = getQueryString();
    sessioncamConfiguration.SessionCamPath = scValues[0];
    sessioncamConfiguration.SessionCamPageName = scValues[1];
})();

The result of this is that you would see the page ‘www.domain.com/load.aspx?PageA

Recorded in Sessioncam as ‘www.domain.com/load.aspx/PageA’.

Extract a value from the query string (Regex)

The below JavaScript is a modified version of the first script which allows you to use regular expression to match and extract values unique to your requirements

function getQueryString() {
// Edit the regex between the brackets on the line below     var scPath = location.search.match(/(test)/);
    return [location.pathname.slice(1), scPath];
}
(function setPageName(){
    if (!window.sessioncamConfiguration) { window.sessioncamConfiguration = new Object(); }
    var scValues = getQueryString();
    sessioncamConfiguration.SessionCamPath = scValues[0];
    sessioncamConfiguration.SessionCamPageName = scValues[1];
})();

The regular expression “ /(test)/” will search the query string for the vale ‘“test” and add this onto your custom page name. The result of this is that the page - ‘www.domain.com/path?ABCtest123will be recorded in Sessioncam as - ‘www.domain.com/path/test’. 

Follow the instructions below to test your implementation:

If you need more help with steps 1 and 2 there is a more in depth set of instructions here: https://help.sessioncam.com/hc/en-gb/articles/201781517-How-to-go-directly-to-the-Recordings-screen-using-a-Session-ID

  1. Navigate to the page you’re renaming in a browser and type ‘window.sessionCamRecorder.sessionId()’ into the console. Copy the returned value excluding the quote marks.                                               
  2. Go to the following webpage ‘https://console.sessioncam.com/Console/Recordings/PlaybackSession?sessionId=UniqueID’ replacing ‘UniqueID’ with value you have copied.
  3. Navigate to ‘Current Page’ at the bottom of this screen, and you will see the names of all pages from that Session.