DocumentationStatisticsBest Practices

Best Practices

  • Always send startDate and toDate, and read a short range at a time, for example seven days. Without startDate, /analytics reads 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 pageSize 1000 and request pages until pageNumber reaches totalPages. 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 404 as an empty result. Retry only 500 and network errors, and wait longer between each attempt.
  • Use /analytics/prometheus for totals and monitoring, and /analytics for 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.