Advanced Cobrowse Cross-Domain

This page highlights additional situations that may arise when setting up Cobrowse Cross-Domain.

Multiple Group IDs

Organizations utilizing multiple Glance group IDs may find it simpler to create a single helper page on each domain that supports the dynamic specification of the group ID and data-site attributes based on parameters in the helper page’s URL.

During the Cross-Domain flow, Glance will automatically append the appropriate group ID and data-site values in the URL of each helper page being opened. For example:

https://www.yourwebsite.com/helper.html?GlanceSession=1&groupid=<groupid>&data-site=<staging|production>

Below is a sample code that would need to be added to the helper page:

function addCobrowseScript() {
  var allowedGroupIDs = ["12345", "23456", "34567", "45678", "56789"];
  var urlParams = new URLSearchParams(window.location.search);

  var groupId = urlParams.get("groupid");
  // Check to make sure the group id in the query string is on the allowed list
  if (!allowedGroupIDs.includes(groupId)) {
    // If no group ID found in the query string, or there is one that's not on the allowed list
    // replace with the desired default group id
    groupId = "12345";
  }

  // Use production as the default, unless staging is specified
  var dataSite =
    urlParams.get("data-site") === "staging" ? "staging" : "production";

  var theCobrowseScript = document.createElement("script");

  theCobrowseScript.setAttribute("id", "glance-cobrowse");
  theCobrowseScript.setAttribute("type", "text/javascript");
  theCobrowseScript.setAttribute("data-groupid", groupId);
  theCobrowseScript.setAttribute("data-site", dataSite);
  theCobrowseScript.setAttribute("charset", "UTF-8");
  theCobrowseScript.setAttribute(
    "src",
    `https://www.glancecdn.net/cobrowse/CobrowseJS.ashx?group=${groupId}&site=${dataSite}&script=XDOM`
  );
  document.head.append(theCobrowseScript);
}

window.addEventListener("load", addCobrowseScript);
Note

The group IDs in the above sample must be replaced with the group IDs for the organization.