fix: auto-detect domain from hostname for zero-config GTM support

When data-domain attribute and pulseConfig are both unavailable (common
with GTM which strips data-* attributes), the script now falls back to
location.hostname. This is safe because the backend already validates
Origin/Referer against the registered domain. Strips www. prefix on
auto-detected hostname to match typical Pulse registration patterns.
This commit is contained in:
Usman Baig
2026-03-19 13:56:18 +01:00
parent 73fc47e910
commit ac9e10b436

View File

@@ -40,7 +40,10 @@
return (script && script.hasAttribute('data-' + name)) || globalConfig[name] === true || globalConfig[camel] === true;
}
const domain = attr('domain');
// * Resolve domain: explicit config > data-domain > auto-detect from hostname
// * Auto-detect enables zero-config GTM installs; the backend validates Origin anyway
var explicitDomain = attr('domain');
const domain = explicitDomain || location.hostname.replace(/^www\./, '');
if (!domain) {
return;
}