Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/tracker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
doNotTrack,
} = window;
const { currentScript, referrer } = document;
if (!currentScript) return;
const globalConfig = window.umamiConfig || {};
if (!currentScript && !globalConfig.websiteId) return;

const { hostname, href, origin } = location;

Expand All @@ -23,8 +24,17 @@
const _data = 'data-';
const _false = 'false';
const _true = 'true';
const attr = currentScript.getAttribute.bind(currentScript);
const config = value => attr(`${_data}${value}`);
const attr = currentScript ? currentScript.getAttribute.bind(currentScript) : () => null;

const toCamelCase = str => str.replace(/-([a-z])/g, g => g[1].toUpperCase());

const config = value => {
const camelKey = toCamelCase(value);
if (globalConfig[camelKey] !== undefined) {
return String(globalConfig[camelKey]);
}
return attr(`${_data}${value}`);
};
Comment thread
Yashh56 marked this conversation as resolved.
Comment thread
Yashh56 marked this conversation as resolved.

const website = config('website-id');
const hostUrl = config('host-url');
Expand All @@ -40,7 +50,7 @@

const domains = domain.split(',').map(n => n.trim());
const host =
hostUrl || '__COLLECT_API_HOST__' || currentScript.src.split('/').slice(0, -1).join('/');
hostUrl || '__COLLECT_API_HOST__' || (currentScript ? currentScript.src.split('/').slice(0, -1).join('/') : '');
const endpoint = `${host.replace(/\/$/, '')}__COLLECT_API_ENDPOINT__`;
const screen = `${width}x${height}`;
const eventRegex = /data-umami-event-([\w-_]+)/;
Expand Down