Best Practices
- Always send
startDateandtoDate, and read a short range at a time, for example seven days. WithoutstartDate,/analyticsreads from the oldest event. Every page call counts all events in the range again, so a wide range makes each call slower and gives many pages. - Use
pageSize1000 and request pages untilpageNumberreachestotalPages. The rows come in no fixed order, so sort them after you have read every page. - Cache the token and reuse it until it expires, see Authentication.
- Treat
404as an empty result. Retry only500and network errors, and wait longer between each attempt. - Use
/analytics/prometheusfor totals and monitoring, and/analyticsfor the hourly detail. - Read the data on a schedule, for example once an hour, not in a tight loop. The count for the current hour keeps growing while events arrive, so a report is most accurate for hours that have already ended. See How the Data Is Collected.
- BI tools such as Power BI need a script to call the API, see BI Integration.
- Make sure your company has a Statistics licence before the period you want to report on. Events that arrive without a valid licence are never added later, and a licence change can take about five minutes to take effect. See How the Data Is Collected.