Slow Matomo API responses can be caused by real-time segment calculation rather than server resource limits or cron configuration. Matomo calculates ad-hoc segments on the fly, which can take longer to process, such as using segment=dimension2 in the API method=VisitsSummary.get&segment=dimension2==ABC&format=JSON.

You can improve performance by saving the segment in the user interface and configuring it to be archived in the background. This ensures it is pre-processed, resulting in faster API responses for recurring requests, for example using a defined idSegment=1 in the API method=VisitsSummary.get&idSegment=1&format=JSON.

  1. In the Matomo Dashboard, expand on the Segment Selector.
  2. Click Add new segment and create the segment you are using in your API call.
  3. In the segment editor, choose the configuration option, Segmented reports are pre-processed (faster, requires cron).
    matomo segment editor
  4. Ensure your cron job is running regularly (e.g., hourly), so the segment data is processed during archiving.
  5. Update your API request to use the saved segment.

After saving the segment and running cron, monitor your API response time to confirm that the optimisation is working. You can also learn more about real-time and archived segments in the Matomo Developer Documentation.

Previous FAQ: How do I get the Visitor Geo Location data from the Visitor IP? (or in JavaScript/JSON when IP address is not known)