From 4fb915063145b06fca77e55d6cb9506b1f16d0d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Vacek?= Date: Wed, 26 Aug 2020 16:12:20 +0200 Subject: [PATCH 1/2] Generic AIP collect URL allowing subfolders I've changed the fetching of "hostUrl" variable to match not only domain, but the subfolder as well. The thing is I've installed the analytics to subfolder "/myfolder/" but when I used the code, the tracker tries to send the data to "mydomain.com/api/collect" instead of correct "mydomain.com/myfolder/api/collect". This change fixes the issue. It's not pretty to filter out the name of the script from the path by .replace, but I wasn't able to find better solution to get the subfolder. If you do, please change it :) --- tracker/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracker/index.js b/tracker/index.js index 60957d76..e248f906 100644 --- a/tracker/index.js +++ b/tracker/index.js @@ -17,7 +17,7 @@ import { post, hook, doNotTrack } from '../lib/web'; if (!script || (__DNT__ && doNotTrack())) return; const website = script.getAttribute('data-website-id'); - const hostUrl = new URL(script.src).origin; + const hostUrl = new URL(script.src).href.replace(/\/umami\.js$/,''); const screen = `${width}x${height}`; const listeners = []; From 36119f4cb474b47c0b96940da00634442eae2682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Vacek?= Date: Thu, 27 Aug 2020 10:01:05 +0200 Subject: [PATCH 2/2] Update index.js better solution from @mikecao, it's not dependent on script name --- tracker/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracker/index.js b/tracker/index.js index e248f906..a30a0220 100644 --- a/tracker/index.js +++ b/tracker/index.js @@ -17,7 +17,7 @@ import { post, hook, doNotTrack } from '../lib/web'; if (!script || (__DNT__ && doNotTrack())) return; const website = script.getAttribute('data-website-id'); - const hostUrl = new URL(script.src).href.replace(/\/umami\.js$/,''); + const hostUrl = new URL(script.src).href.split('/').slice(0, -1).join('/'); const screen = `${width}x${height}`; const listeners = [];