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
Track ecommerce views as new dimensions instead of custom variables #15999
Conversation
@@ -35,7 +35,7 @@ | |||
"matomo/cache": "~2.0", | |||
"matomo/decompress": "~2.0", | |||
"matomo/ini": "~2.0", | |||
"matomo/matomo-php-tracker": "dev-4.x-dev", | |||
"matomo/matomo-php-tracker": "dev-ecommerceview", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be reverted after matomo-org/matomo-php-tracker#68 has been merged
@@ -7,53 +7,89 @@ | |||
<revenue>2500</revenue> | |||
<quantity>3</quantity> | |||
<orders>2</orders> | |||
<nb_visits>3</nb_visits> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The product view metrics were missing here before because of
Lines 792 to 796 in bc499de
// we do not enter the IF | |
// if case idSite=1,3 AND period=day&date=datefrom,dateto, | |
if ($customVariableTableForDate instanceof DataTable | |
&& $customVariableTableForDate->getMetadata(Archive\DataTableFactory::TABLE_METADATA_PERIOD_INDEX) | |
) { |
That's no longer the case, as product views are directly archived...
@@ -2,19 +2,46 @@ | |||
<result> | |||
<row> | |||
<label>Books Cat #0</label> | |||
<nb_visits>5</nb_visits> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why we have more categories here as before is, that custom variables reports are limited by the report limiting in the test. The ecommerce reports do not have any limits when archived, so all categories are shown now. Not sure if that's something we should maybe change.
deepEqual( tracker3.getCustomVariable(2, "page"), false, "No data Ecommerce price"); | ||
deepEqual( tracker3.getCustomVariable(3, "page"), false, "No data Ecommerce view SKU"); | ||
deepEqual( tracker3.getCustomVariable(4, "page"), false, "No data Ecommerce view Name"); | ||
deepEqual( tracker3.getCustomVariable(5, "page"), ["_pkc",""], "No data Ecommerce view Category"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's no longer possible to receive the product view values, as they are no longer stored in custom variables. Not sure if we should add a getProductView
method in order to be able to test that better...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments. Looks good overall. FYI @mattab this will basically add 8 new columns to log_link_visit_action
// Before Matomo 4.0.0 ecommerce views were tracked in custom variables | ||
// So if Matomo was installed before try to fetch the views from custom variables and enrich the report | ||
if (version_compare(DbHelper::getInstallVersion(),'4.0.0-b2', '<')) { | ||
$this->enrichItemsTableWithViewMetrics($dataTable, $recordName, $idSite, $period, $date, $segment); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the enrichItemsTableWithViewMetrics
might need to check if the custom variables plugin is active since we will move it to the marketplace plus people might deactivate it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might not be fully understanding it... are we there basically merging the metrics from custom variables with the metrics from log_link_visit_action if Matomo was installed before 4.0?
I suppose this would usually be mostly for data on the day they upgrade to Matomo 4 cause all previous day will have data from custom variables and all other ones from log_link_visit_action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's basically for BC. If someone installs Matomo after 4 the variables will be directly tracked into the log_link_visit_action
table, so there is no need to fallback to the old behavior.
If Matomo was installed before it might be possible that there were some ecommerce views tracked as custom variables. If those old data would be archived there wouldn't be any ecommerce views reported, so we try to get those data from the custom variables reports and merge that in. (That was the way it was done before).
Actually we should see in the UI tests that this behaviour works, as I didn't update the OmniFixture.sql, so it still includes ecommerce views as custom variables but is archived with the new logic before the tests run...
$this->enrichItemsTableWithViewMetrics($dataTable, $recordName, $idSite, $period, $date, $segment); | ||
// Before Matomo 4.0.0 ecommerce views were tracked in custom variables | ||
// So if Matomo was installed before try to fetch the views from custom variables and enrich the report | ||
if (version_compare(DbHelper::getInstallVersion(),'4.0.0-b2', '<')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw getInstallVersion might not be set AFAIK as it was only added in 2018
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be fine I guess. version_compare(null, '4.0.0-b2', '<')
returns true
if (in_array($slot, array(\MatomoTracker::CVAR_INDEX_ECOMMERCE_ITEM_SKU, \MatomoTracker::CVAR_INDEX_ECOMMERCE_ITEM_NAME, \MatomoTracker::CVAR_INDEX_ECOMMERCE_ITEM_CATEGORY))) { | ||
// Before Matomo 4.0.0 ecommerce views were tracked in custom variables | ||
// So if Matomo was installed before still try to archive it the old way, as old data might be archived | ||
if (version_compare(DbHelper::getInstallVersion(),'4.0.0-b2', '<') && in_array($slot, array(3, 4, 5))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned below getInstallVersion might not return anything just fyi
@tsteur left some comments and applied the other feedback |
@sgiehl tracking etc worked. Not sure if I was supposed to see this in the visits log? Otherwise worked nicely 👍 Could you maybe add it if needed to the visitor log, resolve merge conflicts and then merge? |
fixes #12035