API: No results when using segements with years

Hi,

We have some weird effects in our matomo reports when we use segments. I can reproduce the underlying problem using the API, where I’m getting inconsistent results using different periods.

I get expected results when i use period=month

query:
index.php?module=API&method=Actions.getPageUrls&token_auth=...&idSite=1&date=20170101&segment=pageUrl%3D@tirol.gv.at%252Fschwaz%252F&period=month

result:
<?xml version="1.0" encoding="utf-8" ?>
<result>
	<row>
		<label>schwaz</label>
		<nb_visits>9263</nb_visits>
		<nb_hits>10437</nb_hits>
		<sum_time_spent>212838</sum_time_spent>
		<nb_hits_following_search>660</nb_hits_following_search>
		<sum_bandwidth>177068676</sum_bandwidth>
		<nb_hits_with_bandwidth>10018</nb_hits_with_bandwidth>
		<min_bandwidth>29423791</min_bandwidth>
		<max_bandwidth>38628250</max_bandwidth>
		<entry_nb_visits>3269</entry_nb_visits>
		<entry_nb_actions>15929</entry_nb_actions>
		<entry_sum_visit_length>556495</entry_sum_visit_length>
		<entry_bounce_count>1462</entry_bounce_count>
		<exit_nb_visits>2928</exit_nb_visits>
		<avg_bandwidth>17675</avg_bandwidth>
		<avg_time_on_page>20</avg_time_on_page>
		<bounce_rate>45%</bounce_rate>
		<exit_rate>32%</exit_rate>
		<idsubdatatable>1</idsubdatatable>
	</row>
</result>

But following request using period=year gets an empty result:

query:
index.php?module=API&method=Actions.getPageUrls&token_auth=...&idSite=1&date=20170101&segment=pageUrl%3D@tirol.gv.at%252Fschwaz%252F&period=year`

Result:
<?xml version="1.0" encoding="utf-8" ?>
<result />

How is that possible? Any hints how I can dig into this?

Thanks for your help.

I would appreciate any hint.

Did you run into a timeout when the segment was created?

Segments create statistics from the raw data tables - are these tables present for the selected period? Did you try to pre-process this segment?

Hi Peterbo, thanks for your help.

I can’t tell if the preprocessing timed out, but this would make sense and could cause the inconsistencies.

The raw data tables aren’t available for 2017 anymore. Is there a chance to keep the already archived monthly report data and to recreate the year reports based on the monthly reports rather than the raw log data?

No, not for segmentation, unfortunately. Segmentation is always calculated from the raw data. Only if you are pre processing your segment (while the raw data is still present), it will be loaded from the archive tables (and will still be available even if the raw data is deleted). Raw data can’t be recreated from the archive tables. Only from e.g. logfiles via --replay-tracking parameter.

Are you using cron to schedule the report processing? If so, have you checked to ensure that “year” is set to be processsed also?

I know that visitors and users by default do not process for the year by default, although your api example was for page urls and so this should not be the issue.

Also, check out the following to aide debugging this query:
https://matomo.org/faq/how-to/faq_59/