mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Allow multiple tracker names.
This commit is contained in:
parent
f0d13efc7a
commit
dbc19e4ffd
@ -24,8 +24,9 @@ function customScriptName(req) {
|
|||||||
if (scriptName) {
|
if (scriptName) {
|
||||||
const url = req.nextUrl.clone();
|
const url = req.nextUrl.clone();
|
||||||
const { pathname } = url;
|
const { pathname } = url;
|
||||||
|
const names = scriptName.split(',').map(name => name.trim());
|
||||||
|
|
||||||
if (pathname.endsWith(scriptName)) {
|
if (names.find(name => pathname.endsWith(name))) {
|
||||||
url.pathname = '/script.js';
|
url.pathname = '/script.js';
|
||||||
return NextResponse.rewrite(url);
|
return NextResponse.rewrite(url);
|
||||||
}
|
}
|
||||||
|
@ -45,12 +45,16 @@ if (process.env.COLLECT_API_ENDPOINT) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.TRACKER_SCRIPT_NAME) {
|
if (process.env.TRACKER_SCRIPT_NAME) {
|
||||||
const match = process.env.TRACKER_SCRIPT_NAME?.match(/\/?(\w+)(\.js)?/);
|
const names = process.env.TRACKER_SCRIPT_NAME?.split(',').map(name => name.trim());
|
||||||
|
|
||||||
if (match) {
|
if (names) {
|
||||||
rewrites.push({
|
names.forEach(name => {
|
||||||
source: `/${match[0]}.js`,
|
const slash = name.substring(0, 1) === '/' ? '' : '/';
|
||||||
destination: '/script.js',
|
|
||||||
|
rewrites.push({
|
||||||
|
source: `${slash}${name}`,
|
||||||
|
destination: '/script.js',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user