jenkins-bot has submitted this change and it was merged. Change subject: New version 3.0.0 ......................................................................
New version 3.0.0 With the following changes: * updated JavaScript code to Universal Analytics * added ability to specify custom analytics code (for use with non-Google analytics services) * added ability to exclude specific pages/namespaces from analytics * removed AdSense integration support * removed analytics code from UserLogin, Preferences and other configurable special pages * removed function addGoogleAnalytics() * removed $wgGoogleAnalyticsIgnoreSysops and $wgGoogleAnalyticsIgnoreBots Change-Id: Icbfa27816ede67bdb2e6927b4115b9e9588044a0 --- M googleAnalytics.php M i18n/en.json 2 files changed, 80 insertions(+), 56 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/googleAnalytics.php b/googleAnalytics.php index 530080b..b365057 100644 --- a/googleAnalytics.php +++ b/googleAnalytics.php @@ -4,70 +4,93 @@ } $wgExtensionCredits['other'][] = array( - 'path' => __FILE__, - 'name' => 'Google Analytics Integration', - 'version' => '2.1.0', - 'author' => 'Tim Laqua', + 'path' => __FILE__, + 'name' => 'Google Analytics Integration', + 'version' => '3.0.0', + 'author' => array( 'Tim Laqua', '[https://www.mediawiki.org/wiki/User:DavisNT Davis Mosenkovs]' ), 'descriptionmsg' => 'googleanalytics-desc', - 'url' => 'https://www.mediawiki.org/wiki/Extension:Google_Analytics_Integration', + 'url' => 'https://www.mediawiki.org/wiki/Extension:Google_Analytics_Integration', ); $wgMessagesDirs['googleAnalytics'] = __DIR__ . '/i18n'; -$wgExtensionMessagesFiles['googleAnalytics'] = dirname(__FILE__) . '/googleAnalytics.i18n.php'; +$wgExtensionMessagesFiles['googleAnalytics'] = __DIR__ . '/googleAnalytics.i18n.php'; -$wgHooks['SkinAfterBottomScripts'][] = 'efGoogleAnalyticsHookText'; -$wgHooks['ParserAfterTidy'][] = 'efGoogleAnalyticsASAC'; +/*** Default configuration ***/ -$wgGoogleAnalyticsAccount = ""; -$wgGoogleAnalyticsAddASAC = false; +// Google Universal Analytics account id (e.g. "UA-12345678-1") +$wgGoogleAnalyticsAccount = ''; + +// HTML code for other web analytics (can be used along with Google Universal Analytics) +$wgGoogleAnalyticsOtherCode = ''; + +// Array with NUMERIC namespace IDs where web analytics code should NOT be included. +$wgGoogleAnalyticsIgnoreNsIDs = array(); + +// Array with page names (see magic word {{FULLPAGENAME}}) where web analytics code should NOT be included. +$wgGoogleAnalyticsIgnorePages = array(); + +// Array with special pages where web analytics code should NOT be included. +$wgGoogleAnalyticsIgnoreSpecials = array( 'Userlogin', 'Userlogout', 'Preferences', 'ChangePassword' ); + +/* WARNING! The following options were removed in version 3.0: + * $wgGoogleAnalyticsAddASAC + * $wgGoogleAnalyticsIgnoreSysops + * $wgGoogleAnalyticsIgnoreBots + * It is possible (and advised) to use 'noanalytics' permission to exclude specific groups from web analytics. */ + +/*****************************/ -// These options are deprecated. -// You should add the "noanalytics" right to the group -// Ex: $wgGroupPermissions["sysop"]["noanalytics"] = true; -$wgGoogleAnalyticsIgnoreSysops = true; -$wgGoogleAnalyticsIgnoreBots = true; +$wgHooks['SkinAfterBottomScripts'][] = 'wfUniversalAnalyticsIntegrationSABS'; -function efGoogleAnalyticsASAC( &$parser, &$text ) { - global $wgOut, $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsAddASAC; +function wfUniversalAnalyticsIntegrationSABS( $skin, &$text = '' ) { + global $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsOtherCode, $wgGoogleAnalyticsIgnoreNsIDs, + $wgGoogleAnalyticsIgnorePages, $wgGoogleAnalyticsIgnoreSpecials; - if( !empty($wgGoogleAnalyticsAccount) && $wgGoogleAnalyticsAddASAC ) { - $wgOut->addScript('<script type="text/javascript">window.google_analytics_uacct = "' . $wgGoogleAnalyticsAccount . '";</script>'); + if ( $skin->getUser()->isAllowed( 'noanalytics' ) ) { + $text .= "<!-- Web analytics code inclusion is disabled for this user. -->\r\n"; + return true; + } + + if ( count( array_filter( $wgGoogleAnalyticsIgnoreSpecials, function ( $v ) use ( $skin ) { + return $skin->getTitle()->isSpecial( $v ); + } ) ) > 0 + || in_array( $skin->getTitle()->getNamespace(), $wgGoogleAnalyticsIgnoreNsIDs, true ) + || in_array( $skin->getTitle()->getPrefixedText(), $wgGoogleAnalyticsIgnorePages, true ) ) { + $text .= "<!-- Web analytics code inclusion is disabled for this page. -->\r\n"; + return true; + } + + $appended = false; + + if ( $wgGoogleAnalyticsAccount !== '' ) { + $text .= <<<EOD +<script> + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + + ga('create', ' +EOD +. $wgGoogleAnalyticsAccount . <<<EOD +', 'auto'); + ga('send', 'pageview'); + +</script> + +EOD; + $appended = true; + } + + if ( $wgGoogleAnalyticsOtherCode !== '' ) { + $text .= $wgGoogleAnalyticsOtherCode . "\r\n"; + $appended = true; + } + + if ( !$appended ) { + $text .= "<!-- No web analytics configured. -->\r\n"; } return true; } - -function efGoogleAnalyticsHookText( $skin, &$text='' ) { - $text .= efAddGoogleAnalytics(); - return true; -} - -function efAddGoogleAnalytics() { - global $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsIgnoreSysops, $wgGoogleAnalyticsIgnoreBots, $wgUser; - if ( $wgUser->isAllowed( 'noanalytics' ) || - $wgGoogleAnalyticsIgnoreBots && $wgUser->isAllowed( 'bot' ) || - $wgGoogleAnalyticsIgnoreSysops && $wgUser->isAllowed( 'protect' ) ) { - return "\n<!-- Google Analytics tracking is disabled for this user -->"; - } - - if ( $wgGoogleAnalyticsAccount === '' ) { - return "\n<!-- Set \$wgGoogleAnalyticsAccount to your account # provided by Google Analytics. -->"; - } - - return <<<HTML -<script type="text/javascript"> -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")); -</script> -<script type="text/javascript"> -try { -var pageTracker = _gat._getTracker("{$wgGoogleAnalyticsAccount}"); -pageTracker._trackPageview(); -} catch(err) {} -</script> -HTML; -} - -///Alias for efAddGoogleAnalytics - backwards compatibility. -function addGoogleAnalytics() { return efAddGoogleAnalytics(); } diff --git a/i18n/en.json b/i18n/en.json index dc72788..ebb478e 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -1,9 +1,10 @@ { "@metadata": { "authors": [ - "Tim Laqua" + "Tim Laqua", + "Davis Mosenkovs" ] }, - "googleanalytics-desc": "Inserts Google Analytics script (ga.js) in to MediaWiki pages for tracking", - "right-noanalytics": "Exempted from Google Analytics tracking" + "googleanalytics-desc": "Inserts Google Universal Analytics (and/or other web analytics) scripts into MediaWiki pages for tracking", + "right-noanalytics": "Exempted from web analytics tracking" } \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/175309 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Icbfa27816ede67bdb2e6927b4115b9e9588044a0 Gerrit-PatchSet: 8 Gerrit-Project: mediawiki/extensions/googleAnalytics Gerrit-Branch: master Gerrit-Owner: DavisNT <[email protected]> Gerrit-Reviewer: Brent Garber <[email protected]> Gerrit-Reviewer: DavisNT <[email protected]> Gerrit-Reviewer: Jforrester <[email protected]> Gerrit-Reviewer: Legoktm <[email protected]> Gerrit-Reviewer: Siebrand <[email protected]> Gerrit-Reviewer: jenkins-bot <> Gerrit-Reviewer: shinjiman <[email protected]> Gerrit-Reviewer: tosfos <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
