| 36 | const lastWeek = new Date(today.getTime() - oneWeek); |
| 37 | |
| 38 | async function runSample() { |
| 39 | const list = await searchconsole.sites.list(); |
| 40 | // console.log('%j', list.data.siteEntry); |
| 41 | |
| 42 | const all: any = []; |
| 43 | if (list.data.siteEntry) { |
| 44 | for (const site of list.data.siteEntry) { |
| 45 | if (site.siteUrl) { |
| 46 | const result = await searchconsole.searchanalytics |
| 47 | .query({ |
| 48 | requestBody: { |
| 49 | // dimensions: ['date'], |
| 50 | // dimensions: ['page'], // top pages |
| 51 | startDate: lastWeek.toISOString().substring(0, 10), |
| 52 | endDate: today.toISOString().substring(0, 10), |
| 53 | }, |
| 54 | siteUrl: site.siteUrl, |
| 55 | }) |
| 56 | .catch((e) => { |
| 57 | console.error(e); |
| 58 | }); |
| 59 | if (result) { |
| 60 | const info = { |
| 61 | site: site.siteUrl, |
| 62 | ...result.data.rows?.pop(), |
| 63 | }; |
| 64 | console.log(info); |
| 65 | all.push(info); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | console.log( |
| 72 | JSON.stringify( |
| 73 | all.sort((a: any, b: any) => b.clicks - a.clicks), |
| 74 | null, |
| 75 | 2 |
| 76 | ) |
| 77 | ); |
| 78 | } |