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

Dimensions are not saved for manual goal conversions #16147

Open
code-penguin opened this issue Feb 21, 2017 · 15 comments
Open

Dimensions are not saved for manual goal conversions #16147

code-penguin opened this issue Feb 21, 2017 · 15 comments
Labels
c: Custom Dimensions For issues related to the Custom Dimensions plugin. Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.

Comments

@code-penguin
Copy link

I have the use case that I want to manually trigger a conversion when a user clicks on a button, and store additional data with that conversion. My goal is configured to allow multiple conversions per visit. For the data I have created an 'action dimension'.
I trigger the conversion manually as described in the documentation:
https://developer.piwik.org/guides/tracking-javascript-guide#tracking-a-custom-dimension-for-one-specific-action-only
_paq.push(['trackGoal', idGoal, customRevenue, {dimension1: 'DimensionValue'}]);

In this scenario, the custom dimension is not saved with the conversion; I would expect the custom_dimension_X field in each newly added row in the piwik_log_conversion table to be filled, but this is not the case.

I have taken a look at the code and think I have found the cause. In the CustomDimensionsRequestProcessor class the dimensions are only updated on visits (onNewVisit, onExistingVisit) and on actions (afterRequestProcessed), but not on conversions. To work around this I have modified CustomDimensionsRequestProcessor::afterRequestProcessed to temporarily store the dimensions as metadata on the request, and then retrieve this metadata in GoalManager::recordGoals and add it to the goal. With these changes the dimensions are now saved in the piwik_log_conversion table as expected.

Would love to hear your opinion on this, if there is any "proper" way to accomplish this or if it really is a bug / missing feature.

@tsteur
Copy link
Member

tsteur commented Feb 21, 2017

It is supposed to write into custom dimension in log conversion via the Tracker.newConversionInformation event in the method CustomDimensions::addConversionInformation(). The thing is by looking at the code: It seems to only look for visit custom dimensions, not action custom dimensions which is the behaviour you describe.

Why is this the case? Because we can still get the action dimensions for this conversion why the link from the log_conversion table to the log_link_visit_action table on idlink_va.

So the tracking itself should be fine. It might be maybe more of a reporting issue that likely only conversion dimensions are shown in the reporting but not related action dimensions? This is likely same behaviour as for custom variables I reckon.

@code-penguin
Copy link
Author

Thank you for your reply!
Yes I haven't tried it with visit dimensions because I only want to save this extra information for the conversions and not for the visit.
As far as I can tell though it's not possible to get the action dimensions for conversions from the log_link_visit_action table if you trigger the conversions manually. Because in GoalsRequestProcessor::processRequestParams the action is set to 'null' in this case, so there is no action..

@tsteur
Copy link
Member

tsteur commented Feb 22, 2017

@mattab what do you think? It sounds to me like adding action dimension reports to goals "by dimension" report but not sure.

Another way that may work (rather a workaround) would be to go to "Actions => $YourActionDimension" then apply a segment by Goal "Visit converted a specific Goal ID". You should see the dimensions used when it was converted but haven't tested it.

@mattab
Copy link
Member

mattab commented Feb 23, 2017

It sounds to me like adding action dimension reports to goals "by dimension" report but not sure.

That's my understanding as well. I wonder why we didn't implement it as it seems to make sense that action-dimensions would be duplicated in log_conversion.

@code-penguin maybe you could create a pull request with your changes to have action dimensions stored in log_conversion?

code-penguin referenced this issue in code-penguin/plugin-CustomDimensions Feb 23, 2017
@code-penguin
Copy link
Author

@mattab I have just created two pull requests with my changes:
matomo-org/plugin-CustomDimensions#56
#11400
Unfortunately I had to make changes outside the plugin because I couldn't find an easy way to have the extra data picked up automatically. For actions there is $action->setCustomField but for goals there are no objects. If you have suggestions on how to prevent changing the piwik core for this, those are of course welcome.

code-penguin referenced this issue in code-penguin/plugin-CustomDimensions Feb 24, 2017
…o conversions directly in addConversionInformation()
code-penguin referenced this issue in code-penguin/plugin-CustomDimensions Mar 1, 2017
…t; otherwise, use getCustomDimensionsInScope()
code-penguin referenced this issue in code-penguin/plugin-CustomDimensions Mar 6, 2017
@code-penguin
Copy link
Author

Hi guys, it looks my fix is not quite complete. The custom dimensions are now correctly stored in the log_conversion table, but there doesn't seem to be any way to then use them in reports. I think part of the problem is that Archiver::aggregateDayReport only adds custom dimensions to archives from visits and actions, and ignores the action dimensions stored in log_conversion. But even when I work around this, a segment on 'dimensionX=myvalue' will always return 0 for nb_conversions. Maybe one of you can look into this and let me know how it should work, so I can start making a fix.

