Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/CoreAdminHome/angularjs/trackingcode/imagetrackingcode.controller.js3
-rw-r--r--plugins/CoreAdminHome/angularjs/trackingcode/jstrackingcode.controller.js3
-rw-r--r--plugins/CoreUpdater/Updater.php1
-rw-r--r--plugins/CustomPiwikJs/Commands/UpdateTracker.php3
-rw-r--r--plugins/CustomPiwikJs/Diagnostic/PiwikJsCheck.php44
-rw-r--r--plugins/CustomPiwikJs/TrackerUpdater.php21
-rw-r--r--plugins/CustomPiwikJs/lang/en.json8
-rw-r--r--plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php2
-rw-r--r--plugins/CustomPiwikJs/tests/System/PiwikJsContentTest.php2
-rw-r--r--plugins/Installation/Controller.php4
-rw-r--r--plugins/Installation/lang/en.json2
-rw-r--r--plugins/Installation/templates/welcome.twig2
-rw-r--r--plugins/Installation/tests/UI/expected-screenshots/Installation_js_tracking.png4
-rw-r--r--plugins/Installation/tests/UI/expected-screenshots/Installation_system_check.png4
-rw-r--r--plugins/Morpheus/templates/javascriptCode.twig8
-rw-r--r--plugins/SitesManager/API.php18
-rw-r--r--plugins/SitesManager/Controller.php20
-rw-r--r--plugins/SitesManager/templates/_displayJavascriptCode.twig2
-rw-r--r--plugins/SitesManager/templates/displayJavascriptCode.twig5
-rw-r--r--plugins/SitesManager/tests/System/ApiTest.php35
-rw-r--r--plugins/SitesManager/tests/System/expected/test_SitesManager_after3_7_0__SitesManager.getImageTrackingCode.xml4
-rw-r--r--plugins/SitesManager/tests/System/expected/test_SitesManager_after3_7_0__SitesManager.getJavascriptTag.xml17
-rw-r--r--plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0__SitesManager.getImageTrackingCode.xml4
-rw-r--r--plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0__SitesManager.getJavascriptTag.xml17
-rw-r--r--plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0_but_forced__SitesManager.getImageTrackingCode.xml4
-rw-r--r--plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0_but_forced__SitesManager.getJavascriptTag.xml17
-rw-r--r--plugins/TestRunner/Commands/TestsSetupFixture.php2
27 files changed, 195 insertions, 61 deletions
diff --git a/plugins/CoreAdminHome/angularjs/trackingcode/imagetrackingcode.controller.js b/plugins/CoreAdminHome/angularjs/trackingcode/imagetrackingcode.controller.js
index c19885ac7a..252df4f69d 100644
--- a/plugins/CoreAdminHome/angularjs/trackingcode/imagetrackingcode.controller.js
+++ b/plugins/CoreAdminHome/angularjs/trackingcode/imagetrackingcode.controller.js
@@ -61,7 +61,8 @@
// get data used to generate the link
var postParams = {
piwikUrl: piwikHost + piwikPath,
- actionName: self.pageName
+ actionName: self.pageName,
+ forceMatomoEndpoint: 1
};
if (self.trackGoal && self.trackIdGoal) {
diff --git a/plugins/CoreAdminHome/angularjs/trackingcode/jstrackingcode.controller.js b/plugins/CoreAdminHome/angularjs/trackingcode/jstrackingcode.controller.js
index 5733e145ed..ba85c3729f 100644
--- a/plugins/CoreAdminHome/angularjs/trackingcode/jstrackingcode.controller.js
+++ b/plugins/CoreAdminHome/angularjs/trackingcode/jstrackingcode.controller.js
@@ -88,7 +88,8 @@
doNotTrack: self.doNotTrack ? 1 : 0,
disableCookies: self.disableCookies ? 1 : 0,
crossDomain: self.crossDomain ? 1 : 0,
- trackNoScript: self.trackNoScript ? 1: 0
+ trackNoScript: self.trackNoScript ? 1: 0,
+ forceMatomoEndpoint: 1
};
if (self.useCustomCampaignParams) {
diff --git a/plugins/CoreUpdater/Updater.php b/plugins/CoreUpdater/Updater.php
index 347ea3f5ca..569973fc2d 100644
--- a/plugins/CoreUpdater/Updater.php
+++ b/plugins/CoreUpdater/Updater.php
@@ -228,6 +228,7 @@ class Updater
'/index.php',
'/core/Piwik.php',
'/piwik.php',
+ '/matomo.php',
'/plugins/API/API.php'
);
foreach ($someExpectedFiles as $file) {
diff --git a/plugins/CustomPiwikJs/Commands/UpdateTracker.php b/plugins/CustomPiwikJs/Commands/UpdateTracker.php
index f336b691ee..c53b0ba0c2 100644
--- a/plugins/CustomPiwikJs/Commands/UpdateTracker.php
+++ b/plugins/CustomPiwikJs/Commands/UpdateTracker.php
@@ -21,8 +21,9 @@ class UpdateTracker extends ConsoleCommand
protected function configure()
{
$this->setName('custom-piwik-js:update');
+ $this->setAliases(array('custom-matomo-js:update'));
$this->addOption('source-file', null, InputOption::VALUE_REQUIRED, 'Absolute path to source PiwikJS file.', $this->getPathOriginalPiwikJs());
- $this->addOption('target-file', null, InputOption::VALUE_REQUIRED, 'Absolute path to target file. Useful if your /piwik.js is not writable and you want to replace the file manually', PIWIK_DOCUMENT_ROOT . TrackerUpdater::TARGET_PIWIK_JS);
+ $this->addOption('target-file', null, InputOption::VALUE_REQUIRED, 'Absolute path to target file. Useful if your /matomo.js is not writable and you want to replace the file manually', PIWIK_DOCUMENT_ROOT . TrackerUpdater::TARGET_MATOMO_JS);
$this->addOption('ignore-minified', null, InputOption::VALUE_NONE, 'Ignore minified tracker files, useful during development so the original source file can be debugged');
$this->setDescription('Update the Javascript Tracker with plugin tracker additions');
}
diff --git a/plugins/CustomPiwikJs/Diagnostic/PiwikJsCheck.php b/plugins/CustomPiwikJs/Diagnostic/PiwikJsCheck.php
index 3766dc650b..b952214cd7 100644
--- a/plugins/CustomPiwikJs/Diagnostic/PiwikJsCheck.php
+++ b/plugins/CustomPiwikJs/Diagnostic/PiwikJsCheck.php
@@ -12,7 +12,9 @@ use Piwik\Filesystem;
use Piwik\Plugins\CustomPiwikJs\File;
use Piwik\Plugins\Diagnostics\Diagnostic\Diagnostic;
use Piwik\Plugins\Diagnostics\Diagnostic\DiagnosticResult;
+use Piwik\SettingsPiwik;
use Piwik\SettingsServer;
+use Piwik\Tracker\TrackerCodeGenerator;
use Piwik\Translation\Translator;
/**
@@ -32,23 +34,49 @@ class PiwikJsCheck implements Diagnostic
public function execute()
{
- $label = $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsWritable');
+ // for users that installed matomo 3.7+ we only check for matomo.js being writable... for all other users we
+ // check both piwik.js and matomo.js as they can use both
+ $filesToCheck = array('matomo.js');
- $file = new File(PIWIK_DOCUMENT_ROOT . '/piwik.js');
+ $jsCodeGenerator = new TrackerCodeGenerator();
+ if (SettingsPiwik::isMatomoInstalled() && $jsCodeGenerator->shouldPreferPiwikEndpoint()) {
+ // if matomo is not installed yet, we definitely prefer matomo.js... check for isMatomoInstalled is needed
+ // cause otherwise it would perform a db query before matomo DB is configured
+ $filesToCheck[] = 'piwik.js';
+ }
+
+ $notWritableFiles = array();
+ foreach ($filesToCheck as $fileToCheck) {
+ $file = new File(PIWIK_DOCUMENT_ROOT . '/' . $fileToCheck);
+
+ if (!$file->hasWriteAccess()) {
+ $notWritableFiles[] = $fileToCheck;
+ }
+ }
- if ($file->hasWriteAccess()) {
+ $label = $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsWritable', $this->makeFilesTitles($filesToCheck));
+
+ if (empty($notWritableFiles)) {
return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_OK, ''));
}
- $comment = $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsNotWritable');
+ $comment = $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsNotWritable', $this->makeFilesTitles($notWritableFiles));
- if(!SettingsServer::isWindows()) {
- $realpath = Filesystem::realpath(PIWIK_INCLUDE_PATH . '/piwik.js');
- $command = "<br/><code> chmod +w $realpath<br/> chown ". Filechecks::getUserAndGroup() ." " . $realpath . "</code><br />";
- $comment .= $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsMakeWritable', $command);
+ if (!SettingsServer::isWindows()) {
+ $command = '';
+ foreach ($notWritableFiles as $notWritableFile) {
+ $realpath = Filesystem::realpath(PIWIK_INCLUDE_PATH . '/' . $notWritableFile);
+ $command .= "<br/><code> chmod +w $realpath<br/> chown ". Filechecks::getUserAndGroup() ." " . $realpath . "</code><br />";
+ }
+ $comment .= $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsMakeWritable', array($this->makeFilesTitles($notWritableFiles), $command));
}
return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_WARNING, $comment));
}
+ private function makeFilesTitles($files)
+ {
+ return '"/'. implode('" & "/', $files) .'"';
+ }
+
}
diff --git a/plugins/CustomPiwikJs/TrackerUpdater.php b/plugins/CustomPiwikJs/TrackerUpdater.php
index 37476a7423..ea15e7636a 100644
--- a/plugins/CustomPiwikJs/TrackerUpdater.php
+++ b/plugins/CustomPiwikJs/TrackerUpdater.php
@@ -8,6 +8,7 @@
namespace Piwik\Plugins\CustomPiwikJs;
+use Piwik\Common;
use Piwik\Container\StaticContainer;
use Piwik\Plugins\CustomPiwikJs\TrackingCode\PiwikJsManipulator;
use Piwik\Plugins\CustomPiwikJs\TrackingCode\PluginTrackerFiles;
@@ -23,7 +24,7 @@ class TrackerUpdater
{
const DEVELOPMENT_PIWIK_JS = '/js/piwik.js';
const ORIGINAL_PIWIK_JS = '/js/piwik.min.js';
- const TARGET_PIWIK_JS = '/piwik.js';
+ const TARGET_MATOMO_JS = '/matomo.js';
/**
* @var File
@@ -48,7 +49,7 @@ class TrackerUpdater
}
if (!isset($toFile)) {
- $toFile = PIWIK_DOCUMENT_ROOT . self::TARGET_PIWIK_JS;
+ $toFile = PIWIK_DOCUMENT_ROOT . self::TARGET_MATOMO_JS;
}
$this->setFromFile($fromFile);
@@ -139,5 +140,21 @@ class TrackerUpdater
*/
Piwik::postEvent('CustomPiwikJs.piwikJsChanged', [$this->toFile->getPath()]);
}
+
+ // we need to make sure to sync matomo.js / piwik.js
+ $this->updateAlternative('piwik.js', 'matomo.js', $newContent);
+ $this->updateAlternative('matomo.js', 'piwik.js', $newContent);
+ }
+
+ private function updateAlternative($fromFile, $toFile, $newContent)
+ {
+ if (Common::stringEndsWith($this->toFile->getName(), $fromFile)) {
+ $alternativeFilename = dirname($this->toFile->getName()) . DIRECTORY_SEPARATOR . $toFile;
+ $file = new File($alternativeFilename);
+ if ($file->hasWriteAccess() && $file->getContent() !== $newContent) {
+ $file->save($newContent);
+ Piwik::postEvent('CustomPiwikJs.piwikJsChanged', [$file->getPath()]);
+ }
+ }
}
}
diff --git a/plugins/CustomPiwikJs/lang/en.json b/plugins/CustomPiwikJs/lang/en.json
index 24fb9728b4..53e6c9c68c 100644
--- a/plugins/CustomPiwikJs/lang/en.json
+++ b/plugins/CustomPiwikJs/lang/en.json
@@ -1,8 +1,8 @@
{
"CustomPiwikJs": {
- "PluginDescription": "Allows any plugin to extend the Matomo JavaScript Tracking file (piwik.js) and add new functionnality and website measurement capabilities.",
- "DiagnosticPiwikJsWritable": "Writable JavaScript Tracker (\"/piwik.js\")",
- "DiagnosticPiwikJsNotWritable": "The Matomo JavaScript tracker file \"/piwik.js\" is not writable which means other plugins cannot extend the JavaScript tracker. In the future even some core features might not work as expected. ",
- "DiagnosticPiwikJsMakeWritable": "We recommend to piwik.js writable by running this command: %s"
+ "PluginDescription": "Allows any plugin to extend the Matomo JavaScript Tracking file (matomo.js) and add new functionnality and website measurement capabilities.",
+ "DiagnosticPiwikJsWritable": "Writable JavaScript Tracker (%s)",
+ "DiagnosticPiwikJsNotWritable": "The Matomo JavaScript tracker file %s is not writable which means other plugins cannot extend the JavaScript tracker. In the future even some core features might not work as expected. ",
+ "DiagnosticPiwikJsMakeWritable": "We recommend to make %1$s writable by running this command: %2$s"
}
} \ No newline at end of file
diff --git a/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php b/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php
index 653c5105c5..7a66b035fb 100644
--- a/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php
+++ b/plugins/CustomPiwikJs/tests/Integration/TrackerUpdaterTest.php
@@ -67,7 +67,7 @@ class TrackerUpdaterTest extends IntegrationTestCase
$this->assertTrue($toFile instanceof File);
$this->assertSame(basename(TrackerUpdater::ORIGINAL_PIWIK_JS), $fromFile->getName());
- $this->assertSame(basename(TrackerUpdater::TARGET_PIWIK_JS), $toFile->getName());
+ $this->assertSame(basename(TrackerUpdater::TARGET_MATOMO_JS), $toFile->getName());
}
public function test_setFormFile_getFromFile()
diff --git a/plugins/CustomPiwikJs/tests/System/PiwikJsContentTest.php b/plugins/CustomPiwikJs/tests/System/PiwikJsContentTest.php
index dd3f08ab3a..a8ca3eb844 100644
--- a/plugins/CustomPiwikJs/tests/System/PiwikJsContentTest.php
+++ b/plugins/CustomPiwikJs/tests/System/PiwikJsContentTest.php
@@ -23,7 +23,7 @@ class PiwikJsContentTest extends SystemTestCase
public function test_piwikJsAndPiwikMinJsMustHaveSameContent()
{
$piwikMin = PIWIK_DOCUMENT_ROOT . TrackerUpdater::ORIGINAL_PIWIK_JS;
- $piwikJs = PIWIK_DOCUMENT_ROOT . TrackerUpdater::TARGET_PIWIK_JS;
+ $piwikJs = PIWIK_DOCUMENT_ROOT . TrackerUpdater::TARGET_MATOMO_JS;
$this->assertSame(file_get_contents($piwikMin), file_get_contents($piwikJs));
}
diff --git a/plugins/Installation/Controller.php b/plugins/Installation/Controller.php
index a99ee07929..1f85083ef1 100644
--- a/plugins/Installation/Controller.php
+++ b/plugins/Installation/Controller.php
@@ -16,7 +16,6 @@ use Piwik\Config;
use Piwik\Container\StaticContainer;
use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\Db;
-use Piwik\Db\Adapter;
use Piwik\DbHelper;
use Piwik\Filesystem;
use Piwik\Http;
@@ -26,11 +25,9 @@ use Piwik\Plugin\Manager;
use Piwik\Plugins\Diagnostics\DiagnosticService;
use Piwik\Plugins\LanguagesManager\LanguagesManager;
use Piwik\Plugins\SitesManager\API as APISitesManager;
-use Piwik\Plugins\UserCountry\LocationProvider;
use Piwik\Plugins\UsersManager\API as APIUsersManager;
use Piwik\ProxyHeaders;
use Piwik\SettingsPiwik;
-use Piwik\Theme;
use Piwik\Tracker\TrackerCodeGenerator;
use Piwik\Translation\Translator;
use Piwik\Updater;
@@ -207,6 +204,7 @@ class Controller extends \Piwik\Plugin\ControllerAdmin
DbHelper::createTables();
DbHelper::createAnonymousUser();
+ DbHelper::recordInstallVersion();
$this->updateComponents();
diff --git a/plugins/Installation/lang/en.json b/plugins/Installation/lang/en.json
index e07969a7bc..ff98d6a776 100644
--- a/plugins/Installation/lang/en.json
+++ b/plugins/Installation/lang/en.json
@@ -118,7 +118,7 @@
"SystemCheckSummaryThereWereWarnings": "There are some issues with your system. Matomo will run, but you might experience some minor problems.",
"SystemCheckTimeLimitHelp": "On a high traffic website, executing the archiving process may require more time than currently allowed. If necessary, change the max_execution_time directive in your php.ini file.",
"SystemCheckTracker": "Tracker status",
- "SystemCheckTrackerHelp": "GET request to piwik.php failed. Try whitelisting this URL from HTTP Authentication and disable mod_security (you may have to ask your webhost). For more information about the error, check your web server error log file.",
+ "SystemCheckTrackerHelp": "GET request to matomo.php failed. Try whitelisting this URL from HTTP Authentication and disable mod_security (you may have to ask your webhost). For more information about the error, check your web server error log file.",
"SystemCheckWarnDomHelp": "You should enable the \"dom\" extension (e.g., install the \"php-dom\" and\/or \"php-xml\" package).",
"SystemCheckWarning": "Matomo will work normally but some features may be missing",
"SystemCheckWarnJsonHelp": "You should enable \"json\" extension (e.g., install the \"php-json\" package) for better performance.",
diff --git a/plugins/Installation/templates/welcome.twig b/plugins/Installation/templates/welcome.twig
index 3931478426..d32805f469 100644
--- a/plugins/Installation/templates/welcome.twig
+++ b/plugins/Installation/templates/welcome.twig
@@ -12,7 +12,7 @@
// client-side test for broken tracker (e.g., mod_security rule)
$('.next-step').hide();
$.ajax({
- url: 'piwik.php',
+ url: 'matomo.php',
data: 'url=http://example.com',
complete: function () {
$('.next-step').show();
diff --git a/plugins/Installation/tests/UI/expected-screenshots/Installation_js_tracking.png b/plugins/Installation/tests/UI/expected-screenshots/Installation_js_tracking.png
index 56eac1cb87..64c6dfada7 100644
--- a/plugins/Installation/tests/UI/expected-screenshots/Installation_js_tracking.png
+++ b/plugins/Installation/tests/UI/expected-screenshots/Installation_js_tracking.png
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:d3364ab2ed6eb9dd48eb48025bad28ae19c81facee829e2207474d5fe1efb39f
-size 224953
+oid sha256:a403a5493fdb7a8dbf22cd99caafbf6b0c0b2ce837f59544f9bd839a7a114fd9
+size 224949
diff --git a/plugins/Installation/tests/UI/expected-screenshots/Installation_system_check.png b/plugins/Installation/tests/UI/expected-screenshots/Installation_system_check.png
index 2afe761ea9..5fe151af69 100644
--- a/plugins/Installation/tests/UI/expected-screenshots/Installation_system_check.png
+++ b/plugins/Installation/tests/UI/expected-screenshots/Installation_system_check.png
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
-oid sha256:ca311ba80d2d5525a6ea9addf44161c2d960b3ec888a10f50e9fece4f9d7ba5d
-size 192039
+oid sha256:1045b739708a3086bf86d862afc6ed61ea00bf9e0113854a10941f30f6213fa6
+size 192412
diff --git a/plugins/Morpheus/templates/javascriptCode.twig b/plugins/Morpheus/templates/javascriptCode.twig
index 53a379d8ee..dfa863d0d2 100644
--- a/plugins/Morpheus/templates/javascriptCode.twig
+++ b/plugins/Morpheus/templates/javascriptCode.twig
@@ -6,15 +6,15 @@
_paq.push(['enableLinkTracking']);
(function() {
{$setTrackerUrl}
- {$optionsBeforeTrackerUrl}_paq.push(['setTrackerUrl', u+'piwik.php']);
+ {$optionsBeforeTrackerUrl}_paq.push(['setTrackerUrl', u+'{$matomoPhpFilename}']);
_paq.push(['setSiteId', '{$idSite}']);
{% if loadAsync %}var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
- g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);{% endif %}
+ g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'{$matomoJsFilename}'; s.parentNode.insertBefore(g,s);{% endif %}
})();
</script>
-{% if not loadAsync %}<script type='text/javascript' src="{$protocol}{$piwikUrl}/piwik.js"></script>
+{% if not loadAsync %}<script type='text/javascript' src="{$protocol}{$piwikUrl}/{$matomoJsFilename}"></script>
{% endif %}
-{% if trackNoScript %}<noscript><p><img src="{$protocol}{$piwikUrl}/piwik.php?idsite={$idSite}&amp;rec=1" style="border:0;" alt="" /></p></noscript>
+{% if trackNoScript %}<noscript><p><img src="{$protocol}{$piwikUrl}/{$matomoPhpFilename}?idsite={$idSite}&amp;rec=1" style="border:0;" alt="" /></p></noscript>
{% endif %}
<!-- End Matomo Code -->
diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php
index a6256d7ab5..94ad508d27 100644
--- a/plugins/SitesManager/API.php
+++ b/plugins/SitesManager/API.php
@@ -101,13 +101,14 @@ class API extends \Piwik\Plugin\API
* @param bool $doNotTrack
* @param bool $disableCookies
* @param bool $trackNoScript
+ * @param bool $forceMatomoEndpoint Whether the Matomo endpoint should be forced if Matomo was installed prior 3.7.0.
* @return string The Javascript tag ready to be included on the HTML pages
*/
public function getJavascriptTag($idSite, $piwikUrl = '', $mergeSubdomains = false, $groupPageTitlesByDomain = false,
$mergeAliasUrls = false, $visitorCustomVariables = false, $pageCustomVariables = false,
$customCampaignNameQueryParam = false, $customCampaignKeywordParam = false,
$doNotTrack = false, $disableCookies = false, $trackNoScript = false,
- $crossDomain = false)
+ $crossDomain = false, $forceMatomoEndpoint = false)
{
Piwik::checkUserHasViewAccess($idSite);
@@ -124,6 +125,10 @@ class API extends \Piwik\Plugin\API
$customCampaignKeywordParam = Common::unsanitizeInputValue($customCampaignKeywordParam);
$generator = new TrackerCodeGenerator();
+ if ($forceMatomoEndpoint) {
+ $generator->forceMatomoEndpoint();
+ }
+
$code = $generator->generate($idSite, $piwikUrl, $mergeSubdomains, $groupPageTitlesByDomain,
$mergeAliasUrls, $visitorCustomVariables, $pageCustomVariables,
$customCampaignNameQueryParam, $customCampaignKeywordParam,
@@ -139,9 +144,10 @@ class API extends \Piwik\Plugin\API
* @param string $piwikUrl The domain and URL path to the Matomo installation.
* @param int $idGoal An ID for a goal to trigger a conversion for.
* @param int $revenue The revenue of the goal conversion. Only used if $idGoal is supplied.
+ * @param bool $forceMatomoEndpoint Whether the Matomo endpoint should be forced if Matomo was installed prior 3.7.0.
* @return string The HTML tracking code.
*/
- public function getImageTrackingCode($idSite, $piwikUrl = '', $actionName = false, $idGoal = false, $revenue = false)
+ public function getImageTrackingCode($idSite, $piwikUrl = '', $actionName = false, $idGoal = false, $revenue = false, $forceMatomoEndpoint = false)
{
$urlParams = array('idsite' => $idSite, 'rec' => 1);
@@ -168,7 +174,13 @@ class API extends \Piwik\Plugin\API
*/
Piwik::postEvent('SitesManager.getImageTrackingCode', array(&$piwikUrl, &$urlParams));
- $url = (ProxyHttp::isHttps() ? "https://" : "http://") . $piwikUrl . '/piwik.php?' . Url::getQueryStringFromParameters($urlParams);
+ $trackerCodeGenerator = new TrackerCodeGenerator();
+ if ($forceMatomoEndpoint) {
+ $trackerCodeGenerator->forceMatomoEndpoint();
+ }
+ $matomoPhp = $trackerCodeGenerator->getPhpTrackerEndpoint();
+
+ $url = (ProxyHttp::isHttps() ? "https://" : "http://") . rtrim($piwikUrl, '/') . '/'.$matomoPhp.'?' . Url::getQueryStringFromParameters($urlParams);
$html = "<!-- Matomo Image Tracker-->
<img src=\"" . htmlspecialchars($url, ENT_COMPAT, 'UTF-8') . "\" style=\"border:0\" alt=\"\" />
<!-- End Matomo -->";
diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php
index 67c08f6ac1..71a7c84e97 100644
--- a/plugins/SitesManager/Controller.php
+++ b/plugins/SitesManager/Controller.php
@@ -101,25 +101,6 @@ class Controller extends \Piwik\Plugin\ControllerAdmin
}
/**
- * Displays the admin UI page showing all tracking tags
- * @return string
- */
- function displayJavascriptCode()
- {
- $this->checkSitePermission();
- Piwik::checkUserHasViewAccess($this->idSite);
- $javascriptGenerator = new TrackerCodeGenerator();
- $jsTag = $javascriptGenerator->generate($this->idSite, SettingsPiwik::getPiwikUrl());
- $site = new Site($this->idSite);
-
- return $this->renderTemplate('displayJavascriptCode', array(
- 'idSite' => $this->idSite,
- 'displaySiteName' => $site->getName(),
- 'jsTag' => $jsTag
- ));
- }
-
- /**
* User will download a file called PiwikTracker.php that is the content of the actual script
*/
function downloadPiwikTracker()
@@ -146,6 +127,7 @@ class Controller extends \Piwik\Plugin\ControllerAdmin
public function siteWithoutData()
{
$javascriptGenerator = new TrackerCodeGenerator();
+ $javascriptGenerator->forceMatomoEndpoint();
$piwikUrl = Url::getCurrentUrlWithoutFileName();
if (!$this->site && Piwik::hasUserSuperUserAccess()) {
diff --git a/plugins/SitesManager/templates/_displayJavascriptCode.twig b/plugins/SitesManager/templates/_displayJavascriptCode.twig
index e675220052..aabdc93fce 100644
--- a/plugins/SitesManager/templates/_displayJavascriptCode.twig
+++ b/plugins/SitesManager/templates/_displayJavascriptCode.twig
@@ -30,4 +30,4 @@
{{ postEvent('Template.endTrackingHelpPage') }}
-</div>
+</div> \ No newline at end of file
diff --git a/plugins/SitesManager/templates/displayJavascriptCode.twig b/plugins/SitesManager/templates/displayJavascriptCode.twig
deleted file mode 100644
index 05d867030e..0000000000
--- a/plugins/SitesManager/templates/displayJavascriptCode.twig
+++ /dev/null
@@ -1,5 +0,0 @@
-{% extends 'admin.twig' %}
-
-{% block content %}
-{% include "@SitesManager/_displayJavascriptCode.twig" %}
-{% endblock %} \ No newline at end of file
diff --git a/plugins/SitesManager/tests/System/ApiTest.php b/plugins/SitesManager/tests/System/ApiTest.php
index 393a8fc6a4..34f57a849c 100644
--- a/plugins/SitesManager/tests/System/ApiTest.php
+++ b/plugins/SitesManager/tests/System/ApiTest.php
@@ -8,6 +8,8 @@
namespace Piwik\Plugins\SitesManager\tests\System;
+use Piwik\Db\Schema\Mysql;
+use Piwik\Option;
use Piwik\Plugins\SitesManager\tests\Fixtures\ManySites;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
@@ -68,6 +70,39 @@ class ApiTest extends SystemTestCase
return $apiToTest;
}
+ public function test_InstalledBeforeMatomo37()
+ {
+ $this->setInstallVersion('3.6.0');
+ $this->runApiTests(array('SitesManager.getJavascriptTag', 'SitesManager.getImageTrackingCode'), array(
+ 'idSite' => 1,
+ 'testSuffix' => '_prior3_7_0'
+ ));
+ }
+
+ public function test_InstalledBeforeMatomo37ButForced()
+ {
+ $this->setInstallVersion('3.6.0');
+ $this->runApiTests(array('SitesManager.getJavascriptTag', 'SitesManager.getImageTrackingCode'), array(
+ 'idSite' => 1,
+ 'otherRequestParameters' => array('forceMatomoEndpoint' => 1),
+ 'testSuffix' => '_prior3_7_0_but_forced'
+ ));
+ }
+
+ public function test_InstalledAfterMatomo37()
+ {
+ $this->setInstallVersion('3.7.0');
+ $this->runApiTests(array('SitesManager.getJavascriptTag', 'SitesManager.getImageTrackingCode'), array(
+ 'idSite' => 1,
+ 'testSuffix' => '_after3_7_0'
+ ));
+ }
+
+ private function setInstallVersion($installVersion)
+ {
+ Option::set(Mysql::OPTION_NAME_MATOMO_INSTALL_VERSION, $installVersion);
+ }
+
public static function getOutputPrefix()
{
return 'SitesManager';
diff --git a/plugins/SitesManager/tests/System/expected/test_SitesManager_after3_7_0__SitesManager.getImageTrackingCode.xml b/plugins/SitesManager/tests/System/expected/test_SitesManager_after3_7_0__SitesManager.getImageTrackingCode.xml
new file mode 100644
index 0000000000..b2f6990bc7
--- /dev/null
+++ b/plugins/SitesManager/tests/System/expected/test_SitesManager_after3_7_0__SitesManager.getImageTrackingCode.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>&lt;!-- Matomo Image Tracker--&gt;
+&lt;img src=&quot;http://http://example.org/piwik/matomo.php?idsite=1&amp;amp;rec=1&quot; style=&quot;border:0&quot; alt=&quot;&quot; /&gt;
+&lt;!-- End Matomo --&gt;</result> \ No newline at end of file
diff --git a/plugins/SitesManager/tests/System/expected/test_SitesManager_after3_7_0__SitesManager.getJavascriptTag.xml b/plugins/SitesManager/tests/System/expected/test_SitesManager_after3_7_0__SitesManager.getJavascriptTag.xml
new file mode 100644
index 0000000000..a09f82642d
--- /dev/null
+++ b/plugins/SitesManager/tests/System/expected/test_SitesManager_after3_7_0__SitesManager.getJavascriptTag.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>&lt;!-- Matomo --&gt;
+&lt;script type=&quot;text/javascript&quot;&gt;
+ var _paq = _paq || [];
+ /* tracker methods like &quot;setCustomDimension&quot; should be called before &quot;trackPageView&quot; */
+ _paq.push(['trackPageView']);
+ _paq.push(['enableLinkTracking']);
+ (function() {
+ var u=&quot;//example.org/piwik/&quot;;
+ _paq.push(['setTrackerUrl', u+'matomo.php']);
+ _paq.push(['setSiteId', '1']);
+ var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
+ g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
+ })();
+&lt;/script&gt;
+&lt;!-- End Matomo Code --&gt;
+</result> \ No newline at end of file
diff --git a/plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0__SitesManager.getImageTrackingCode.xml b/plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0__SitesManager.getImageTrackingCode.xml
new file mode 100644
index 0000000000..5854de6082
--- /dev/null
+++ b/plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0__SitesManager.getImageTrackingCode.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>&lt;!-- Matomo Image Tracker--&gt;
+&lt;img src=&quot;http://http://example.org/piwik/piwik.php?idsite=1&amp;amp;rec=1&quot; style=&quot;border:0&quot; alt=&quot;&quot; /&gt;
+&lt;!-- End Matomo --&gt;</result> \ No newline at end of file
diff --git a/plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0__SitesManager.getJavascriptTag.xml b/plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0__SitesManager.getJavascriptTag.xml
new file mode 100644
index 0000000000..5a5a0088d6
--- /dev/null
+++ b/plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0__SitesManager.getJavascriptTag.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>&lt;!-- Matomo --&gt;
+&lt;script type=&quot;text/javascript&quot;&gt;
+ var _paq = _paq || [];
+ /* tracker methods like &quot;setCustomDimension&quot; should be called before &quot;trackPageView&quot; */
+ _paq.push(['trackPageView']);
+ _paq.push(['enableLinkTracking']);
+ (function() {
+ var u=&quot;//example.org/piwik/&quot;;
+ _paq.push(['setTrackerUrl', u+'piwik.php']);
+ _paq.push(['setSiteId', '1']);
+ var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
+ g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
+ })();
+&lt;/script&gt;
+&lt;!-- End Matomo Code --&gt;
+</result> \ No newline at end of file
diff --git a/plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0_but_forced__SitesManager.getImageTrackingCode.xml b/plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0_but_forced__SitesManager.getImageTrackingCode.xml
new file mode 100644
index 0000000000..b2f6990bc7
--- /dev/null
+++ b/plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0_but_forced__SitesManager.getImageTrackingCode.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>&lt;!-- Matomo Image Tracker--&gt;
+&lt;img src=&quot;http://http://example.org/piwik/matomo.php?idsite=1&amp;amp;rec=1&quot; style=&quot;border:0&quot; alt=&quot;&quot; /&gt;
+&lt;!-- End Matomo --&gt;</result> \ No newline at end of file
diff --git a/plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0_but_forced__SitesManager.getJavascriptTag.xml b/plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0_but_forced__SitesManager.getJavascriptTag.xml
new file mode 100644
index 0000000000..a09f82642d
--- /dev/null
+++ b/plugins/SitesManager/tests/System/expected/test_SitesManager_prior3_7_0_but_forced__SitesManager.getJavascriptTag.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<result>&lt;!-- Matomo --&gt;
+&lt;script type=&quot;text/javascript&quot;&gt;
+ var _paq = _paq || [];
+ /* tracker methods like &quot;setCustomDimension&quot; should be called before &quot;trackPageView&quot; */
+ _paq.push(['trackPageView']);
+ _paq.push(['enableLinkTracking']);
+ (function() {
+ var u=&quot;//example.org/piwik/&quot;;
+ _paq.push(['setTrackerUrl', u+'matomo.php']);
+ _paq.push(['setSiteId', '1']);
+ var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
+ g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
+ })();
+&lt;/script&gt;
+&lt;!-- End Matomo Code --&gt;
+</result> \ No newline at end of file
diff --git a/plugins/TestRunner/Commands/TestsSetupFixture.php b/plugins/TestRunner/Commands/TestsSetupFixture.php
index 35b19eb983..e97319b633 100644
--- a/plugins/TestRunner/Commands/TestsSetupFixture.php
+++ b/plugins/TestRunner/Commands/TestsSetupFixture.php
@@ -159,7 +159,7 @@ class TestsSetupFixture extends ConsoleCommand
private function createSymbolicLinksForUITests()
{
// make sure symbolic links exist (phantomjs doesn't support symlink-ing yet)
- foreach (array('libs', 'plugins', 'tests', 'misc', 'piwik.js') as $linkName) {
+ foreach (array('libs', 'plugins', 'tests', 'misc', 'piwik.js', 'matomo.js') as $linkName) {
$linkPath = PIWIK_INCLUDE_PATH . '/tests/PHPUnit/proxy/' . $linkName;
if (!file_exists($linkPath)) {
$target = PIWIK_INCLUDE_PATH . '/' . $linkName;