( projectId: string, startDate: string, endDate: string, interval: 'day' | 'week' | 'month' = 'day' )
| 293 | } |
| 294 | |
| 295 | export async function getGscOverview( |
| 296 | projectId: string, |
| 297 | startDate: string, |
| 298 | endDate: string, |
| 299 | interval: 'day' | 'week' | 'month' = 'day' |
| 300 | ): Promise< |
| 301 | Array<{ |
| 302 | date: string; |
| 303 | clicks: number; |
| 304 | impressions: number; |
| 305 | ctr: number; |
| 306 | position: number; |
| 307 | }> |
| 308 | > { |
| 309 | const dateExpr = |
| 310 | interval === 'month' |
| 311 | ? 'toStartOfMonth(date)' |
| 312 | : interval === 'week' |
| 313 | ? 'toStartOfWeek(date)' |
| 314 | : 'date'; |
| 315 | |
| 316 | const result = await originalCh.query({ |
| 317 | query: ` |
| 318 | SELECT |
| 319 | ${dateExpr} as date, |
| 320 | sum(clicks) as clicks, |
| 321 | sum(impressions) as impressions, |
| 322 | avg(ctr) as ctr, |
| 323 | avg(position) as position |
| 324 | FROM gsc_daily |
| 325 | FINAL |
| 326 | WHERE project_id = {projectId: String} |
| 327 | AND date >= {startDate: String} |
| 328 | AND date <= {endDate: String} |
| 329 | GROUP BY date |
| 330 | ORDER BY date ASC |
| 331 | `, |
| 332 | query_params: { projectId, startDate, endDate }, |
| 333 | format: 'JSONEachRow', |
| 334 | }); |
| 335 | return result.json(); |
| 336 | } |
| 337 | |
| 338 | export async function getGscPages( |
| 339 | projectId: string, |
no test coverage detected