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 :)
This commit is contained in:
Ondřej Vacek 2020-08-26 16:12:20 +02:00 committed by GitHub
parent 3e1bc27f26
commit 4fb9150631
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,7 @@ import { post, hook, doNotTrack } from '../lib/web';
if (!script || (__DNT__ && doNotTrack())) return; if (!script || (__DNT__ && doNotTrack())) return;
const website = script.getAttribute('data-website-id'); 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 screen = `${width}x${height}`;
const listeners = []; const listeners = [];