summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-12-08 18:13:20 -0800
committerBrion Vibber <brion@pobox.com>2010-12-08 18:13:20 -0800
commite25d4683c8999a215f3f8e91e280ff52b8dd2499 (patch)
tree014a71ffe5b69b334c2d5d25c935f218a87fb944 /plugins
parentd8d9edfc990a20f67421e40a7d3055a58697a002 (diff)
parent516161213fd8ebc42332042541e6812466521fe6 (diff)
Merge branch 'master' into 0.9.x
Diffstat (limited to 'plugins')
-rw-r--r--plugins/PiwikAnalytics/PiwikAnalyticsPlugin.php22
1 files changed, 15 insertions, 7 deletions
diff --git a/plugins/PiwikAnalytics/PiwikAnalyticsPlugin.php b/plugins/PiwikAnalytics/PiwikAnalyticsPlugin.php
index 777fd9c5d..8a730113e 100644
--- a/plugins/PiwikAnalytics/PiwikAnalyticsPlugin.php
+++ b/plugins/PiwikAnalytics/PiwikAnalyticsPlugin.php
@@ -78,20 +78,28 @@ class PiwikAnalyticsPlugin extends Plugin
*/
function onEndShowScripts($action)
{
- $piwikCode1 = <<<ENDOFPIWIK
-var pkBaseURL = (("https:" == document.location.protocol) ? "https://{$this->piwikroot}" : "http://{$this->piwikroot}");
-document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
-ENDOFPIWIK;
- $piwikCode2 = <<<ENDOFPIWIK
+ // Slight modification to the default code.
+ // Loading the piwik.js file from a <script> 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 = <<<ENDOFPIWIK
try {
+var pkBaseURL = (("https:" == document.location.protocol) ? "https://{$this->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;
}