Open your agency account which manages all sub-accounts and navigate to Settings and then to Company.
Now locate "Custom Javascript" and paste in the code snippet below. Please make sure to replace YOUR_SDK_KEY_GOES_HERE with your SDK key.
The script below also identifies your customers with Gleap.identify().
<script>
const GLEAP_SDK_KEY = "YOUR_SDK_KEY_GOES_HERE";
!function(){if(!(window.Gleap=window.Gleap||[]).invoked){window.GleapActions=[];const e=new Proxy({invoked:!0},{get:function(e,n){return"invoked"===n?e.invoked:function(){const e=Array.prototype.slice.call(arguments);window.GleapActions.push({e:n,a:e})}},set:function(e,n,t){return e[n]=t,!0}});window.Gleap=e;const n=document.getElementsByTagName("head")[0],t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src="https://sdk.gleap.io/latest/index.js",n.appendChild(t),
window.Gleap.initialize(GLEAP_SDK_KEY)
}}();
(function () {
function getCompanyInfo() {
let companyName = null;
let companyId = null;
try {
const el = document.querySelector(".hl_switcher-loc-name");
if (el) companyName = el.textContent?.trim() || null;
const url = window.location.href;
const part = url.split("location/")[1]?.split("/")[0];
if (part && typeof part === "string" && part.length > 0) companyId = part;
} catch (e) {
console.log("Gleap failed getting company informations", e);
}
return { companyName, companyId };
}
function getUserFromVue() {
const appEl = document.querySelector("#app");
if (!appEl) return null;
// Vue 2: __vue__ on root element
const vue2 = appEl.__vue__;
if (vue2 && vue2.$store) {
let g = vue2.$store.getters?.["user/get"];
return typeof g === "function" ? g() : g || null;
}
// Vue 3: __vue_app__ on root element, store at globalProperties.$store
const vue3App = appEl.__vue_app__;
const store = vue3App?.config?.globalProperties?.$store;
if (store) {
let g = store.getters?.["user/get"];
return typeof g === "function" ? g() : g || null;
}
return null;
}
// Poll for up to ~15s because SPA chunks & store may mount late
const start = Date.now();
const timer = setInterval(() => {
try {
if (!/\/location\//.test(window.location.href)) return;
const user = getUserFromVue();
if (!user || !user.id) {
if (Date.now() - start > 15000) clearInterval(timer);
return;
}
const { companyId, companyName } = getCompanyInfo();
if (typeof Gleap !== "undefined" && Gleap.identify) {
Gleap.identify(user.id, {
name: user.name,
email: user.email,
phone: user.phone,
...(companyId && { companyId }),
...(companyName && { companyName }),
});
}
clearInterval(timer);
} catch (e) {
console.log("Error in Gleap integration", e);
clearInterval(timer);
}
}, 500);
})();
</script>