Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combining Segments with comma not working in API call #18426

Closed
albertski opened this issue Dec 1, 2021 · 4 comments
Closed

Combining Segments with comma not working in API call #18426

albertski opened this issue Dec 1, 2021 · 4 comments
Labels
answered For when a question was asked and we referred to forum or answered it.

Comments

@albertski
Copy link

albertski commented Dec 1, 2021

Looking over the docs, it mentions to comma separate the segments to use an OR condition, but it isn't working. When I comma separate my two segments (segment=eventCategory==MyFirstEvent,eventCategory==MySecondEvent), I get no records. If I run them separately (segment=eventCategory==MyFirstEvent), I do get a response.

Sample API Call that has two segments that is not working

https://www.example.com/piwik/index.php?module=API&method=Events.getCategory&secondaryDimension=eventAction&flat=1&token_auth=mykey&format=json&widget=1&moduleToWidgetize=Events&actionToWidgetize=getCategory&idSite=1&period=week&date=2021-11-15&filter_sort_column=nb_events&disableLink=1&filter_sort_order=desc&segment=eventCategory==MyFirstEvent,eventCategory==MySecondEvent

If I call MyFirstEvent and MySecondEvent separately, it does work so it looks like the comma separation is not work.

Working (with only MyFirstEvent):

https://www.example.com/index.php?module=API&method=Events.getCategory&secondaryDimension=eventAction&flat=1&token_auth=mykey&format=json&widget=1&moduleToWidgetize=Events&actionToWidgetize=getCategory&idSite=1&period=week&date=2021-11-15&filter_sort_column=nb_events&disableLink=1&filter_sort_order=desc&segment=eventCategory==MyFirstEvent

Working (with only MySecondEvent):

https://www.example.com/iindex.php?module=API&method=Events.getCategory&secondaryDimension=eventAction&flat=1&token_auth=mykey&format=json&widget=1&moduleToWidgetize=Events&actionToWidgetize=getCategory&idSite=1&period=week&date=2021-11-15&filter_sort_column=nb_events&disableLink=1&filter_sort_order=desc&segment=eventCategory==MySecondEvent

Your Environment

  • Matomo Version: 4.6.1
  • PHP Version: PHP 7.4
  • MySQL version: 10.2.41-MariaDB-log
  • Browser: Chrome / Safari
  • Operating System: CentOS Linux release 7.9.2009 (Core)
@albertski albertski added the Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. label Dec 1, 2021
@sgiehl
Copy link
Member

sgiehl commented Dec 2, 2021

@albertski For me or combined segments work as expected. Maybe you need to escape the segment in the url like segment=eventCategory%3D%3DMyFirstEvent,eventCategory%3D%3DMySecondEvent. Also depending on your archiving setting new segments might need to be archived before they are showing data...

Btw. what are you actually trying to achieve? Using the eventCategory segment on the Events report, might not result in what you might possibly expect. The eventCategory segment will segment for all visitors that had an event action with that category. The Event reports may therefor also include other event categories, which those segmented visitors had.

@albertski
Copy link
Author

@sgiehl Say I have 10 events displaying but I only want two of them. I was using the segment to only display the two. Is that not a good approach? I also tried to escape the segment in the URL and it also does not work.

@sgiehl
Copy link
Member

sgiehl commented Dec 2, 2021

Segments are actually good for "filtering" the data used to generate the report. So if you would like to see all events done by users using windows, or all countries users with tablets came from,.... But in your case it sound like you actually want to filter that specific report for certain values? In that case segments are actually a bad choice, because they take a lot time for calculation, which would actually be unneeded. You can use the filter_pattern api parameter. See https://developer.matomo.org/api-reference/reporting-api

@heurteph-ei
Copy link

Issue still to be let opened?

@sgiehl sgiehl closed this as completed Dec 22, 2021
@tsteur tsteur added answered For when a question was asked and we referred to forum or answered it. and removed Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. labels Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it.
Projects
None yet
Development

No branches or pull requests

4 participants