const tag_version = '1.0.0'; let scriptURL; if (document.currentScript) { // Works in modern browsers scriptURL = document.currentScript.src; } else { // Fallback for older browsers var scripts = document.getElementsByTagName('script'); var currentScript = scripts[scripts.length - 1]; scriptURL = currentScript.src; } let urlObj = new URL(scriptURL); let baseUrl = urlObj.origin let errUrl = baseUrl + '/api/errors' function uuidv4() { return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c => ( c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4 ).toString(16)); } function sync_uuid(value, uuid, replace_string = '%%UUID%%') { value = String(value); if (value.includes(replace_string)) { value = value.replace(replace_string, uuid); } return value; } function loadTags() { let tags = [{'html_tag': 'script', 'attributes': [{'key': 'async', 'value': ''}, {'key': 'src', 'value': 'https://tag.prospectdesk.ai/ldc.js?pid=tnoevry&aid=0eb9034a'}], 'content': ''}, {'html_tag': 'script', 'attributes': [], 'content': "window.ldcDataLayer = window.ldcDataLayer || []; function ldcConfig(){{ldcDataLayer.push(arguments);}}; ldcConfig('externalId', '%%UUID%%');"}]; let uuid = Date.UTC().toString(); try { uuid = uuidv4(); } catch (e) { console.error(e) } if (typeof tags === "string") { tags = JSON.parse(tags); } tags.forEach(tag => { let container_tag = document.createElement(tag.html_tag); tag.attributes.forEach(attribute => { attribute.value = sync_uuid(attribute.value, uuid); container_tag.setAttribute(attribute.key, attribute.value); }); if (tag.content) { tag.content = sync_uuid(tag.content, uuid); container_tag.innerHTML = tag.content; } container_tag.onerror = function(event) { fetch(errUrl, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ message: `tags service ${tag_version}: an error occured`, tag_html: container_tag.outerHTML, timestamp: Date.now(), error_event: event, script_url: scriptURL }) }).then(response => { console.log(`tags service ${tag_version}: error reported to server: ${response.status}`); }).catch(error => { console.error(error); }); } document.body.appendChild(container_tag); }) console.log(`tags service ${tag_version}: loaded!`) } if (document.readyState === "loading") { window.addEventListener('DOMContentLoaded', loadTags); } else { loadTags(); }