How to track browser console errors

You can track the logging of, or get alerts on, errors in the SessionCam console. For example, you may have a piece of Javascript which contains an error that causes a visitor to leave your site.

By setting up a Custom Variable, you can send a string of data to SessionCam that can be used inSegments, Exports and Alerts. This means you can review any sessions in which an error message occured.

While it’s not possible to pull all console messages, the script below should enable you to pull the data you need to debug any possible errors on your site that could impact conversion.

The following shows an example of an error that can be caught by this script:

  • Uncaught exceptions
    • throw "some messages"
    • call_something_undefined()
    • cross_origin_iframe.contentWindow.documen, a security exception
  • Compile error
    • <script>{</script>
    • <script>for(;)</script>
    • <script>"oops</script>

The code snippet below can be added to your page and will log JavaScript errors once the page has loaded.

<script type="text/javascript">
window.onerror = function (errorMsg, url, lineNumber, column, errorObj) {
var extra = !column ? '' : ' - ColumnNo: ' + column;
extra += !errorObj ? '' : ' - Error Stack: ' + errorObj;
var errorString = "Error Detected - " + "MSG: " + errorMsg + " - URL: " + document.location.href + " - LineNo: " + lineNumber + extra
if (!window.sessioncamConfiguration)
window.sessioncamConfiguration = new Object();
if (!window.sessioncamConfiguration.customDataObjects)
window.sessioncamConfiguration.customDataObjects = [];
var errorvariable = {key: "ConsoleError",value: errorString};
return false;