36 lines
1016 B
TypeScript
36 lines
1016 B
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getConversionFunnel } from '@/lib/analytics';
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
// 获取请求参数
|
|
const { searchParams } = new URL(request.url);
|
|
const linkId = searchParams.get('linkId');
|
|
const startDate = searchParams.get('startDate') || undefined;
|
|
const endDate = searchParams.get('endDate') || undefined;
|
|
|
|
// 验证必要参数
|
|
if (!linkId) {
|
|
return NextResponse.json(
|
|
{ error: 'Missing required parameter: linkId' },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
// 获取转化漏斗数据
|
|
const funnelData = await getConversionFunnel(
|
|
linkId,
|
|
startDate || undefined,
|
|
endDate || undefined
|
|
);
|
|
|
|
// 返回数据
|
|
return NextResponse.json(funnelData);
|
|
} catch (error) {
|
|
console.error('Error in funnel API:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch funnel data' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|