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

Track ecommerce views as new dimensions instead of custom variables #15999

Merged
merged 24 commits into from Jun 9, 2020

Conversation

sgiehl
Copy link
Member

@sgiehl sgiehl commented May 28, 2020

fixes #12035

@sgiehl sgiehl added the Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. label May 28, 2020
@sgiehl sgiehl added this to the 4.0.0 milestone May 28, 2020
@@ -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",
Copy link
Member Author

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>
Copy link
Member Author

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

// 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>
Copy link
Member Author

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");
Copy link
Member Author

@sgiehl sgiehl May 29, 2020

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...

@sgiehl sgiehl added Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. and removed Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. labels May 30, 2020
@sgiehl sgiehl removed the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label May 30, 2020
@sgiehl sgiehl marked this pull request as ready for review May 30, 2020 14:40
Copy link
Member

@tsteur tsteur left a 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

plugins/Ecommerce/Columns/ProductViewName.php Show resolved Hide resolved
plugins/Ecommerce/Columns/ProductViewCategory.php Outdated Show resolved Hide resolved
plugins/Ecommerce/Columns/ProductViewSku.php Show resolved Hide resolved
// 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);
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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', '<')) {
Copy link
Member

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

Copy link
Member Author

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))) {
Copy link
Member

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

@sgiehl
Copy link
Member Author

sgiehl commented Jun 5, 2020

@tsteur left some comments and applied the other feedback

@tsteur
Copy link
Member

tsteur commented Jun 9, 2020

@sgiehl tracking etc worked. Not sure if I was supposed to see this in the visits log?
image
i tracked some data and didn't see it on hover but not sure if it maybe used to be shown? Eg in #12035 (comment) it looks like they used to be shown?

Otherwise worked nicely 👍 Could you maybe add it if needed to the visitor log, resolve merge conflicts and then merge?

@sgiehl sgiehl merged commit 8e25f1c into 4.x-dev Jun 9, 2020
@sgiehl sgiehl deleted the ecommerceview branch June 9, 2020 08:58
@mattab mattab added the Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. label Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ecommerce Product average price may be incorrect, review implementation without using Custom Variables
3 participants