Find your real 24-hour click peak with the Search Console API (hourly data)
The Search Console UI shows a "last 24 hours" view, but it moves every hour. If you only look at it twice a day you'll miss your real peak. Last week our site hit 307 clicks on its best calendar day, but the rolling 24-hour peak was 347 — and I only found it through the API. Here's the small script. 1. Request hourly data The Search Analytics API accepts dataState: "hourly_all" together with the…
The Search Console UI presents a "last 24 hours" view, but it updates every hour. If someone only checks it twice a day, they might overlook their actual peak. Last week, their site achieved a high of 307 clicks on its best day, but the rolling 24-hour peak reached 347. The discrepancy was discovered only by utilizing the API.
To uncover the real peak, the following steps were taken:
1. Request hourly data using the Search Analytics API with dataState: "hourly_all" and the hour dimension. This returns the last few days hour by hour, with timestamps in Pacific Time. The necessary credentials were obtained from a service account file with the scope "https://www.googleapis.com/auth/webmasters.readonly". The API query was made for the site "https://example.com/", with a row limit of 500.
2. Scan a 24-hour window to find the best peak. Initialize a variable "best" as (0, None), then iterate through the rows, creating a window of 24 hours. Calculate the total clicks in each window, and if the current window's clicks exceed the best value, update "best" with the new clicks and the timestamp of the last hour in the window. Print the peak with the format "Peak: X clicks in the 24 h ending YYYY-MM-DD HH:MM:SS". Remember to convert the timestamp to the appropriate time zone before reporting.
3. Examine concentration, not just volume. To differentiate between a spike from a single lucky URL and a spike spread across many pages, use the same API query with the page dimension and daily data. Calculate the total clicks, determine the percentage of pages with clicks, and print the results. In this case, there were 61 pages with clicks, with the top page accounting for only 18% of the total clicks. This indicated that the growth was due to the method rather than a single page.
Important notes:
- Hourly data only covers the last ~10 days. Save it if historical data is needed.
- dataState: "all" includes fresh, not-yet-final data; numbers may fluctuate for a couple of days.
- The 24-hour UI view and the sum can differ by a few clicks due to privacy filtering.
- A scheduled script was used to generate a daily report and post it to Telegram, ensuring the peak is never missed.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to