Skip to content

Commit

Permalink
Merge pull request #699 from EPNW/setEcommerceView
Browse files Browse the repository at this point in the history
Implemented setEcommerceView
  • Loading branch information
AltamashShaikh authored Oct 13, 2023
2 parents 507be11 + 0c191e0 commit 9190395
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Template/Tag/MatomoTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public function getParameters()
'initialise' => Piwik::translate('TagManager_InitializeTrackerOnly'),
);
});
$isEcommerceView = $this->makeSetting('isEcommerceView', false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
$field->title = Piwik::translate('TagManager_MatomoTagEcommerceViewIsEcommerceView');
$field->description = Piwik::translate('TagManager_MatomoTagEcommerceViewIsEcommerceViewHelp');
$field->condition = 'trackingType == "pageview"';
});
return array(
$this->makeSetting(self::PARAM_MATOMO_CONFIG, '', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = Piwik::translate('TagManager_MatomoConfigurationVariableName');
Expand Down Expand Up @@ -105,6 +110,55 @@ public function getParameters()
return trim($value);
};
}),
$isEcommerceView,
$this->makeSetting('productSKU', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) use ($trackingType, $isEcommerceView) {
$field->title = Piwik::translate('TagManager_MatomoTagEcommerceViewProductSKU');
$field->customFieldComponent = self::FIELD_VARIABLE_COMPONENT;
$field->description = Piwik::translate('TagManager_MatomoTagEcommerceViewProductSKUHelp');
$field->condition = 'trackingType == "pageview" && isEcommerceView';
if ($trackingType->getValue() === 'pageview' && $isEcommerceView->getValue()) {
$field->validators[] = new CharacterLength(0, 500);
}
$field->transform = function ($value) {
return trim($value);
};
}),
$this->makeSetting('productName', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) use ($trackingType, $isEcommerceView) {
$field->title = Piwik::translate('TagManager_MatomoTagEcommerceViewProductName');
$field->customFieldComponent = self::FIELD_VARIABLE_COMPONENT;
$field->description = Piwik::translate('TagManager_MatomoTagEcommerceViewProductNameHelp');
$field->condition = 'trackingType == "pageview" && isEcommerceView';
if ($trackingType->getValue() === 'pageview' && $isEcommerceView->getValue()) {
$field->validators[] = new CharacterLength(0, 500);
}
$field->transform = function ($value) {
return trim($value);
};
}),
$this->makeSetting('categoryName', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) use ($trackingType, $isEcommerceView) {
$field->title = Piwik::translate('TagManager_MatomoTagEcommerceViewCategoryName');
$field->customFieldComponent = self::FIELD_VARIABLE_COMPONENT;
$field->description = Piwik::translate('TagManager_MatomoTagEcommerceViewCategoryNameHelp');
$field->condition = 'trackingType == "pageview" && isEcommerceView';
if ($trackingType->getValue() === 'pageview' && $isEcommerceView->getValue()) {
$field->validators[] = new CharacterLength(0, 500);
}
$field->transform = function ($value) {
return trim($value);
};
}),
$this->makeSetting('price', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) use ($trackingType, $isEcommerceView) {
$field->title = Piwik::translate('TagManager_MatomoTagEcommerceViewPrice');
$field->customFieldComponent = self::FIELD_VARIABLE_COMPONENT;
$field->description = Piwik::translate('TagManager_MatomoTagEcommerceViewPriceHelp');
$field->condition = 'trackingType == "pageview" && isEcommerceView';
if ($trackingType->getValue() === 'pageview' && $isEcommerceView->getValue()) {
$field->validators[] = new Numeric(true, true);
}
$field->transform = function ($value) {
return trim($value);
};
}),
$this->makeSetting('eventCategory', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) use ($trackingType) {
$field->title = Piwik::translate('Events_EventCategory');
$field->customFieldComponent = self::FIELD_VARIABLE_COMPONENT;
Expand Down
4 changes: 4 additions & 0 deletions Template/Tag/MatomoTag.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@
tracker.setSessionCookieTimeout(matomoConfig.sessionCookieTimeOut * 60);
}

