overcentric
Version:
Overcentric watches your website, product, and users - and tells you what matters and what to do about it.
43 lines (42 loc) • 1.3 kB
JavaScript
let reb2bLoaded = false;
let currentProjectId = null;
const REB2B_KEY = "Z6PVLHQ2XR6R";
function setCustomerId(projectId, sessionId) {
var _a;
const w = window;
const customerId = `${projectId}:${sessionId}`;
if ((_a = w.rb2bConfig) === null || _a === void 0 ? void 0 : _a.options) {
w.rb2bConfig.options.customer_id = customerId;
}
else {
w.rb2bConfig = { options: { customer_id: customerId } };
}
}
function loadReb2bScript() {
if (window.reb2b)
return;
window.reb2b = { loaded: true };
const s = document.createElement("script");
s.async = true;
s.src = `https://ddwl4m2hdecbv.cloudfront.net/b/${REB2B_KEY}/${REB2B_KEY}.js.gz`;
const first = document.getElementsByTagName("script")[0];
if (first && first.parentNode) {
first.parentNode.insertBefore(s, first);
}
else {
document.head.appendChild(s);
}
}
export function initVisitorIdentification(projectId, sessionId) {
if (reb2bLoaded)
return;
reb2bLoaded = true;
currentProjectId = projectId;
setCustomerId(projectId, sessionId);
loadReb2bScript();
}
export function updateVisitorSession(sessionId) {
if (!reb2bLoaded || !currentProjectId)
return;
setCustomerId(currentProjectId, sessionId);
}