123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class GoogleAnalyticsPlugin extends Plugin
- {
- var $code;
- var $domain;
- const VERSION = '0.2';
- function __construct($code=null)
- {
- if (!empty($code)) {
- global $config;
- $config['googleanalytics']['code'] = $code;
- }
- parent::__construct();
- }
- function onEndShowScripts($action)
- {
- $code = common_config('googleanalytics', 'code');
- if (empty($code)) {
- $code = $this->code;
- }
- $domain = common_config('googleanalytics', 'domain');
- if (empty($domain)) {
- $domain = $this->domain;
- }
- $js = <<<ENDOFSCRIPT0
- var _gaq = _gaq || [];
- _gaq.push(['_setAccount', '{$code}']);
- _gaq.push(['_trackPageview']);
- ENDOFSCRIPT0;
- if (!empty($domain)) {
- $js .= <<<ENDOFSCRIPT1
- _gaq.push(['_setDomainName', '{$domain}']);
- _gaq.push(['_setAllowHash', false]);
- ENDOFSCRIPT1;
- }
- $js .= <<<ENDOFSCRIPT2
- (function() {
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
- })();
- ENDOFSCRIPT2;
- $action->inlineScript($js);
- }
- function onPluginVersion(&$versions)
- {
- $versions[] = array('name' => 'GoogleAnalytics',
- 'version' => self::VERSION,
- 'author' => 'Evan Prodromou',
- 'homepage' => 'http://status.net/wiki/Plugin:GoogleAnalytics',
- 'rawdescription' =>
-
- _m('Use <a href="http://www.google.com/analytics/">Google Analytics</a>'.
- ' to track web access.'));
- return true;
- }
- }
|