From d08b8c0afa74a780a4a7a44efff3bf388e8029d9 Mon Sep 17 00:00:00 2001 From: Tomas Persson Date: Sat, 19 Nov 2022 09:41:10 +0100 Subject: [PATCH 1/6] Adding new tracking type to the Matomo Tag Adding new tracking type to the Matomo Tag. --- Template/Tag/MatomoTag.php | 29 +++++++++ Template/Tag/MatomoTag.web.js | 2 + lang/en.json | 7 ++ ...gManager.getAvailableTagTypesInContext.xml | 64 +++++++++++++++++++ 4 files changed, 102 insertions(+) diff --git a/Template/Tag/MatomoTag.php b/Template/Tag/MatomoTag.php index 5eebc078b..6ba95a7e6 100644 --- a/Template/Tag/MatomoTag.php +++ b/Template/Tag/MatomoTag.php @@ -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'), @@ -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) { + $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; diff --git a/Template/Tag/MatomoTag.web.js b/Template/Tag/MatomoTag.web.js index dff84586b..4814ea218 100644 --- a/Template/Tag/MatomoTag.web.js +++ b/Template/Tag/MatomoTag.web.js @@ -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') { diff --git a/lang/en.json b/lang/en.json index 4ffa4e569..df2b64c9d 100644 --- a/lang/en.json +++ b/lang/en.json @@ -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.", @@ -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.", diff --git a/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml b/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml index 984eee5b4..9e873568b 100644 --- a/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml +++ b/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml @@ -88,6 +88,7 @@ Pageview + Search Event Goal Initialise tracker only. Don't track anything. @@ -183,6 +184,69 @@ FieldVariableTemplate + + searchKeyword + Search keyword + + + string + text + + + + The search keyword is what the user searched for. + + + + trackingType == "search" + 0 + + TagManager + FieldVariableTemplate + + + + searchCategory + Search category + + + string + text + + + + Search category selected in your search engine. If you do not need this, set to false. + + + + trackingType == "search" + 0 + + TagManager + FieldVariableTemplate + + + + SearchCount + Search count + + + string + text + + + + The search count to use. Set to false if you don't know. + + + + trackingType == "search" + 0 + + TagManager + FieldVariableTemplate + + eventCategory Event Category From 2a61afd00064d73f9653bb2ce98b427b2328643a Mon Sep 17 00:00:00 2001 From: Tomas Persson Date: Sat, 19 Nov 2022 10:22:16 +0100 Subject: [PATCH 2/6] Fixing tests and adding db updates Fixing tests to match new translations and also adding a new db update script --- Updates/4.12.4-b3.php | 29 +++++++++++++++++++ lang/en.json | 4 +-- ...ontainerVersion_site_default_container.xml | 3 ++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 Updates/4.12.4-b3.php diff --git a/Updates/4.12.4-b3.php b/Updates/4.12.4-b3.php new file mode 100644 index 000000000..6b19f91ce --- /dev/null +++ b/Updates/4.12.4-b3.php @@ -0,0 +1,29 @@ +addField('searchCategory',''); + $migrator2->addField('searchCount',''); + $migrator2->migrate(); + } +} diff --git a/lang/en.json b/lang/en.json index df2b64c9d..33547f07d 100644 --- a/lang/en.json +++ b/lang/en.json @@ -262,9 +262,9 @@ "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", + "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", + "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", diff --git a/tests/System/expected/test___TagManager.exportContainerVersion_site_default_container.xml b/tests/System/expected/test___TagManager.exportContainerVersion_site_default_container.xml index 15ffa0e53..53ca9bc28 100644 --- a/tests/System/expected/test___TagManager.exportContainerVersion_site_default_container.xml +++ b/tests/System/expected/test___TagManager.exportContainerVersion_site_default_container.xml @@ -32,6 +32,9 @@ + + + From 166c1329336c7eb8e7de0b57a55e8270e316eb39 Mon Sep 17 00:00:00 2001 From: Tomas Persson Date: Sat, 19 Nov 2022 15:10:58 +0100 Subject: [PATCH 3/6] Adjust tests --- ...est_webContext__TagManager.getAvailableTagTypesInContext.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml b/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml index 9e873568b..63ea34b08 100644 --- a/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml +++ b/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml @@ -88,7 +88,7 @@ Pageview - Search + Search Event Goal Initialise tracker only. Don't track anything. From c24e60187e40d0408486e0dfd8892ef535d15578 Mon Sep 17 00:00:00 2001 From: Tomas Persson Date: Mon, 21 Nov 2022 13:32:45 +0100 Subject: [PATCH 4/6] Fix tests --- ...t_webContext__TagManager.getAvailableTagTypesInContext.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml b/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml index 63ea34b08..7030176fc 100644 --- a/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml +++ b/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml @@ -209,7 +209,7 @@ searchCategory Search category - + false string text @@ -230,7 +230,7 @@ SearchCount Search count - + false string text From dba2cf47ffd641180248b69bd8ab58302cd683c0 Mon Sep 17 00:00:00 2001 From: Tomas Persson Date: Mon, 21 Nov 2022 14:04:08 +0100 Subject: [PATCH 5/6] New test improvements --- ...t_webContext__TagManager.getAvailableTagTypesInContext.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml b/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml index 7030176fc..f586e694e 100644 --- a/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml +++ b/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml @@ -208,7 +208,7 @@ searchCategory Search category - + false false string text @@ -229,7 +229,7 @@ SearchCount Search count - + false false string text From e3b042f787715c55bb4505cf37009a61e4e8013b Mon Sep 17 00:00:00 2001 From: Tomas Persson Date: Mon, 21 Nov 2022 22:43:43 +0100 Subject: [PATCH 6/6] Another test update --- ...gManager.exportContainerVersion_site_default_container.xml | 4 ++-- ...t_webContext__TagManager.getAvailableTagTypesInContext.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/System/expected/test___TagManager.exportContainerVersion_site_default_container.xml b/tests/System/expected/test___TagManager.exportContainerVersion_site_default_container.xml index 53ca9bc28..c5059ceb5 100644 --- a/tests/System/expected/test___TagManager.exportContainerVersion_site_default_container.xml +++ b/tests/System/expected/test___TagManager.exportContainerVersion_site_default_container.xml @@ -33,8 +33,8 @@ - - + false + false diff --git a/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml b/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml index f586e694e..b73db8f65 100644 --- a/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml +++ b/tests/System/expected/test_webContext__TagManager.getAvailableTagTypesInContext.xml @@ -227,7 +227,7 @@ - SearchCount + searchCount Search count false false