Skip to content

Commit 3fea420

Browse files
committed
Add GDPR Option (anonymize IP)
1 parent 924ed01 commit 3fea420

5 files changed

Lines changed: 53 additions & 2 deletions

File tree

event/listener.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function load_google_analytics()
6868
$this->template->assign_vars(array(
6969
'GOOGLEANALYTICS_ID' => $this->config['googleanalytics_id'],
7070
'GOOGLEANALYTICS_USER_ID' => $this->user->data['user_id'],
71+
'S_ANONYMIZE_IP' => $this->config['ga_anonymize_ip'],
7172
));
7273
}
7374

@@ -98,6 +99,12 @@ public function add_googleanalytics_configs($event)
9899
'type' => 'text:40:20',
99100
'explain' => true,
100101
),
102+
'ga_anonymize_ip' => array(
103+
'lang' => 'ACP_GA_ANONYMIZE_IP',
104+
'validate' => 'bool',
105+
'type' => 'radio:yes_no',
106+
'explain' => true,
107+
),
101108
);
102109

103110
// Add the new config vars after warnings_expire_days in the display_vars config array

language/en/googleanalytics_acp.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@
4242
'ACP_GOOGLEANALYTICS_ID' => 'Google Analytics ID',
4343
'ACP_GOOGLEANALYTICS_ID_EXPLAIN' => 'Enter your Google Analytics ID code, e.g.: <samp>UA-0000000-00</samp>.<br /><br />Google Analytics can track your registered users across multiple devices and sessions, for a more accurate user count in your reports. To enable this enhanced functionality User ID tracking must be configured in your Google Analytics account. <a href="https://support.google.com/analytics/answer/3123666">Click for more information</a>.',
4444
'ACP_GOOGLEANALYTICS_ID_INVALID' => '“%s” is not a valid Google Analytics ID code.<br />It should be in the form “UA-0000000-00”.',
45+
'ACP_GA_ANONYMIZE_IP' => 'Turn on IP Anonymization',
46+
'ACP_GA_ANONYMIZE_IP_EXPLAIN' => 'Enable this option if you want the data collected by Google Analytics to be compliant with the EU‘s General Data Protection Regulation (GDPR). Note that enabling this option may slightly reduce the accuracy of geographic reporting.',
4547
));
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
*
4+
* Google Analytics extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2018 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\googleanalytics\migrations\v10x;
12+
13+
/**
14+
* Migration stage 2: Add anonymize ip config option
15+
*/
16+
class m2_anonymize_ip extends \phpbb\db\migration\migration
17+
{
18+
/**
19+
* {@inheritdoc}
20+
*/
21+
static public function depends_on()
22+
{
23+
return array('\phpbb\googleanalytics\migrations\v10x\m1_initial_data');
24+
}
25+
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public function update_data()
30+
{
31+
return array(
32+
array('config.add', array('ga_anonymize_ip', 0)),
33+
);
34+
}
35+
}

styles/all/template/event/overall_header_stylesheets_after.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
{% if S_REGISTERED_USER -%}
1010
ga('set', 'userId', {{ GOOGLEANALYTICS_USER_ID }});
1111
{% endif -%}
12+
{% if S_ANONYMIZE_IP -%}
13+
ga('set', 'anonymizeIp', true);
14+
{% endif -%}
1215
{% EVENT phpbb_googleanalytics_alter_ga_requirements -%}
1316
ga('send', 'pageview');
1417
</script>

tests/event/listener_test.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public function setUp()
3636
global $phpbb_root_path, $phpEx;
3737

3838
// Load/Mock classes required by the event listener class
39-
$this->config = new \phpbb\config\config(array('googleanalytics_id' => 'UA-000000-01'));
39+
$this->config = new \phpbb\config\config(array(
40+
'googleanalytics_id' => 'UA-000000-01',
41+
'ga_anonymize_ip' => 0,
42+
));
4043
$this->template = $this->getMockBuilder('\phpbb\template\template')
4144
->getMock();
4245
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
@@ -91,6 +94,7 @@ public function test_load_google_analytics()
9194
->with(array(
9295
'GOOGLEANALYTICS_ID' => $this->config['googleanalytics_id'],
9396
'GOOGLEANALYTICS_USER_ID' => $this->user->data['user_id'],
97+
'S_ANONYMIZE_IP' => $this->config['ga_anonymize_ip'],
9498
));
9599

96100
$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
@@ -109,7 +113,7 @@ public function add_googleanalytics_configs_data()
109113
array( // expected config and mode
110114
'settings',
111115
array('vars' => array('warnings_expire_days' => array())),
112-
array('warnings_expire_days', 'legend_googleanalytics', 'googleanalytics_id'),
116+
array('warnings_expire_days', 'legend_googleanalytics', 'googleanalytics_id', 'ga_anonymize_ip'),
113117
),
114118
array( // unexpected mode
115119
'foobar',

0 commit comments

Comments
 (0)