@tsteur tsteur transferred this issue from matomo-org/plugin-CustomDimensions Jun 29, 2020
@tsteur tsteur added c: Custom Dimensions For issues related to the Custom Dimensions plugin. Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. labels Jun 29, 2020
@peterbo
Copy link
Contributor

peterbo commented Apr 15, 2021

@code-penguin - What are the ToDos on this ticket? Only the reporting? This seems to be a quite good feature if it worked!

@sgiehl
Copy link
Member

sgiehl commented Apr 15, 2021

@peterbo Did you check if that still doesn't work? I've just tested it with a manually triggered _paq.push(['trackGoal', idGoal, customRevenue, {dimension1: 'DimensionValue'}]); locally. And the custom dimension was set correctly in the log_conversion table. Maybe this issue has been fixed meanwhile and can be closed?

@peterbo
Copy link
Contributor

peterbo commented Apr 15, 2021

Hi @sgiehl ! - For visit scope custom dimensions, this works, but not for action scope Custom dimensions. This would make a lot of sense to attach multiple attributes to a conversion. Otherwise, you'd have to send an event along with all custom dimensions attached. But getting this reported afterwards is a nightmare.

For example, the request:
https://example.com/piwik.php?cdt=2021-04-14+15%3A52%3A28&revenue=130&idsite=123&uid=XXX&token_auth=XXX&rec=1&r=735130&idgoal=58&dimension31=test&dimension32=depot&dimension33=test

results in the following goal reported in the API:

actionDimensions

dimensions31/32/33 are all action dimensions.

@sgiehl
Copy link
Member

sgiehl commented Apr 15, 2021

I guess that is actually by design. For the scope conversion the defined dimensions of scope visits are used, so there won't be any action dimensions tracked. See e.g.

public function addConversionInformation(&$conversion, $visitInformation, Tracker\Request $request)
{
$dimensions = CustomDimensionsRequestProcessor::getCachedCustomDimensions($request);
// we copy all visit custom dimensions, but only if the index also exists in the conversion table
// to not fail while conversion custom dimensions are added
$conversionIndexes = $this->getCachedInstalledIndexesForScope(self::SCOPE_CONVERSION);
$conversionIndexes = array_map(function ($index) {
return (int) $index; // make sure we work with integers
}, $conversionIndexes);
foreach ($dimensions as $dimension) {
$index = (int) $dimension['index'];
if ($dimension['scope'] === self::SCOPE_VISIT && in_array($index, $conversionIndexes)) {
$field = LogTable::buildCustomDimensionColumnName($dimension);
if (array_key_exists($field, $visitInformation)) {
$conversion[$field] = $visitInformation[$field];
}
}
}
}

@peterbo
Copy link
Contributor

peterbo commented Apr 15, 2021

@sgiehl - thank you for providing the code! Ok, I see. Having this would be great, also an action custom dimension report in the goals report would be a fantastic tool.

For other users, that are pulling their hair out, searching for the reason, why this doesn't work, we should probably note this in the documentation until this might be implemented, because from a user's perspective, this is not self-explanatory (even if it makes sense from a coder's perspective):
https://developer.matomo.org/guides/tracking-javascript-guide#tracking-a-custom-dimension-for-one-specific-action-only

@sgiehl
Copy link
Member

sgiehl commented Apr 15, 2021

The "problem" is that the log_conversion table holds his own customdimension columns. Currently they are kind of synced with the visit dimension ones. If we would like to have visit and action dimensions here we would need to hold columns for both.
But actually I wonder why it holds the visit dimensions at all. Those could be determined by joining the log_visit table any time. So in theory it might make more sense to store the action dimensions here instead.
Another possibility would be to allow defining the dimensions for scope conversion...

@peterbo
Copy link
Contributor

peterbo commented Apr 15, 2021

Great ideas, @sgiehl !! - I would vote for the scope conversion proposal. From an analytical perspective, conversion attributes are most often distinct from attribute types that are tracked for (behavioural) actions. And also from the coding perspective, this could make things a bit easier (no values would have to be kept in sync or doubled in the conversions table).

The only place where it could make sense to copy values, is an event that triggers a goal (goal setting). In this case, it would make sense to copy the action dimenions (that were attached to the triggering event) to the conversion scope custom dimension.

@MatomoForumNotifications

This issue has been mentioned on Matomo forums. There might be relevant details there:

https://forum.matomo.org/t/custom-dimension-on-a-ecommerce-purchase/55146/2

@MatomoForumNotifications

This issue has been mentioned on Matomo forums. There might be relevant details there:

https://forum.matomo.org/t/does-custom-action-dimension-from-event-not-reach-its-goal-custom-action-dimension-for-goal/54262/13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Custom Dimensions For issues related to the Custom Dimensions plugin. Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Projects
None yet
Development

No branches or pull requests

7 participants