Events.getAction API Returning Unexpected Results

I am adding analytics to an existing desktop application. I am tracking events using Matomo’s HTTP API: Tracking HTTP API: API Reference - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3

Here is a sample event I am tracking - I am using the event category, event action, event URL, event name, event value (numeric) and page scope custom variables:

http://localhost/matomo.php?idsite=1&rec=1&url=http://mysiteurl.com/page1/subpage1&e_c=MyEventCategory&e_a=MyEventAction&e_v=500&e_n=MyEventName&cvar={“1”:[“MyCustomVarName1”,“MyCustomVarValue1”],“2”:[“MyCustomVarName2”,“MyCustomVarValue2”]}

We end up tracking around 10-20 “events” like this during a single “visit” on average.

When I try to use the Events.getAction Reporting API, I am finding that the values returned are not what I expect. For example, I want to report on how many individual events have MyCustomVarName1 set to MyCustomVarValue1. I put together a Reporting API query like this:

http://localhost/index.php?module=API&method=Events.getAction&idSite=1&period=year&date=today&format=JSON&token_auth=anonymous&flat=1&segment=customVariablePageName1==MyCustomVarName1;customVariablePageValue1==MyCustomVarValue1

The event counts returned are higher than I expected, and some of the events being returned do NOT have that custom variable set. From what I can discern, if there is a single event in the visit that has that custom variable set, then all events in that visit are “counted” by this query.

Please advise. Thanks!
Cheryl

Hi,

I think this is the same topic as Segments not filtering correctly · Issue #15163 · matomo-org/matomo · GitHub and Full support for Filters in Matomo 4 · Issue #15438 · matomo-org/matomo · GitHub and the linked issues.

Hi,

I am using Matomo v3.12.0 so it does seem like this is one of the same issues noted in the other topic, see viezel’s comment here: Segments not filtering correctly · Issue #15163 · matomo-org/matomo · GitHub about getting more events returned by the reporting API than there really should be / were returned in the past.

I do NOT see that this issue gets resolved by updating:

config/config.ini.php:

[General]
enable_segments_cache = 0

But I do see that I can get accurate results when I use the Matomo dashboard to query for this reporting data instead of the HTTP API - I created a new custom segment via:

Behavior (left side of page) -> Events

And entered the same query info I was previously entering via the HTTP API parameters, and it returned the values I expected.

Is there any way to get the Reporting API to return the precise number of events that match the segment parameter instead of getting the total number of events for each visit that has a single event that matches the segment parameter?

Thank you.

Actually, I found that if I wiped out all data points that had already been tracked, then disabling the segment cache does actually fix the Reporting API (HTTP) issue. Thanks!