Custom Reports calculation bug when Action Dimension and Goals used

Using Matomo 3.13.0 and Custom Reports 3.1.23 (this also happened with previous Matomo / Custom report versions) we see a calculation bug when An Action Dimension is used in conjunction with a GoalID metric.

As a basic example if we had the following:
Action Dimension name “Color” with red, blue, green as values that get set on Page 1 and a goal, “Goal 1” also being set on page 1 unrelated to the color value and being set just by accessing the page (which can be set multiple times per visit), the goal count is incorrect in a Custom report where the Action dimension “color” is used as a Report dimension and “Goal 1 Conversion Count” is used as a metric.

Basically what we see is that the goal count metric isn’t constrained by each Action dimension value row. An example with the following sample traffic:

Visitor 1
Visit 1: Page 1, color red, goal fired
Visit 2: Page 1, color blue, goal fired
Visit 3: Page 1, color green, goal fired

Visitor 2
Visit 1: Page 1, color red, goal fired
Visit 2: Page 1, color green, goal fired

In a custom report defined as above we should see:

Color, GoalID Conversion
red,2
blue,1
green,2

What we actually see is:

Color, GoalID Conversion
red,5
blue,1
green,5

Glancing through the code it seems to be an issue in the Querybuilder.php file. Happy to share real data/repro cases as needed to help diagnose and resolve. Thanks.

Hi,

I have tried to recreate this exact scenario:

I have an action dimension that grabs the colour from the URL, and goal that is converted when the URL contains colour. Here are the visits:

Here is the report:

This seems to be in order?

The bug occurs when you have multiple goal conversions with different action dimension values in the same visit. If in one of those visits you have an action with color =red and another action with color = blue, each converting the goal, you’d have an overcount where red would show 3 (because it would also count the blue goal conversion in the same visit) and blue would also show 3 because of the same issue.