( projectId: string, query: string, startDate: string, endDate: string )
| 512 | } |
| 513 | |
| 514 | export async function getGscQueryDetails( |
| 515 | projectId: string, |
| 516 | query: string, |
| 517 | startDate: string, |
| 518 | endDate: string |
| 519 | ): Promise<{ |
| 520 | timeseries: Array<{ date: string; clicks: number; impressions: number; ctr: number; position: number }>; |
| 521 | pages: Array<{ page: string; clicks: number; impressions: number; ctr: number; position: number }>; |
| 522 | }> { |
| 523 | const conn = await db.gscConnection.findUniqueOrThrow({ where: { projectId } }); |
| 524 | const accessToken = await getGscAccessToken(projectId); |
| 525 | const filterGroups: GscFilterGroup[] = [{ filters: [{ dimension: 'query', operator: 'equals', expression: query }] }]; |
| 526 | |
| 527 | const [timeseriesRows, pageRows] = await Promise.all([ |
| 528 | queryGscSearchAnalytics(accessToken, conn.siteUrl, startDate, endDate, ['date'], filterGroups), |
| 529 | queryGscSearchAnalytics(accessToken, conn.siteUrl, startDate, endDate, ['page'], filterGroups), |
| 530 | ]); |
| 531 | |
| 532 | return { |
| 533 | timeseries: timeseriesRows.map((row) => ({ |
| 534 | date: row.keys[0] ?? '', |
| 535 | clicks: row.clicks, |
| 536 | impressions: row.impressions, |
| 537 | ctr: row.ctr, |
| 538 | position: row.position, |
| 539 | })), |
| 540 | pages: pageRows.map((row) => ({ |
| 541 | page: row.keys[0] ?? '', |
| 542 | clicks: row.clicks, |
| 543 | impressions: row.impressions, |
| 544 | ctr: row.ctr, |
| 545 | position: row.position, |
| 546 | })), |
| 547 | }; |
| 548 | } |
| 549 | |
| 550 | export async function getGscQueries( |
| 551 | projectId: string, |
no test coverage detected