From 672d9281a968b9b0f9be065496a5429ae454e3b2 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Sun, 17 Mar 2024 20:42:39 -0700 Subject: [PATCH 1/2] Added COLLECT_API_HOST environment variable. --- rollup.tracker.config.mjs | 3 ++- src/tracker/index.js | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rollup.tracker.config.mjs b/rollup.tracker.config.mjs index 6a692efa8..05df28798 100644 --- a/rollup.tracker.config.mjs +++ b/rollup.tracker.config.mjs @@ -10,7 +10,8 @@ export default { }, plugins: [ replace({ - '/api/send': process.env.COLLECT_API_ENDPOINT || '/api/send', + '__COLLECT_API_HOST__': process.env.COLLECT_API_HOST || '', + '__COLLECT_API_ENDPOINT__': process.env.COLLECT_API_ENDPOINT || '/api/send', delimiters: ['', ''], preventAssignment: true, }), diff --git a/src/tracker/index.js b/src/tracker/index.js index 9af6351db..333a61cdb 100644 --- a/src/tracker/index.js +++ b/src/tracker/index.js @@ -22,10 +22,9 @@ const stripSearch = attr(_data + 'strip-search') === _true; const domain = attr(_data + 'domains') || ''; const domains = domain.split(',').map(n => n.trim()); - const root = hostUrl - ? hostUrl.replace(/\/$/, '') - : currentScript.src.split('/').slice(0, -1).join('/'); - const endpoint = `${root}/api/send`; + const host = + '__COLLECT_API_HOST__' || hostUrl || 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-_]+)/; const eventNameAttribute = _data + 'umami-event'; From c69a703c7f61f5c2e969209969268130fe3a9f6e Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Sun, 17 Mar 2024 21:35:30 -0700 Subject: [PATCH 2/2] Host URL data attribute should take precedence. --- src/tracker/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tracker/index.js b/src/tracker/index.js index 333a61cdb..3728be0e9 100644 --- a/src/tracker/index.js +++ b/src/tracker/index.js @@ -23,7 +23,7 @@ const domain = attr(_data + 'domains') || ''; const domains = domain.split(',').map(n => n.trim()); const host = - '__COLLECT_API_HOST__' || hostUrl || currentScript.src.split('/').slice(0, -1).join('/'); + hostUrl || '__COLLECT_API_HOST__' || 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-_]+)/;