click subpath match
This commit is contained in:
@@ -66,23 +66,28 @@ export async function GET(request: NextRequest) {
|
|||||||
conditions.push(`link_id = '${linkId}'`);
|
conditions.push(`link_id = '${linkId}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加子路径筛选
|
// 添加子路径筛选 - 使用更精确的匹配方式
|
||||||
if (subpath) {
|
if (subpath && subpath.trim() !== '') {
|
||||||
console.log('====== UTM API SUBPATH DEBUG ======');
|
console.log('====== UTM API SUBPATH DEBUG ======');
|
||||||
console.log('Raw subpath param:', subpath);
|
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)));
|
|
||||||
|
|
||||||
// 确保没有前导斜杠,避免双斜杠问题
|
// 清理并准备subpath值
|
||||||
const cleanSubpath = subpath.startsWith('/')
|
let cleanSubpath = subpath.trim();
|
||||||
? subpath.substring(1)
|
// 移除开头的斜杠以便匹配
|
||||||
: subpath;
|
if (cleanSubpath.startsWith('/')) {
|
||||||
|
cleanSubpath = cleanSubpath.substring(1);
|
||||||
|
}
|
||||||
|
// 移除结尾的斜杠以便匹配
|
||||||
|
if (cleanSubpath.endsWith('/')) {
|
||||||
|
cleanSubpath = cleanSubpath.substring(0, cleanSubpath.length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Cleaned subpath:', cleanSubpath);
|
console.log('Cleaned subpath:', cleanSubpath);
|
||||||
|
|
||||||
// 在event_attributes JSON的full_url字段中查找subpath
|
// 使用正则表达式匹配URL中的第二个路径部分
|
||||||
const condition = `JSONExtractString(event_attributes, 'full_url') LIKE '%${cleanSubpath}%'`;
|
// 示例: 在 "https://abc.com/slug/subpath/" 中匹配 "subpath"
|
||||||
|
const condition = `match(JSONExtractString(event_attributes, 'full_url'), '/[^/]+/${cleanSubpath}(/|\\\\?|$)')`;
|
||||||
|
|
||||||
console.log('Final SQL condition:', condition);
|
console.log('Final SQL condition:', condition);
|
||||||
console.log('==================================');
|
console.log('==================================');
|
||||||
|
|
||||||
|
|||||||
@@ -58,22 +58,28 @@ export function buildFilter(params: Partial<EventsQueryParams>): string {
|
|||||||
filters.push(`user_id = '${params.userId}'`);
|
filters.push(`user_id = '${params.userId}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加子路径过滤条件
|
// 添加子路径过滤条件 - 使用更精确的匹配方式
|
||||||
if (params.subpath) {
|
if (params.subpath && params.subpath.trim() !== '') {
|
||||||
console.log('====== SUBPATH DEBUG ======');
|
console.log('====== SUBPATH DEBUG ======');
|
||||||
console.log('Raw subpath param:', params.subpath);
|
console.log('Raw subpath param:', params.subpath);
|
||||||
console.log('Subpath type:', typeof params.subpath);
|
|
||||||
console.log('Subpath length:', params.subpath.length);
|
|
||||||
|
|
||||||
// 确保子路径没有前导斜杠,避免双斜杠问题
|
// 清理并准备subpath值
|
||||||
const cleanSubpath = params.subpath.startsWith('/')
|
let cleanSubpath = params.subpath.trim();
|
||||||
? params.subpath.substring(1)
|
// 移除开头的斜杠以便匹配
|
||||||
: params.subpath;
|
if (cleanSubpath.startsWith('/')) {
|
||||||
|
cleanSubpath = cleanSubpath.substring(1);
|
||||||
|
}
|
||||||
|
// 移除结尾的斜杠以便匹配
|
||||||
|
if (cleanSubpath.endsWith('/')) {
|
||||||
|
cleanSubpath = cleanSubpath.substring(0, cleanSubpath.length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Cleaned subpath:', cleanSubpath);
|
console.log('Cleaned subpath:', cleanSubpath);
|
||||||
|
|
||||||
// 在event_attributes JSON的full_url字段中查找subpath
|
// 使用正则表达式匹配URL中的第二个路径部分
|
||||||
const condition = `JSONExtractString(event_attributes, 'full_url') LIKE '%${cleanSubpath}%'`;
|
// 示例: 在 "https://abc.com/slug/subpath/" 中匹配 "subpath"
|
||||||
|
const condition = `match(JSONExtractString(event_attributes, 'full_url'), '/[^/]+/${cleanSubpath}(/|\\\\?|$)')`;
|
||||||
|
|
||||||
console.log('Final SQL condition:', condition);
|
console.log('Final SQL condition:', condition);
|
||||||
console.log('==========================');
|
console.log('==========================');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user