jenkins-bot has submitted this change and it was merged.

Change subject: Add option for GA anonymizeIp
......................................................................


Add option for GA anonymizeIp

Added configuration parameter $wgGoogleAnalyticsAnonymizeIP
For more info see https://support.google.com/analytics/answer/2763052?hl=en

Change-Id: I36a08c9a34224ba99c7faa785f7eea8fa7684aba
---
M googleAnalytics.hooks.php
M googleAnalytics.php
M tests/GoogleAnalyticsHooksTest.php
3 files changed, 21 insertions(+), 3 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/googleAnalytics.hooks.php b/googleAnalytics.hooks.php
index 88d9cc2..9f77b3e 100644
--- a/googleAnalytics.hooks.php
+++ b/googleAnalytics.hooks.php
@@ -7,8 +7,8 @@
         * @return bool
         */
        public static function onSkinAfterBottomScripts( Skin $skin, &$text = 
'' ) {
-               global $wgGoogleAnalyticsAccount, $wgGoogleAnalyticsOtherCode, 
$wgGoogleAnalyticsIgnoreNsIDs,
-                          $wgGoogleAnalyticsIgnorePages, 
$wgGoogleAnalyticsIgnoreSpecials;
+               global $wgGoogleAnalyticsAccount, 
$wgGoogleAnalyticsAnonymizeIP, $wgGoogleAnalyticsOtherCode,
+                          $wgGoogleAnalyticsIgnoreNsIDs, 
$wgGoogleAnalyticsIgnorePages, $wgGoogleAnalyticsIgnoreSpecials;
 
                if ( $skin->getUser()->isAllowed( 'noanalytics' ) ) {
                        $text .= "<!-- Web analytics code inclusion is disabled 
for this user. -->\r\n";
@@ -38,6 +38,9 @@
 EOD
 . $wgGoogleAnalyticsAccount . <<<EOD
 ', 'auto');
+
+EOD
+. ( $wgGoogleAnalyticsAnonymizeIP ? "  ga('set', 'anonymizeIp', true);\r\n" : 
"" ) . <<<EOD
   ga('send', 'pageview');
 
 </script>
diff --git a/googleAnalytics.php b/googleAnalytics.php
index c43bc8e..f2e922f 100644
--- a/googleAnalytics.php
+++ b/googleAnalytics.php
@@ -6,7 +6,7 @@
 $wgExtensionCredits['other'][] = array(
        'path' => __FILE__,
        'name' => 'Google Analytics Integration',
-       'version' => '3.0.0',
+       'version' => '3.0.1',
        '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',
@@ -20,6 +20,10 @@
 // Google Universal Analytics account id (e.g. "UA-12345678-1")
 $wgGoogleAnalyticsAccount = '';
 
+// Don't store last octet (or last 80 bits of IPv6 address) in Google 
Universal Analytics
+// For more info see https://support.google.com/analytics/answer/2763052?hl=en
+$wgGoogleAnalyticsAnonymizeIP = true;
+
 // HTML code for other web analytics (can be used along with Google Universal 
Analytics)
 $wgGoogleAnalyticsOtherCode = '';
 
diff --git a/tests/GoogleAnalyticsHooksTest.php 
b/tests/GoogleAnalyticsHooksTest.php
index 9a361ca..ae4a151 100644
--- a/tests/GoogleAnalyticsHooksTest.php
+++ b/tests/GoogleAnalyticsHooksTest.php
@@ -67,6 +67,17 @@
                $this->assertContains( 'analytics.example.com/foo.js', $text );
        }
 
+       public function testAnonymizeIp() {
+               $this->setMwGlobals( 'wgGoogleAnalyticsAccount', 'foobarbaz' );
+               $text = '';
+               GoogleAnalyticsHooks::onSkinAfterBottomScripts( 
$this->mockSkin( false ), $text );
+               $this->assertContains( 'anonymizeIp', $text );
+               $this->setMwGlobals( 'wgGoogleAnalyticsAnonymizeIP', false );
+               $text = '';
+               GoogleAnalyticsHooks::onSkinAfterBottomScripts( 
$this->mockSkin( false ), $text );
+               $this->assertNotContains( 'anonymizeIp', $text );
+       }
+
        /**
         * @dataProvider provideExcludedPages
         */

-- 
To view, visit https://gerrit.wikimedia.org/r/189338
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I36a08c9a34224ba99c7faa785f7eea8fa7684aba
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/googleAnalytics
Gerrit-Branch: master
Gerrit-Owner: DavisNT <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to