logger = $logger; $this->label = "🧪 " . "matomo.js"; # no need to make it translatable } /** * @return DiagnosticResult[] */ public function execute() { $matomoUrl = SettingsPiwik::getPiwikUrl(); $generator = new TrackerCodeGenerator(); $matomoJs = $generator->getJsTrackerEndpoint(); $checkURL = "$matomoUrl$matomoJs"; # something like https://example.com/matomo.js $timeout = self::SOCKET_TIMEOUT; try { $response = Http::sendHttpRequest($checkURL, $timeout, $userAgent = null, $destinationPath = null, $followDepth = 0, $acceptLanguage = false, $byteRange = false, $getExtendedInfo = true); $status = $response["status"]; $headers = $response["headers"]; $data = $response["data"]; if ($status != 200 || strpos($data, "c80d50af7d3db9be66a4d0a86db0286e4fd33292") === false) { $result = new DiagnosticResult($this->label); $result->addItem(new DiagnosticResultItem( DiagnosticResult::STATUS_INFORMATIONAL, Piwik::translate("DiagnosticsExtended_MatomoJSCheckFailed") )); $result->setLongErrorMessage(Piwik::translate("DiagnosticsExtended_MatomoJSCheckFailedCurlTip", [ "curl -v $checkURL" ])); return [$result]; } $results = new DiagnosticResult($this->label); $contentType = $headers["content-type"]; if ($contentType !== "application/javascript") { $results->addItem(new DiagnosticResultItem( DiagnosticResult::STATUS_WARNING, Piwik::translate("DiagnosticsExtended_MatomoJSCheckMIMEError", [$contentType]) )); } $contentEncoding = $headers["content-encoding"]; if ($contentEncoding === "gzip") { $results->addItem(new DiagnosticResultItem( DiagnosticResult::STATUS_OK, Piwik::translate("DiagnosticsExtended_MatomoJSCheckGzipped") )); } else { $results->addItem(new DiagnosticResultItem( DiagnosticResult::STATUS_WARNING, Piwik::translate("DiagnosticsExtended_MatomoJSCheckNotGzipped") )); } return [$results]; } catch (\Exception $e) { return [DiagnosticResult::singleResult( $this->label, DiagnosticResult::STATUS_INFORMATIONAL, Piwik::translate("DiagnosticsExtended_MatomoJSCheckUnknown") )]; } } }