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

Adding new tracking type to the Matomo Tag #575

Open
wants to merge 6 commits into
base: 5.x-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Template/Tag/MatomoTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function getParameters()
$field->validators[] = new NotEmpty();
$field->availableValues = array(
'pageview' => Piwik::translate('TagManager_PageViewTriggerName'),
'search' => Piwik::translate('TagManager_SearchTagName'),
'event' => Piwik::translate('Events_Event'),
'goal' => Piwik::translate('General_Goal'),
'initialise' => Piwik::translate('TagManager_InitializeTrackerOnly'),
Expand Down Expand Up @@ -105,6 +106,34 @@ public function getParameters()
return trim($value);
};
}),
$this->makeSetting('searchKeyword', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) use ($trackingType) {
$field->title = Piwik::translate('TagManager_SearchKeyWord');
$field->customFieldComponent = self::FIELD_VARIABLE_COMPONENT;
$field->description = Piwik::translate('TagManager_SearchKeyWordHelp');
$field->condition = 'trackingType == "search"';
if ($trackingType->getValue() === 'search') {
$field->validators[] = new NotEmpty();
$field->validators[] = new CharacterLength(0, 500);
}
}),
$this->makeSetting('searchCategory', 'false', FieldConfig::TYPE_STRING, function (FieldConfig $field) use ($trackingType) {
snake14 marked this conversation as resolved.
Show resolved Hide resolved
$field->title = Piwik::translate('TagManager_SearchCategory');
$field->customFieldComponent = self::FIELD_VARIABLE_COMPONENT;
$field->description = Piwik::translate('TagManager_SearchCategoryHelp');
$field->condition = 'trackingType == "search"';
if ($trackingType->getValue() === 'search') {
$field->validators[] = new CharacterLength(0, 500);
}
}),
$this->makeSetting('searchCount', 'false', FieldConfig::TYPE_STRING, function (FieldConfig $field) use ($trackingType) {
$field->title = Piwik::translate('TagManager_SearchCount');
$field->customFieldComponent = self::FIELD_VARIABLE_COMPONENT;
$field->description = Piwik::translate('TagManager_SearchCountHelp');
$field->condition = 'trackingType == "search"';
if ($trackingType->getValue() === 'search') {
$field->validators[] = new CharacterLength(0, 500);
}
}),
$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
2 changes: 2 additions & 0 deletions Template/Tag/MatomoTag.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@
tracker.setVisitorCookieTimeout(matomoConfig.customCookieTimeOut * 86400);
}
tracker.trackPageView();
} else if (trackingType === 'search') {
tracker.trackSiteSearch(parameters.get('searchKeyword'), parameters.get('searchCategory'), parameters.get('searchCount'));
} else if (trackingType === 'event') {
tracker.trackEvent(parameters.get('eventCategory'), parameters.get('eventAction'), parameters.get('eventName'), parameters.get('eventValue'));
} else if (trackingType === 'goal') {
Expand Down
29 changes: 29 additions & 0 deletions Updates/4.12.4-b3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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\Variable\MatomoConfigurationVariable;
use Piwik\Plugins\TagManager\Updates\NewVariableParameterMigrator;
use Piwik\Updater;
use Piwik\Updates as PiwikUpdates;

/**
* Update for version 4.12.4-b1.
*/
class Updates_4_12_4_b3 extends PiwikUpdates
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomper00 Sorry but can you update this migration class name as per your other PR suggestion ?

{
public function doUpdate(Updater $updater)
{
$migrator2 = new NewTagParameterMigrator(MatomoTag::ID, 'searchKeyword');
$migrator2->addField('searchCategory','');
$migrator2->addField('searchCount','');
$migrator2->migrate();
}
}
7 changes: 7 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@
"CustomTitleHelp": "Optionally, specify a custom document title which should be tracked instead of the default document title.",
"CustomUrl": "Custom URL",
"CustomUrlHelp": "Optionally, specify a custom URL which should be tracked instead of the current location.",
"SearchKeyWord": "Search keyword",
"SearchKeyWordHelp": "The search keyword is what the user searched for.",
"SearchCategory": "Search category",
"SearchCategoryHelp": "Search category selected in your search engine. If you do not need this, set to false.",
"SearchCount": "Search count",
"SearchCountHelp": "The search count to use. Set to false if you don't know.",
"LinkedinInsightTagName": "LinkedIn Insight Tag",
"LinkedinInsightTagDescription": "Adds the LinkedIn Insight Tag so you can apply conversion tracking to your LinkedIn ad campaigns.",
"LinkedinInsightTagHelp": "The tag will enable detailed campaign reporting and information about your website visitors in LinkedIn. It allows you to track conversions, retarget website visitors, and gain additional insights about LinkedIn members that interact with your LinkedIn ads.",
Expand Down Expand Up @@ -627,6 +633,7 @@
"PageUrlVariableName": "Page URL",
"PageViewTriggerDescription": "Triggered as soon as the Tag Manager is executed within the page.",
"PageViewTriggerName": "Pageview",
"SearchTagName": "Search",
"PingdomRUMTagDescription": "Pingdom Real User Monitoring (RUM) lets you collect performance data from actual visitors to your site.",
"PingdomRUMTagHelp": "This tag allows you to add the Pingdom Real User Monitoring (RUM) to your site.",
"PluginDescription": "Manage and unify all your tracking and marketing snippets in one place.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<goalCustomRevenue />
<documentTitle />
<customUrl />
<searchKeyword />
<searchCategory>false</searchCategory>
<searchCount>false</searchCount>
<eventCategory />
<eventAction />
<eventName />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
</uiControlAttributes>
<availableValues>
<pageview>Pageview</pageview>
<search>Search</search>
<event>Event</event>
<goal>Goal</goal>
<initialise>Initialise tracker only. Don't track anything.</initialise>
Expand Down Expand Up @@ -183,6 +184,69 @@
<name>FieldVariableTemplate</name>
</component>
</row>
<row>
<name>searchKeyword</name>
<title>Search keyword</title>
<value />
<defaultValue />
<type>string</type>
<uiControl>text</uiControl>
<uiControlAttributes>
</uiControlAttributes>
<availableValues />
<description>The search keyword is what the user searched for.</description>
<inlineHelp />
<templateFile />
<introduction />
<condition>trackingType == &quot;search&quot;</condition>
<fullWidth>0</fullWidth>
<component>
<plugin>TagManager</plugin>
<name>FieldVariableTemplate</name>
</component>
</row>
<row>
<name>searchCategory</name>
<title>Search category</title>
<value>false</value>
<defaultValue>false</defaultValue>
<type>string</type>
<uiControl>text</uiControl>
<uiControlAttributes>
</uiControlAttributes>
<availableValues />
<description>Search category selected in your search engine. If you do not need this, set to false.</description>
<inlineHelp />
<templateFile />
<introduction />
<condition>trackingType == &quot;search&quot;</condition>
<fullWidth>0</fullWidth>
<component>
<plugin>TagManager</plugin>
<name>FieldVariableTemplate</name>
</component>
</row>
<row>
<name>searchCount</name>
<title>Search count</title>
<value>false</value>
<defaultValue>false</defaultValue>
<type>string</type>
<uiControl>text</uiControl>
<uiControlAttributes>
</uiControlAttributes>
<availableValues />
<description>The search count to use. Set to false if you don't know.</description>
<inlineHelp />
<templateFile />
<introduction />
<condition>trackingType == &quot;search&quot;</condition>
<fullWidth>0</fullWidth>
<component>
<plugin>TagManager</plugin>
<name>FieldVariableTemplate</name>
</component>
</row>
<row>
<name>eventCategory</name>
<title>Event Category</title>
Expand Down