X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FPiwikAnalytics%2FPiwikAnalyticsPlugin.php;h=2c8558671570a2c8d8893de2317dbf1c6ec47d75;hb=cb183359e23ae7a5cfb483fa06c6c4b7a8b05fff;hp=b353d725526920c22df02be716a374050159e7d4;hpb=95b534c5cee56602dffcc11121908c0f518cab6d;p=quix0rs-gnu-social.git diff --git a/plugins/PiwikAnalytics/PiwikAnalyticsPlugin.php b/plugins/PiwikAnalytics/PiwikAnalyticsPlugin.php index b353d72552..2c85586715 100644 --- a/plugins/PiwikAnalytics/PiwikAnalyticsPlugin.php +++ b/plugins/PiwikAnalytics/PiwikAnalyticsPlugin.php @@ -49,7 +49,6 @@ if (!defined('STATUSNET')) { * analytics setup - for example '8'. * */ - class PiwikAnalyticsPlugin extends Plugin { /** the base of your Piwik installation */ @@ -63,7 +62,6 @@ class PiwikAnalyticsPlugin extends Plugin * @param string $root Piwik root URL * @param string $id Piwik ID of this app */ - function __construct($root=null, $id=null) { $this->piwikroot = $root; @@ -78,23 +76,30 @@ class PiwikAnalyticsPlugin extends Plugin * * @return boolean ignored */ - function onEndShowScripts($action) { - $piwikCode1 = <<piwikroot}" : "http://{$this->piwikroot}"); -document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E")); -ENDOFPIWIK; - $piwikCode2 = << created in a document.write + // meant that the browser had no way to preload it, ensuring that its + // loading will be synchronous, blocking further page rendering. + // + // User-agents understand protocol-relative links, so instead of the + // URL produced in JS we can just give a universal one. Since it's + // sitting there in the DOM ready to go, the browser can preload the + // file for us and we're less likely to have to wait for it. + $piwikUrl = '//' . $this->piwikroot . 'piwik.js'; + $piwikCode = <<piwikroot}" : "http://{$this->piwikroot}"); var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", {$this->piwikId}); piwikTracker.trackPageView(); piwikTracker.enableLinkTracking(); } catch( err ) {} ENDOFPIWIK; - $action->inlineScript($piwikCode1); - $action->inlineScript($piwikCode2); + // Don't use $action->script() here; it'll try to preface the URL. + $action->element('script', array('type' => 'text/javascript', 'src' => $piwikUrl), ' '); + $action->inlineScript($piwikCode); return true; } @@ -105,8 +110,8 @@ ENDOFPIWIK; 'author' => 'Tobias Diekershoff, Evan Prodromou', 'homepage' => 'http://status.net/wiki/Plugin:Piwik', 'rawdescription' => - _m('Use Piwik Open Source Web analytics software.')); + // TRANS: Plugin description. + _m('Use Piwik Open Source web analytics software.')); return true; } - }