utm
This commit is contained in:
@@ -25,6 +25,11 @@ export async function GET(request: NextRequest) {
|
||||
const endTime = searchParams.get('endTime');
|
||||
const linkId = searchParams.get('linkId');
|
||||
|
||||
// 获取团队、项目和标签筛选参数
|
||||
const teamIds = searchParams.getAll('teamId');
|
||||
const projectIds = searchParams.getAll('projectId');
|
||||
const tagIds = searchParams.getAll('tagId');
|
||||
|
||||
// 获取UTM类型参数
|
||||
const utmType = searchParams.get('utmType') || 'source';
|
||||
|
||||
@@ -44,6 +49,37 @@ export async function GET(request: NextRequest) {
|
||||
conditions.push(`link_id = '${linkId}'`);
|
||||
}
|
||||
|
||||
// 添加团队筛选
|
||||
if (teamIds && teamIds.length > 0) {
|
||||
// 如果只有一个团队ID
|
||||
if (teamIds.length === 1) {
|
||||
conditions.push(`team_id = '${teamIds[0]}'`);
|
||||
} else {
|
||||
// 多个团队ID
|
||||
conditions.push(`team_id IN ('${teamIds.join("','")}')`);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加项目筛选
|
||||
if (projectIds && projectIds.length > 0) {
|
||||
// 如果只有一个项目ID
|
||||
if (projectIds.length === 1) {
|
||||
conditions.push(`project_id = '${projectIds[0]}'`);
|
||||
} else {
|
||||
// 多个项目ID
|
||||
conditions.push(`project_id IN ('${projectIds.join("','")}')`);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加标签筛选
|
||||
if (tagIds && tagIds.length > 0) {
|
||||
// 使用与buildFilter函数相同的处理方式
|
||||
const tagConditions = tagIds.map(tag =>
|
||||
`link_tags LIKE '%${tag}%'`
|
||||
);
|
||||
conditions.push(`(${tagConditions.join(' OR ')})`);
|
||||
}
|
||||
|
||||
if (conditions.length > 0) {
|
||||
whereClause = `WHERE ${conditions.join(' AND ')}`;
|
||||
}
|
||||
|
||||
@@ -15,9 +15,12 @@ interface UtmAnalyticsProps {
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
linkId?: string;
|
||||
teamIds?: string[];
|
||||
projectIds?: string[];
|
||||
tagIds?: string[];
|
||||
}
|
||||
|
||||
export default function UtmAnalytics({ startTime, endTime, linkId }: UtmAnalyticsProps) {
|
||||
export default function UtmAnalytics({ startTime, endTime, linkId, teamIds, projectIds, tagIds }: UtmAnalyticsProps) {
|
||||
const [activeTab, setActiveTab] = useState<string>('source');
|
||||
const [utmData, setUtmData] = useState<UtmData[]>([]);
|
||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||
@@ -37,6 +40,21 @@ export default function UtmAnalytics({ startTime, endTime, linkId }: UtmAnalytic
|
||||
if (linkId) params.append('linkId', linkId);
|
||||
params.append('utmType', activeTab);
|
||||
|
||||
// 添加团队ID参数
|
||||
if (teamIds && teamIds.length > 0) {
|
||||
teamIds.forEach(id => params.append('teamId', id));
|
||||
}
|
||||
|
||||
// 添加项目ID参数
|
||||
if (projectIds && projectIds.length > 0) {
|
||||
projectIds.forEach(id => params.append('projectId', id));
|
||||
}
|
||||
|
||||
// 添加标签ID参数
|
||||
if (tagIds && tagIds.length > 0) {
|
||||
tagIds.forEach(id => params.append('tagId', id));
|
||||
}
|
||||
|
||||
// 发送请求
|
||||
const response = await fetch(`/api/events/utm?${params}`);
|
||||
|
||||
@@ -60,7 +78,7 @@ export default function UtmAnalytics({ startTime, endTime, linkId }: UtmAnalytic
|
||||
};
|
||||
|
||||
fetchUtmData();
|
||||
}, [activeTab, startTime, endTime, linkId]);
|
||||
}, [activeTab, startTime, endTime, linkId, teamIds, projectIds, tagIds]);
|
||||
|
||||
// 安全地格式化数字
|
||||
const formatNumber = (value: number | undefined | null): string => {
|
||||
|
||||
@@ -770,6 +770,9 @@ export default function HomePage() {
|
||||
<UtmAnalytics
|
||||
startTime={format(dateRange.from, "yyyy-MM-dd'T'HH:mm:ss'Z'")}
|
||||
endTime={format(dateRange.to, "yyyy-MM-dd'T'HH:mm:ss'Z'")}
|
||||
teamIds={selectedTeamIds}
|
||||
projectIds={selectedProjectIds}
|
||||
tagIds={selectedTagIds}
|
||||
/>
|
||||
</>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user