X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FPiwikAnalytics%2FPiwikAnalyticsPlugin.php;h=adc87e66eeb62a5c6768f4b95434446c7bebcb51;hb=ec504ec4dfd62a2aade22ae3e2c0ba18173afafc;hp=777fd9c5d315c289826bc526af6dfcaf5fa5a9dd;hpb=78ed0348b0eaaebf7a51d55adc7e746cc5b43bbf;p=quix0rs-gnu-social.git diff --git a/plugins/PiwikAnalytics/PiwikAnalyticsPlugin.php b/plugins/PiwikAnalytics/PiwikAnalyticsPlugin.php index 777fd9c5d3..adc87e66ee 100644 --- a/plugins/PiwikAnalytics/PiwikAnalyticsPlugin.php +++ b/plugins/PiwikAnalytics/PiwikAnalyticsPlugin.php @@ -33,7 +33,7 @@ if (!defined('STATUSNET')) { } /** - * Plugin to use Piwik Analytics (based on the Google Analytics plugin by Evan) + * Plugin to use Piwik Analytics (based on the Analytics plugin by Evan) * * This plugin will spoot out the correct JavaScript spell to invoke * Piwik Analytics on a page. @@ -78,30 +78,39 @@ class PiwikAnalyticsPlugin extends Plugin */ 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; } - function onPluginVersion(&$versions) + function onPluginVersion(array &$versions) { $versions[] = array('name' => 'PiwikAnalytics', - 'version' => STATUSNET_VERSION, + 'version' => GNUSOCIAL_VERSION, 'author' => 'Tobias Diekershoff, Evan Prodromou', - 'homepage' => 'http://status.net/wiki/Plugin:Piwik', + 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/Piwik', 'rawdescription' => + // TRANS: Plugin description. _m('Use Piwik Open Source web analytics software.')); return true; }