click subpath match

This commit is contained in:
2025-04-10 18:31:24 +08:00
parent b8cd3716c4
commit 85f29d8b49
2 changed files with 33 additions and 22 deletions

View File

@@ -66,23 +66,28 @@ export async function GET(request: NextRequest) {
conditions.push(`link_id = '${linkId}'`);
}
// 添加子路径筛选
if (subpath) {
// 添加子路径筛选 - 使用更精确的匹配方式
if (subpath && subpath.trim() !== '') {
console.log('====== UTM API SUBPATH DEBUG ======');
console.log('Raw subpath param:', subpath);
console.log('Subpath type:', typeof subpath);
console.log('Subpath length:', subpath.length);
console.log('Subpath chars:', Array.from(subpath).map(c => c.charCodeAt(0)));
// 确保没有前导斜杠,避免双斜杠问题
const cleanSubpath = subpath.startsWith('/')
? subpath.substring(1)
: subpath;
// 清理并准备subpath值
let cleanSubpath = subpath.trim();
// 移除开头的斜杠以便匹配
if (cleanSubpath.startsWith('/')) {
cleanSubpath = cleanSubpath.substring(1);
}
// 移除结尾的斜杠以便匹配
if (cleanSubpath.endsWith('/')) {
cleanSubpath = cleanSubpath.substring(0, cleanSubpath.length - 1);
}
console.log('Cleaned subpath:', cleanSubpath);
// 在event_attributes JSON的full_url字段中查找subpath
const condition = `JSONExtractString(event_attributes, 'full_url') LIKE '%${cleanSubpath}%'`;
// 使用正则表达式匹配URL中的第二个路径部分
// 示例: 在 "https://abc.com/slug/subpath/" 中匹配 "subpath"
const condition = `match(JSONExtractString(event_attributes, 'full_url'), '/[^/]+/${cleanSubpath}(/|\\\\?|$)')`;
console.log('Final SQL condition:', condition);
console.log('==================================');