support multiple track script name
parent
2b4ddb5388
commit
2bd3ddf6ec
|
@ -15,10 +15,15 @@ function customScriptName(req) {
|
||||||
const scriptName = process.env.TRACKER_SCRIPT_NAME;
|
const scriptName = process.env.TRACKER_SCRIPT_NAME;
|
||||||
|
|
||||||
if (scriptName) {
|
if (scriptName) {
|
||||||
|
const names = scriptName.split(',').map(name => name + '.js');
|
||||||
|
|
||||||
const url = req.nextUrl.clone();
|
const url = req.nextUrl.clone();
|
||||||
const { pathname } = url;
|
const { pathname } = url;
|
||||||
|
|
||||||
if (pathname.endsWith(`/${scriptName}.js`)) {
|
const pathNameParts = pathname.split('/');
|
||||||
|
const lastPathName = pathNameParts[pathNameParts.length - 1];
|
||||||
|
|
||||||
|
if (names.indexOf(lastPathName) !== -1) {
|
||||||
url.pathname = '/umami.js';
|
url.pathname = '/umami.js';
|
||||||
return NextResponse.rewrite(url);
|
return NextResponse.rewrite(url);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue