From: Evan Prodromou Date: Mon, 20 Jun 2011 20:38:00 +0000 (-0400) Subject: use async, domain-aware GoogleAnalytics JS X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c4fc69ad2a46d8676573dfa3609a63c45748d8cb;p=quix0rs-gnu-social.git use async, domain-aware GoogleAnalytics JS --- 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' =>