if (parameters.get('isEcommerceView')) {
tracker.setEcommerceView(parameters.get('productSKU'), parameters.get('productName'), parameters.get('categoryName'), parameters.get('price'));
}

tracker.trackPageView();
} else if (trackingType === 'event') {
tracker.trackEvent(parameters.get('eventCategory'), parameters.get('eventAction'), parameters.get('eventName'), parameters.get('eventValue'));
Expand Down
71 changes: 71 additions & 0 deletions Updates/5.0.0-rc5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Plugins\TagManager;

use Piwik\Plugins\TagManager\Template\Tag\MatomoTag;
use Piwik\Plugins\TagManager\UpdateHelper\NewTagParameterMigrator;
use Piwik\Updater;
use Piwik\Updater\Migration;
use Piwik\Updater\Migration\Factory as MigrationFactory;
use Piwik\Updates as PiwikUpdates;

/**
* Update for version 5.0.0-rc5.
*/
class Updates_5_0_0_rc5 extends PiwikUpdates
{
/**
* @var MigrationFactory
*/
private $migration;

public function __construct(MigrationFactory $factory)
{
$this->migration = $factory;
}

/**
* Return database migrations to be executed in this update.
*
* Database migrations should be defined here, instead of in `doUpdate()`, since this method is used
* in the `core:update` command when displaying the queries an update will run. If you execute
* migrations directly in `doUpdate()`, they won't be displayed to the user. Migrations will be executed in the
* order as positioned in the returned array.
*
* @param Updater $updater
* @return Migration\Db[]
*/
public function getMigrations(Updater $updater)
{
return array(
);
}

/**
* Perform the incremental version update.
*
* This method should perform all updating logic. If you define queries in the `getMigrations()` method,
* you must call {@link Updater::executeMigrations()} here.
*
* @param Updater $updater
*/
public function doUpdate(Updater $updater)
{
$updater->executeMigrations(__FILE__, $this->getMigrations($updater));

// Migrate the MatomoConfiguration type variables to all include the newly configured fields.
$migrator = new NewTagParameterMigrator(MatomoTag::ID, 'isEcommerceView', false);
$migrator->addField('productSKU', '');
$migrator->addField('productName', '');
$migrator->addField('categoryName', '');
$migrator->addField('price', '');
$migrator->migrate();
}
}
10 changes: 10 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,16 @@
"MatomoConfigurationMatomoCustomRequestProcessingTitle": "Custom Request Processing",
"MatomoConfigurationMatomoCustomRequestProcessingDescription": "Can be set to a variable of type \"%s\" to augment or override default request sending behaviour.",
"MatomoTagDescription": "Matomo is the leading open source analytics platform.",
"MatomoTagEcommerceViewCategoryName": "Category Name",
"MatomoTagEcommerceViewCategoryNameHelp": "Category page being viewed. On an item's page, this is the item's category.",
"MatomoTagEcommerceViewIsEcommerceView": "Is Ecommerce View",
"MatomoTagEcommerceViewIsEcommerceViewHelp": "Used to record that the current page view is an item (product) page view, or a Ecommerce Category page view. On a category page, you can set the parameter category, and set the other parameters to empty strings. Tracking Product/Category page views will allow Matomo to report on Product & Categories conversion rates (Conversion rate = Ecommerce orders containing this product or category / Visits to the product or category). Requires the Ecommerce plugin to be active.",
"MatomoTagEcommerceViewPrice": "Price",
"MatomoTagEcommerceViewPriceHelp": "Item's display price, not used in standard Matomo reports, but output in API product reports.",
"MatomoTagEcommerceViewProductName": "Product Name",
"MatomoTagEcommerceViewProductNameHelp": "Item's Name being viewed. On a category page this should be empty.",
"MatomoTagEcommerceViewProductSKU": "Product SKU",
"MatomoTagEcommerceViewProductSKUHelp": "Item's SKU code being viewed. On a category page this should be empty.",
"MatomoTagHelp": "This tag lets you track pageviews and events into your Matomo. You can customize the tracking to your needs.",
"MatomoTagName": "Matomo Analytics",
"MetaContentVariableDescription": "Reads a value from a \"meta\" HTML element.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<goalCustomRevenue />
<documentTitle />
<customUrl />
<isEcommerceView>0</isEcommerceView>
<productSKU />
<productName />
<categoryName />
<price />
<eventCategory />
<eventAction />
<eventName />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,102 @@
<name>FieldVariableTemplate</name>
</component>
</row>
<row>
<name>isEcommerceView</name>
<title>Is Ecommerce View</title>
<value>0</value>
<defaultValue>0</defaultValue>
<type>boolean</type>
<uiControl>checkbox</uiControl>
<uiControlAttributes>
</uiControlAttributes>
<availableValues />
<description>Used to record that the current page view is an item (product) page view, or a Ecommerce Category page view. On a category page, you can set the parameter category, and set the other parameters to empty strings. Tracking Product/Category page views will allow Matomo to report on Product &amp; Categories conversion rates (Conversion rate = Ecommerce orders containing this product or category / Visits to the product or category). Requires the Ecommerce plugin to be active.</description>
<inlineHelp />
<introduction />
<condition>trackingType == &quot;pageview&quot;</condition>
<fullWidth>0</fullWidth>
</row>
<row>
<name>productSKU</name>
<title>Product SKU</title>
<value />
<defaultValue />
<type>string</type>
<uiControl>text</uiControl>
<uiControlAttributes>
</uiControlAttributes>
<availableValues />
<description>Item's SKU code being viewed. On a category page this should be empty.</description>
<inlineHelp />
<introduction />
<condition>trackingType == &quot;pageview&quot; &amp;&amp; isEcommerceView</condition>
<fullWidth>0</fullWidth>
<component>
<plugin>TagManager</plugin>
<name>FieldVariableTemplate</name>
</component>
</row>
<row>
<name>productName</name>
<title>Product Name</title>
<value />
<defaultValue />
<type>string</type>
<uiControl>text</uiControl>
<uiControlAttributes>
</uiControlAttributes>
<availableValues />
<description>Item's Name being viewed. On a category page this should be empty.</description>
<inlineHelp />
<introduction />
<condition>trackingType == &quot;pageview&quot; &amp;&amp; isEcommerceView</condition>
<fullWidth>0</fullWidth>
<component>
<plugin>TagManager</plugin>
<name>FieldVariableTemplate</name>
</component>
</row>
<row>
<name>categoryName</name>
<title>Category Name</title>
<value />
<defaultValue />
<type>string</type>
<uiControl>text</uiControl>
<uiControlAttributes>
</uiControlAttributes>
<availableValues />
<description>Category page being viewed. On an item's page, this is the item's category.</description>
<inlineHelp />
<introduction />
<condition>trackingType == &quot;pageview&quot; &amp;&amp; isEcommerceView</condition>
<fullWidth>0</fullWidth>
<component>
<plugin>TagManager</plugin>
<name>FieldVariableTemplate</name>
</component>
</row>
<row>
<name>price</name>
<title>Price</title>
<value />
<defaultValue />
<type>string</type>
<uiControl>text</uiControl>
<uiControlAttributes>
</uiControlAttributes>
<availableValues />
<description>Item's display price, not used in standard Matomo reports, but output in API product reports.</description>
<inlineHelp />
<introduction />
<condition>trackingType == &quot;pageview&quot; &amp;&amp; isEcommerceView</condition>
<fullWidth>0</fullWidth>
<component>
<plugin>TagManager</plugin>
<name>FieldVariableTemplate</name>
</component>
</row>
<row>
<name>eventCategory</name>
<title>Event Category</title>
Expand Down

0 comments on commit 9190395

Please sign in to comment.