@code-penguin opened this Issue on February 21st 2017

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 commented on February 21st 2017 Member

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 commented on February 22nd 2017

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 commented on February 22nd 2017 Member

@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 commented on February 23rd 2017 Member

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 commented on February 23rd 2017

@mattab I have just created two pull requests with my changes:
https://github.com/piwik/plugin-CustomDimensions/pull/56
https://github.com/piwik/piwik/pull/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 commented on March 10th 2017

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.

Powered by GitHub Issue Mirror