Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#2727 closed Bug (fixed)

pageUrl segment does not work with =@ contains operator

Reported by: matt Owned by:
Priority: major Milestone: 1.7 Piwik 1.7
Component: Core Keywords:
Cc: Sensitive: no

Change History (10)

comment:1 Changed 2 years ago by matt (mattab)

  • Description modified (diff)

comment:2 Changed 2 years ago by matt (mattab)

  • Summary changed from pageUrl segment does not work with =@ operator to pageUrl segment does not work with =@ contains operator

comment:3 Changed 2 years ago by mk3vil

Is there currently another way to achieve the segmentation behavior expected when using the pageUrl segment with the =@ contains operator? Thanks.

comment:4 Changed 2 years ago by EZdesign (BeezyT)

(In [5719]) refs #2727 =@ and !@ for pageUrl / pageTitle segments

comment:5 Changed 2 years ago by EZdesign (BeezyT)

The segmentation mechanism with callbacks was built for comparing against a single ID, which only works for == and !=. I tried to introduce dynamic SQL sub-expression with as little impact on the existing system as possible.

  • For LIKE matches (=@, !@), the callback of the Actions plugin returns an array with the index SQL. This can be discerned from regular literal values.
  • Segment recognizes the array and changes the match type to IN.
  • SegmentExpression recognizes the match type IN and injects the sub-expression. It marks the value as null because there are no parameters to be bound in the sub-expression. This null value is recognized in other parts of SegmentExpression to build the query without a ?-parameter and a bound value.

Btw, I changed the "action not found"-value from -1 to -100 because we were discussing to use -1 for something else. When we do, we would most likely forget to change the value. ;)

Please review.

comment:6 Changed 2 years ago by matt (mattab)

  • Resolution set to fixed
  • Status changed from new to closed

(In [5742]) Fixes #2727

  • Kuddos EZDesign for initial commit!!
  • Reviewed code & now more secure: use bind parameters rather than manually escaping SQL
  • Added integration tests for contains/ does not contain for title/URL. Also added test for the special case characters _ and % (ensure they are properly quoted since they are mysql special characters in a LIKE statement).


  • when you add &segment=pageTitle!=XXXXX to the request, it will sometimes return a different result data set than when the parameter is not added at all (one might expect the same data set in both cases). Adding a segment condition on pageTitle or pageUrl will restrict the visits being looked at, and once you add this condition segment=pageTitle== THEN Piwik will only look at visits that had at least one Page Title and then will apply the condition. ie. When using segment=pageTitle!=test Piwik will IGNORE all visits that do not have any "Page title", and will then exclude the remaining "Page title" that do not match the condition.

  • it does not make sense to call Actions.getPageUrls segmented on pageTitle: result will not be what you expect.

Similarly, calling Actions.getPageTitles with segment=pageUrl=@Test will NOT return page titles that belong to a URL matching Test. Instead it will return all page titles, that have been visited by a visitor that visited a page URL containing Test.

comment:7 Changed 2 years ago by EZdesign (BeezyT)

Nice update, makes it much cleaner!

What makes you think the second limitaion exists? Page title und page URL are both action-based reports/segments, so the output should be as expected. It tried it on my local box and it works.

comment:8 Changed 2 years ago by matt (mattab)

  • Resolution fixed deleted
  • Status changed from closed to reopened

Thanks for feedback, reopening to investigate further my claim

comment:9 Changed 2 years ago by matt (mattab)

  • Resolution set to fixed
  • Status changed from reopened to closed

You're right, it WORKS! :)

comment:10 Changed 2 years ago by matt (mattab)

  • Priority changed from normal to major
Note: See TracTickets for help on using tickets.