From c4fc69ad2a46d8676573dfa3609a63c45748d8cb Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 20 Jun 2011 16:38:00 -0400 Subject: [PATCH] use async, domain-aware GoogleAnalytics JS --- .../GoogleAnalytics/GoogleAnalyticsPlugin.php | 50 ++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/plugins/GoogleAnalytics/GoogleAnalyticsPlugin.php b/plugins/GoogleAnalytics/GoogleAnalyticsPlugin.php index bb937ec5b9..dff43eff95 100644 --- a/plugins/GoogleAnalytics/GoogleAnalyticsPlugin.php +++ b/plugins/GoogleAnalytics/GoogleAnalyticsPlugin.php @@ -49,31 +49,57 @@ if (!defined('STATUSNET')) { */ class GoogleAnalyticsPlugin extends Plugin { - var $code = null; + const VERSION = '0.2'; function __construct($code=null) { - $this->code = $code; + if (!empty($code)) { + global $config; + $config['googleanalytics']['code'] = $code; + } + parent::__construct(); } function onEndShowScripts($action) { - $js1 = 'var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");'. - 'document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));'; - $js2 = sprintf('try{'. - 'var pageTracker = _gat._getTracker("%s");'. - 'pageTracker._trackPageview();'. - '} catch(err) {}', - $this->code); - $action->inlineScript($js1); - $action->inlineScript($js2); + $code = common_config('googleanalytics', 'code'); + $domain = common_config('googleanalytics', 'domain'); + + $js = <<inlineScript($js); } function onPluginVersion(&$versions) { $versions[] = array('name' => 'GoogleAnalytics', - 'version' => STATUSNET_VERSION, + 'version' => self::VERSION, 'author' => 'Evan Prodromou', 'homepage' => 'http://status.net/wiki/Plugin:GoogleAnalytics', 'rawdescription' => -- 2.39.5