diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/CoreHome/angularjs/content-block/content-block.directive.js | 3 | ||||
-rw-r--r-- | plugins/CoreHome/angularjs/widget-loader/widgetloader.directive.js | 3 | ||||
-rw-r--r-- | plugins/SitesManager/Controller.php | 67 | ||||
-rw-r--r-- | plugins/SitesManager/GtmSiteTypeGuesser.php | 68 | ||||
-rw-r--r-- | plugins/SitesManager/SitesManager.php | 21 | ||||
-rw-r--r-- | plugins/SitesManager/lang/en.json | 14 | ||||
-rw-r--r-- | plugins/SitesManager/stylesheets/SitesManager.less | 4 | ||||
-rw-r--r-- | plugins/SitesManager/templates/_siteWithoutDataTabs.twig | 87 | ||||
-rw-r--r-- | plugins/SitesManager/templates/siteWithoutData.twig | 89 | ||||
-rw-r--r-- | plugins/SitesManager/tests/Unit/GuessSiteTypeAndGtmTest.php | 102 |
10 files changed, 373 insertions, 85 deletions
diff --git a/plugins/CoreHome/angularjs/content-block/content-block.directive.js b/plugins/CoreHome/angularjs/content-block/content-block.directive.js index 2746f58ab5..d803bb98c5 100644 --- a/plugins/CoreHome/angularjs/content-block/content-block.directive.js +++ b/plugins/CoreHome/angularjs/content-block/content-block.directive.js @@ -82,9 +82,8 @@ element.css('marginTop', '0'); } } - }; } }; } -})();
\ No newline at end of file +})(); diff --git a/plugins/CoreHome/angularjs/widget-loader/widgetloader.directive.js b/plugins/CoreHome/angularjs/widget-loader/widgetloader.directive.js index be6de1bf47..b1c0c3a11d 100644 --- a/plugins/CoreHome/angularjs/widget-loader/widgetloader.directive.js +++ b/plugins/CoreHome/angularjs/widget-loader/widgetloader.directive.js @@ -27,7 +27,8 @@ transclude: true, scope: { piwikWidgetLoader: '=', - widgetName: '@' + widgetName: '@', + loadingMessage: '@' }, templateUrl: 'plugins/CoreHome/angularjs/widget-loader/widgetloader.directive.html?cb=' + piwik.cacheBuster, compile: function (element, attrs) { diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php index 5888aaf60e..79cf29882b 100644 --- a/plugins/SitesManager/Controller.php +++ b/plugins/SitesManager/Controller.php @@ -22,12 +22,24 @@ use Piwik\Site; use Piwik\Tracker\TrackerCodeGenerator; use Piwik\Url; use Piwik\View; +use Piwik\Http; +use Piwik\Plugins\SitesManager\GtmSiteTypeGuesser; +use Matomo\Cache\Lazy; /** * */ class Controller extends \Piwik\Plugin\ControllerAdmin { + /** @var Lazy */ + private $cache; + + public function __construct(Lazy $cache) { + $this->cache = $cache; + + parent::__construct(); + } + /** * Main view showing listing of websites and settings */ @@ -38,7 +50,7 @@ class Controller extends \Piwik\Plugin\ControllerAdmin return $this->renderTemplate('index'); } - + public function globalSettings() { Piwik::checkUserHasSuperUserAccess(); @@ -146,6 +158,47 @@ class Controller extends \Piwik\Plugin\ControllerAdmin 'idSite' => $this->idSite ), $viewType = 'basic'); + return $this->renderTemplateAs('siteWithoutData', array( + 'siteName' => $this->site->getName(), + 'idSite' => $this->idSite, + 'piwikUrl' => $piwikUrl, + 'emailBody' => $emailContent, + ), $viewType = 'basic'); + } + + public function siteWithoutDataTabs() { + $typeCacheId = 'guessedtype_' . md5($this->site->getMainUrl()); + $gtmCacheId = 'guessedgtm_' . md5($this->site->getMainUrl()); + + $siteType = $this->cache->fetch($typeCacheId); + $gtmUsed = $this->cache->fetch($gtmCacheId); + + if (!$siteType) { + try { + $response = Http::sendHttpRequest($this->site->getMainUrl(), 5, null, null, 0, false, false, true); + } catch (Exception $e) { + $response = false; + } + + $guesser = new GtmSiteTypeGuesser(); + $siteType = $guesser->guessSiteTypeFromResponse($response); + $gtmUsed = $guesser->guessGtmFromResponse($response); + + $this->cache->save($typeCacheId, $siteType, 60 * 60 * 24); + $this->cache->save($gtmCacheId, $gtmUsed, 60 * 60 * 24); + } + + $instructionUrl = SitesManager::getInstructionUrlBySiteType($siteType); + + $piwikUrl = Url::getCurrentUrlWithoutFileName(); + $jsTag = Request::processRequest('SitesManager.getJavascriptTag', array('idSite' => $this->idSite, 'piwikUrl' => $piwikUrl)); + + $showMatomoLinks = true; + /** + * @ignore + */ + Piwik::postEvent('SitesManager.showMatomoLinksInTrackingCodeEmail', array(&$showMatomoLinks)); + $googleAnalyticsImporterMessage = ''; if (Manager::getInstance()->isPluginLoaded('GoogleAnalyticsImporter')) { $googleAnalyticsImporterMessage = '<h3>' . Piwik::translate('CoreAdminHome_ImportFromGoogleAnalytics') . '</h3>' @@ -158,14 +211,22 @@ class Controller extends \Piwik\Plugin\ControllerAdmin Piwik::postEvent('SitesManager.siteWithoutData.customizeImporterMessage', [&$googleAnalyticsImporterMessage]); } - return $this->renderTemplateAs('siteWithoutData', array( + $tagManagerActive = false; + if (Manager::getInstance()->isPluginActivated('TagManager')) { + $tagManagerActive = true; + } + + return $this->renderTemplateAs('_siteWithoutDataTabs', array( 'siteName' => $this->site->getName(), 'idSite' => $this->idSite, 'jsTag' => $jsTag, 'piwikUrl' => $piwikUrl, - 'emailBody' => $emailContent, 'showMatomoLinks' => $showMatomoLinks, + 'siteType' => $siteType, + 'instructionUrl' => $instructionUrl, + 'gtmUsed' => $gtmUsed, 'googleAnalyticsImporterMessage' => $googleAnalyticsImporterMessage, + 'tagManagerActive' => $tagManagerActive, ), $viewType = 'basic'); } } diff --git a/plugins/SitesManager/GtmSiteTypeGuesser.php b/plugins/SitesManager/GtmSiteTypeGuesser.php new file mode 100644 index 0000000000..d79313c275 --- /dev/null +++ b/plugins/SitesManager/GtmSiteTypeGuesser.php @@ -0,0 +1,68 @@ +<?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\SitesManager; + +use Piwik\Plugins\SitesManager\SitesManager; + +class GtmSiteTypeGuesser +{ + public function guessSiteTypeFromResponse($response) + { + if ($response === false) { + return SitesManager::SITE_TYPE_UNKNOWN; + } + + $needle = '/wp-content'; + if (strpos($response['data'], $needle) !== false) { + return SitesManager::SITE_TYPE_WORDPRESS; + } + + $needle = '<!-- This is Squarespace. -->'; + if (strpos($response['data'], $needle) !== false) { + return SitesManager::SITE_TYPE_SQUARESPACE; + } + + $needle = 'X-Wix-Published-Version'; + if (strpos($response['data'], $needle) !== false) { + return SitesManager::SITE_TYPE_WIX; + } + + // https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Application/WebApplication.php#L516 + // Joomla was the outcome of a fork of Mambo on 17 August 2005 - https://en.wikipedia.org/wiki/Joomla + if (isset($response['headers']['expires']) && $response['headers']['expires'] === 'Wed, 17 Aug 2005 00:00:00 GMT') { + return SitesManager::SITE_TYPE_JOOMLA; + } + + $needle = 'Shopify.theme'; + if (strpos($response['data'], $needle) !== false) { + return SitesManager::SITE_TYPE_SHOPIFY; + } + + $needle = 'content="Microsoft SharePoint'; + if (strpos($response['data'], $needle) !== false) { + return SitesManager::SITE_TYPE_SHAREPOINT; + } + + return SitesManager::SITE_TYPE_UNKNOWN; + } + + public function guessGtmFromResponse($response) + { + if ($response === false) { + return false; + } + + $needle = 'gtm.start'; + if (strpos($response['data'], $needle) !== false) { + return true; + } + + return false; + } +} diff --git a/plugins/SitesManager/SitesManager.php b/plugins/SitesManager/SitesManager.php index 8a40bc4a98..3c0fa2a8c6 100644 --- a/plugins/SitesManager/SitesManager.php +++ b/plugins/SitesManager/SitesManager.php @@ -32,6 +32,13 @@ class SitesManager extends \Piwik\Plugin const KEEP_URL_FRAGMENT_USE_DEFAULT = 0; const KEEP_URL_FRAGMENT_YES = 1; const KEEP_URL_FRAGMENT_NO = 2; + const SITE_TYPE_UNKNOWN = 'unknown'; + const SITE_TYPE_WORDPRESS = 'wordpress'; + const SITE_TYPE_SQUARESPACE = 'squarespace'; + const SITE_TYPE_WIX = 'wix'; + const SITE_TYPE_SHAREPOINT = 'sharepoint'; + const SITE_TYPE_JOOMLA = 'joomla'; + const SITE_TYPE_SHOPIFY = 'shopify'; /** * @see \Piwik\Plugin::registerEvents @@ -351,6 +358,20 @@ class SitesManager extends \Piwik\Plugin return $hosts; } + public static function getInstructionUrlBySiteType($siteType) + { + $map = [ + self::SITE_TYPE_JOOMLA => 'https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-analytics-tracking-code-on-joomla', + self::SITE_TYPE_SHAREPOINT => 'https://matomo.org/faq/how-to-install/faq_19424', + self::SITE_TYPE_SHOPIFY => 'https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-my-shopify-store', + self::SITE_TYPE_SQUARESPACE => 'https://matomo.org/faq/new-to-piwik/how-do-i-integrate-matomo-with-squarespace-website', + self::SITE_TYPE_WIX => 'https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-analytics-tracking-code-on-wix', + self::SITE_TYPE_WORDPRESS => 'https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-wordpress', + ]; + + return $map[$siteType] ? $map[$siteType] : false; + } + public function getClientSideTranslationKeys(&$translationKeys) { $translationKeys[] = "General_Save"; diff --git a/plugins/SitesManager/lang/en.json b/plugins/SitesManager/lang/en.json index 08b7131082..fc4ea83428 100644 --- a/plugins/SitesManager/lang/en.json +++ b/plugins/SitesManager/lang/en.json @@ -76,10 +76,19 @@ "Sites": "Websites", "SiteSearchUse": "You can use Matomo to track and report what visitors are searching in your website's internal search engine.", "SiteWithoutDataTitle": "No data has been recorded yet, get set up below", - "SiteWithoutDataDescription": "No analytics data has been tracked for this website yet.", + "SiteWithoutDataDescription": "Only one last step to track your web traffic with Matomo and gain valuable insights. You need to add some extra code to your website or mobile app if you haven't done already. Check your option below or %1$ssend all the instructions to a team mate%2$s.", "SiteWithoutDataSetupTracking": "Please set up the %1$stracking code%2$s below into your website or mobile app if you haven't done already.", "SiteWithoutDataMessageDisappears": "This message will disappear as soon as some data was tracked for this website.", "SiteWithoutDataIgnoreMessage": "Don't show this message for the next hour", + "SiteWithoutDataChoosePreferredWay": "Choose your preferred way of getting set up", + "SiteWithoutDataOtherWays": "Other ways", + "SiteWithoutDataOtherIntegrations": "Other integrations", + "SiteWithoutDataGoogleTagManager": "Google Tag Manager", + "SiteWithoutDataMatomoTagManager": "Matomo Tag Manager", + "SiteWithoutDataMatomoTagManagerNotActive": "Don't know what a Tag Manager is? Check out our %1$sTag Manager guide%2$s. If you are embedding multiple resources from 3rd party websites into your website, then tracking your website using the Tag Manager may be a better choice for you compared to using the regular JavaScript tracking.", + "SiteWithoutDataGoogleTagManagerDescription": "You can use Matomo with Google Tag Manager. To setup Matomo Tracking in Google Tag Manager, follow the instructions from this %1$sguide%2$s.", + "SiteWithoutDataDetectedSite": "We've detected you're using a %1$s site. Simple follow the instructions from this %2$sguide%3$s.", + "SiteWithoutDataDetectedGtm": "We've also detected you're using a Google Tag Manager. If you prefer to set up Matomo using GTM please follow this %2$sguide%3$s.", "SuperUserAccessCan": "A user with Super User access can also %1$s specify global settings%2$s for new websites.", "Timezone": "Time zone", "TrackingSiteSearch": "Tracking Internal Site Search", @@ -103,6 +112,7 @@ "EmailInstructionsSiteDetailsHeading": "Your Site Details", "EmailInstructionsSiteDetails": "You will need these details to use the API or SDKs to track Matomo visits.", "EmailInstructionsYourSiteId": "Your site ID: %1$s", - "EmailInstructionsYourTrackingUrl": "Your tracking URL: %1$s" + "EmailInstructionsYourTrackingUrl": "Your tracking URL: %1$s", + "DetectingYourSite": "Detecting your site" } } diff --git a/plugins/SitesManager/stylesheets/SitesManager.less b/plugins/SitesManager/stylesheets/SitesManager.less index 898f801755..3fcff25546 100644 --- a/plugins/SitesManager/stylesheets/SitesManager.less +++ b/plugins/SitesManager/stylesheets/SitesManager.less @@ -121,6 +121,10 @@ td.editable-site-field:hover { h3 { font-weight: bold; } + + p { + padding-bottom: 0.25rem; + } } #js-visitor-cv-extra th { diff --git a/plugins/SitesManager/templates/_siteWithoutDataTabs.twig b/plugins/SitesManager/templates/_siteWithoutDataTabs.twig new file mode 100644 index 0000000000..6e50deb89e --- /dev/null +++ b/plugins/SitesManager/templates/_siteWithoutDataTabs.twig @@ -0,0 +1,87 @@ +<script type="text/javascript"> + $(document).ready(function(){ + $('.tabs').tabs(); + }); +</script> + +<div class="row"> + <div class="col s12"> + <ul class="tabs"> + <li class="tab col s3"><a {% if siteType != constant('Piwik\\Plugins\\SitesManager\\SitesManager::SITE_TYPE_UNKNOWN') %} class="active" {% endif %} href="#integrations">{{ 'SitesManager_Integrations'|translate }}</a></li> + <li class="tab col s3"><a {% if siteType == constant('Piwik\\Plugins\\SitesManager\\SitesManager::SITE_TYPE_UNKNOWN') %} class="active" {% endif %} href="#tracking-code">{{ 'CoreAdminHome_TrackingCode'|translate}}</a></li> + <li class="tab col s3"><a href="#mtm">{{ 'SitesManager_SiteWithoutDataMatomoTagManager'|translate}}</a></li> + <li class="tab col s3"><a href="#other">{{ 'SitesManager_SiteWithoutDataOtherWays'|translate }}</a></li> + </ul> + </div> + + <div id="integrations" class="col s12"> + <h3>{{ 'SitesManager_Integrations'|translate }}</h3> + {% if siteType != constant('Piwik\\Plugins\\SitesManager\\SitesManager::SITE_TYPE_UNKNOWN') and instructionUrl %} + <p>{{ 'SitesManager_SiteWithoutDataDetectedSite'|translate(siteType|capitalize, '<a target="_blank" rel="noreferrer noopener" href="' ~ instructionUrl ~ '">','</a>')|raw }}</p> + + {% if gtmUsed %} + <p>{{ 'SitesManager_SiteWithoutDataDetectedGtm'|translate(siteType|capitalize, '<a target="_blank" rel="noreferrer noopener" href="https://matomo.org/faq/new-to-piwik/how-do-i-use-matomo-analytics-within-gtm-google-tag-manager">','</a>')|raw }}</p> + {% endif %} + + <p>{{ 'SitesManager_SiteWithoutDataOtherIntegrations'|translate }}: {{ 'CoreAdminHome_JSTrackingIntro3a'|translate('<a href="https://matomo.org/integrate/" rel="noreferrer noopener" target="_blank">','</a>')|raw }}</p> + {% else %} + <p>{{ 'SitesManager_InstallationGuidesIntro'|translate }} + + <p> + <a target="_blank" rel="noreferrer noopener" href='https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-wordpress/'>WordPress</a> + | <a target="_blank" rel="noreferrer noopener" href='https://matomo.org/faq/new-to-piwik/how-do-i-integrate-matomo-with-squarespace-website/'>Squarespace</a> + | <a target="_blank" rel="noreferrer noopener" href='https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-analytics-tracking-code-on-wix/'>Wix</a> + | <a target="_blank" rel="noreferrer noopener" href='https://matomo.org/faq/how-to-install/faq_19424/'>SharePoint</a> + | <a target="_blank" rel="noreferrer noopener" href='https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-analytics-tracking-code-on-joomla/'>Joomla</a> + | <a target="_blank" rel="noreferrer noopener" href='https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-my-shopify-store/'>Shopify</a> + | <a target="_blank" rel="noreferrer noopener" href='https://matomo.org/faq/new-to-piwik/how-do-i-use-matomo-analytics-within-gtm-google-tag-manager/'>Google Tag Manager</a> + </p> + + <p>{{ 'CoreAdminHome_JSTrackingIntro3a'|translate('<a href="https://matomo.org/integrate/" rel="noreferrer noopener" target="_blank">','</a>')|raw }}</p> + <p>{{ 'CoreAdminHome_JSTrackingIntro3b'|translate|raw }}</p> + <br> + <p>{{ 'SitesManager_ExtraInformationNeeded'|translate }}</p> + <p>Matomo URL: <code piwik-select-on-focus>{{ piwikUrl }}</code></p> + <p>{{ 'SitesManager_EmailInstructionsYourSiteId'|translate('<code piwik-select-on-focus>' ~ idSite ~ '</code>')|raw }}</p> + {% endif %} + </div> + + <div id="tracking-code" class="col s12"> + <h3>{{ 'CoreAdminHome_TrackingCode'|translate}}</h3> + + <p>{{ 'CoreAdminHome_JSTracking_CodeNoteBeforeClosingHead'|translate("</head>")|raw }}</p> + + <pre piwik-select-on-focus>{{ jsTag|raw }}</pre> + + <p>{{ 'CoreAdminHome_JSTrackingIntro5'|translate('<a rel="noreferrer noopener" target="_blank" href="https://developer.matomo.org/guides/tracking-javascript-guide">','</a>')|raw }}</p> + + <p>{{ 'CoreAdminHome_JSTracking_EndNote'|translate('<a href="' ~ linkTo({'module': 'CoreAdminHome', 'action': 'trackingCodeGenerator'}) ~'">','</a>')|raw }}</p> + </div> + + <div id="mtm" class="col s12"> + {% if tagManagerActive %} + {{ postEvent('Template.endTrackingCodePage') }} + {% else %} + <h3>{{ 'SitesManager_SiteWithoutDataMatomoTagManager'|translate }}</h3> + <p>{{ 'SitesManager_SiteWithoutDataMatomoTagManagerNotActive'|translate('<a href="https://matomo.org/docs/tag-manager/" rel="noreferrer noopener" target="_blank">', '</a>')|raw }}</p> + {% endif %} + </div> + + <div id="other" class="col s12"> + <h3>{{ 'SitesManager_LogAnalytics'|translate }}</h3> + <p>{{ 'SitesManager_LogAnalyticsDescription'|translate('<a href="https://matomo.org/log-analytics/" rel="noreferrer noopener" target="_blank">', '</a>')|raw }}</p> + + <h3>{{ 'SitesManager_MobileAppsAndSDKs'|translate }}</h3> + <p>{{ 'SitesManager_MobileAppsAndSDKsDescription'|translate('<a href="https://matomo.org/integrate/#programming-language-platforms-and-frameworks" rel="noreferrer noopener" target="_blank">','</a>')|raw }}</p> + + <h3>{{ 'CoreAdminHome_HttpTrackingApi'|translate }}</h3> + <p>{{ 'CoreAdminHome_HttpTrackingApiDescription'|translate('<a href="https://developer.matomo.org/api-reference/tracking-api" rel="noreferrer noopener" target="_blank">','</a>')|raw }}</p> + + <h3>{{ 'SitesManager_SiteWithoutDataGoogleTagManager'|translate }}</h3> + <p>{{ 'SitesManager_SiteWithoutDataGoogleTagManagerDescription'|translate('<a target="_blank" rel="noreferrer noopener" href="https://matomo.org/faq/new-to-piwik/how-do-i-use-matomo-analytics-within-gtm-google-tag-manager">','</a>')|raw }}</p> + + {% if googleAnalyticsImporterMessage is defined %} + {{ googleAnalyticsImporterMessage|raw }} + {% endif %} + </div> +</div> diff --git a/plugins/SitesManager/templates/siteWithoutData.twig b/plugins/SitesManager/templates/siteWithoutData.twig index 4f35259eec..f5da6d405f 100644 --- a/plugins/SitesManager/templates/siteWithoutData.twig +++ b/plugins/SitesManager/templates/siteWithoutData.twig @@ -27,92 +27,27 @@ <div class="site-without-data"> <div piwik-content-block content-title="{{ 'SitesManager_SiteWithoutDataTitle'|translate|e('html_attr') }}"> - <p> - {{ 'SitesManager_SiteWithoutDataDescription'|translate }} {{ 'Installation_JSTracking_Intro'|translate }} - {{ 'SitesManager_SiteWithoutDataSetupTracking'|translate('<a href="' ~ linkTo({ - 'module': 'CoreAdminHome', - 'action': 'trackingCodeGenerator', - }) ~ '">', "</a>")|raw }} - <br /> - <br /> - {{ 'SitesManager_SiteWithoutDataMessageDisappears'|translate }} - - </p> - - <div class='trackingHelp'> - {% if showMatomoLinks %} - <h3>{{ 'SitesManager_InstallationGuides'|translate }}</h3> - <p>{{ 'SitesManager_InstallationGuidesIntro'|translate }} - - <a target="_blank" rel="noreferrer noopener" href='https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-wordpress/'>WordPress</a> - | <a target="_blank" rel="noreferrer noopener" href='https://matomo.org/faq/new-to-piwik/how-do-i-integrate-matomo-with-squarespace-website/'>Squarespace</a> - | <a target="_blank" rel="noreferrer noopener" href='https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-analytics-tracking-code-on-wix/'>Wix</a> - | <a target="_blank" rel="noreferrer noopener" href='https://matomo.org/faq/how-to-install/faq_19424/'>SharePoint</a> - | <a target="_blank" rel="noreferrer noopener" href='https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-analytics-tracking-code-on-joomla/'>Joomla</a> - | <a target="_blank" rel="noreferrer noopener" href='https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-my-shopify-store/'>Shopify</a> - | <a target="_blank" rel="noreferrer noopener" href='https://matomo.org/faq/new-to-piwik/how-do-i-use-matomo-analytics-within-gtm-google-tag-manager/'>Google Tag Manager</a> - <br > - <br > - {{ 'SitesManager_ExtraInformationNeeded'|translate }} - <br > - Matomo URL: <code piwik-select-on-focus>{{ piwikUrl }}</code> - <br > - {{ 'SitesManager_EmailInstructionsYourSiteId'|translate('<code piwik-select-on-focus>' ~ idSite ~ '</code>')|raw }} - <br > - </p> - {% endif %} - - <h3>{{ 'SitesManager_Integrations'|translate }}</h3> - - <p>{{ 'CoreAdminHome_JSTrackingIntro3a'|translate('<a href="https://matomo.org/integrate/" rel="noreferrer noopener" target="_blank">','</a>')|raw }} {{ 'CoreAdminHome_JSTrackingIntro3b'|translate|raw }}</p> - - <div class="valign-wrapper trackingHelpHeader"> - <div> - - <h3>{{ 'General_JsTrackingTag'|translate }}</h3> + <p>{{ 'SitesManager_SiteWithoutDataDescription'|translate('<a href="mailto:?subject=' ~ 'SitesManager_EmailInstructionsSubject'|translate|url_encode|e('html_attr') ~ '&body=' ~ emailBody|url_encode|e('html_attr') ~ '">', '</a>')|raw }}</p> + <p>{{ 'SitesManager_SiteWithoutDataMessageDisappears'|translate }}</p> - <p>{{ 'CoreAdminHome_JSTracking_CodeNoteBeforeClosingHead'|translate("</head>")|raw }}</p> - </div> - <a class="btn" id="emailTrackingCodeBtn" - href="mailto:?subject={{ 'SitesManager_EmailInstructionsSubject'|translate|url_encode|e('html_attr') }}&body={{ emailBody|url_encode|e('html_attr') }}"> - {{ 'SitesManager_EmailInstructionsButton'|translate }} - </a> - </div> + <h3>{{ 'SitesManager_SiteWithoutDataChoosePreferredWay'|translate }}</h3> - <pre piwik-select-on-focus>{{ jsTag|raw }}</pre> + <div piwik-widget-loader='{"module":"SitesManager","action":"siteWithoutDataTabs"}' loading-message="{{ 'SitesManager_DetectingYourSite'|translate|e('html_attr') }}..."></div> - <p>{{ 'CoreAdminHome_JSTrackingIntro5'|translate('<a rel="noreferrer noopener" target="_blank" href="https://developer.matomo.org/guides/tracking-javascript-guide">','</a>')|raw }}</p> + <hr> - <p><br />{{ 'CoreAdminHome_JSTracking_EndNote'|translate('<a href="' ~ linkTo({'module': 'CoreAdminHome', 'action': 'trackingCodeGenerator'}) ~'">','</a>')|raw }} - <br /> - <br /> - <a href="{{ linkTo({module: 'CoreAdminHome', action: 'trackingCodeGenerator'}) }}"class="btn"><span class="icon-configure"></span> {{ 'SitesManager_CustomizeJavaScriptTracker'|translate }}</a></p> - - <h3>{{ 'SitesManager_LogAnalytics'|translate }}</h3> - - <p>{{ 'SitesManager_LogAnalyticsDescription'|translate('<a href="https://matomo.org/log-analytics/" rel="noreferrer noopener" target="_blank">', '</a>')|raw }}</p> - - <h3>{{ 'SitesManager_MobileAppsAndSDKs'|translate }}</h3> - - <p>{{ 'SitesManager_MobileAppsAndSDKsDescription'|translate('<a href="https://matomo.org/integrate/#programming-language-platforms-and-frameworks" rel="noreferrer noopener" target="_blank">','</a>')|raw }}</p> - - <h3>{{ 'CoreAdminHome_HttpTrackingApi'|translate }}</h3> - <p>{{ 'CoreAdminHome_HttpTrackingApiDescription'|translate('<a href="https://developer.matomo.org/api-reference/tracking-api" rel="noreferrer noopener" target="_blank">','</a>')|raw }}</p> - - {% if googleAnalyticsImporterMessage is defined %} - {{ googleAnalyticsImporterMessage|raw }} - {% endif %} - - {{ postEvent('Template.endTrackingHelpPage') }} - - </div> + <a class="btn" id="emailTrackingCodeBtn" + href="mailto:?subject={{ 'SitesManager_EmailInstructionsSubject'|translate|url_encode|e('html_attr') }}&body={{ emailBody|url_encode|e('html_attr') }}" + >{{ 'SitesManager_EmailInstructionsButton'|translate }}</a> {{ postEvent('Template.siteWithoutData.afterIntro') }} <br /> <br /> <a href="{{ linkTo({module: 'SitesManager', action: 'ignoreNoDataMessage'}) }}" - class="btn ignoreSitesWithoutData">{{ 'SitesManager_SiteWithoutDataIgnoreMessage'|translate }}</a> - + class="btn ignoreSitesWithoutData" + > + {{ 'SitesManager_SiteWithoutDataIgnoreMessage'|translate }} + </a> </div> {{ postEvent('Template.siteWithoutData.afterTrackingHelp') }} diff --git a/plugins/SitesManager/tests/Unit/GuessSiteTypeAndGtmTest.php b/plugins/SitesManager/tests/Unit/GuessSiteTypeAndGtmTest.php new file mode 100644 index 0000000000..66045cc909 --- /dev/null +++ b/plugins/SitesManager/tests/Unit/GuessSiteTypeAndGtmTest.php @@ -0,0 +1,102 @@ +<?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\SitesManager\tests\Unit; + +use Piwik\Plugins\SitesManager\GtmSiteTypeGuesser; +use Piwik\Plugins\SitesManager\SitesManager; + +/** + * @group SitesManager + * @group GtmSiteTypeGuesserTest + * @group Plugins + */ +class GtmSiteTypeGuesserTest extends \PHPUnit\Framework\TestCase +{ + /** + * @var GtmSiteTypeGuesser + */ + private $guesser; + + public function setUp(): void + { + parent::setUp(); + + $this->guesser = new GtmSiteTypeGuesser(); + } + + public function test_site_type_unknown_if_response_false() + { + $this->assertEquals(SitesManager::SITE_TYPE_UNKNOWN, $this->guesser->guessSiteTypeFromResponse(false)); + } + + public function test_gtm_is_false_if_response_false() + { + $this->assertFalse($this->guesser->guessGtmFromResponse(false)); + } + + public function test_gtm_is_true() + { + $response = [ + 'status' => 200, + 'headers' => [], + 'data' => 'it contains gtm.start somewhere' + ]; + + $this->assertTrue($this->guesser->guessGtmFromResponse($response)); + } + + /** + * @dataProvider responseProvider + */ + public function test_site_types_by_response($expected, $response) + { + $this->assertEquals($expected, $this->guesser->guessSiteTypeFromResponse($response)); + } + + public function responseProvider() + { + return [ + [SitesManager::SITE_TYPE_UNKNOWN, [ + 'status' => 200, + 'headers' => [], + 'data' => 'nothing special' + ]], + [SitesManager::SITE_TYPE_SHOPIFY, [ + 'status' => 200, + 'headers' => [], + 'data' => 'contains Shopify.theme text' + ]], + [SitesManager::SITE_TYPE_WORDPRESS, [ + 'status' => 200, + 'headers' => [], + 'data' => 'contains /wp-content text' + ]], + [SitesManager::SITE_TYPE_WIX, [ + 'status' => 200, + 'headers' => [], + 'data' => 'contains X-Wix-Published-Version text' + ]], + [SitesManager::SITE_TYPE_SQUARESPACE, [ + 'status' => 200, + 'headers' => [], + 'data' => 'contains <!-- This is Squarespace. --> text' + ]], + [SitesManager::SITE_TYPE_SHAREPOINT, [ + 'status' => 200, + 'headers' => [], + 'data' => 'contains content="Microsoft SharePoint text' + ]], + [SitesManager::SITE_TYPE_JOOMLA, [ + 'status' => 200, + 'headers' => ['expires' => 'Wed, 17 Aug 2005 00:00:00 GMT'], + 'data' => 'nothing special' + ]], + ]; + } +} |