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.

How to filter by a Custom Variable in SessionCam

Custom Variables are treated in SessionCam like anonymous form fields. You can filter for them by using the Field Value filter in the Advanced Filters.

mceclip1.png

Field Name is your KEY and Field Value is your VALUE.

If you cannot see you KEY auto populating you may need to wait for the session to be processed in SessionCam (usually 20 minutes but we recommend waiting 2 hours), or you may need to test if the value is being sent. See how to test if the variable is sent here

To find more about advanced filters click here.