Skip to content

Commit 3bba437

Browse files
authored
Merge pull request #2 from phpbb-extensions/master
up to date
2 parents aa27442 + c58d767 commit 3bba437

7 files changed

Lines changed: 143 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
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
*
4+
* Google Analytics extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
/**
12+
* DO NOT CHANGE
13+
*/
14+
if (!defined('IN_PHPBB'))
15+
{
16+
exit;
17+
}
18+
19+
if (empty($lang) || !is_array($lang))
20+
{
21+
$lang = array();
22+
}
23+
24+
// DEVELOPERS PLEASE NOTE
25+
//
26+
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
27+
//
28+
// Placeholders can now contain order information, e.g. instead of
29+
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
30+
// translators to re-order the output of data while ensuring it remains correct
31+
//
32+
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
33+
// equally where a string contains only two placeholders which are used to wrap text
34+
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine
35+
//
36+
// Some characters you may want to copy&paste:
37+
// ’ » “ ” …
38+
//
39+
40+
$lang = array_merge($lang, array(
41+
'ACP_GOOGLEANALYTICS' => 'Google Analytics',
42+
'ACP_GOOGLEANALYTICS_ID' => 'Google Analytics-ID',
43+
'ACP_GOOGLEANALYTICS_ID_EXPLAIN' => 'Gib deine Google Analytics-ID ein, z.B.: <samp>UA-0000000-00</samp>.<br /><br />Google Analytics kann deine registrierten Benutzer für eine genauere Benutzerzählung über mehrere Geräte und Sitzungen hinweg verfolgen. Um diese verbesserte User ID-Funktion nutzen zu können, muss sie in deinem Google Analytics-Account aktiviert sein. <a href="https://support.google.com/analytics/answer/3123666">Klicke hier für mehr Informationen</a>.',
44+
'ACP_GOOGLEANALYTICS_ID_INVALID' => '“%s” ist keine valide Google Analytics-ID.<br />Sie sollte die folgende Form haben: “UA-0000000-00”.',
45+
));
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
*
4+
* Google Analytics extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
/**
12+
* DO NOT CHANGE
13+
*/
14+
if (!defined('IN_PHPBB'))
15+
{
16+
exit;
17+
}
18+
19+
if (empty($lang) || !is_array($lang))
20+
{
21+
$lang = array();
22+
}
23+
24+
// DEVELOPERS PLEASE NOTE
25+
//
26+
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
27+
//
28+
// Placeholders can now contain order information, e.g. instead of
29+
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
30+
// translators to re-order the output of data while ensuring it remains correct
31+
//
32+
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
33+
// equally where a string contains only two placeholders which are used to wrap text
34+
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine
35+
//
36+
// Some characters you may want to copy&paste:
37+
// ’ » “ ” …
38+
//
39+
40+
$lang = array_merge($lang, array(
41+
'ACP_GOOGLEANALYTICS' => 'Google Analytics',
42+
'ACP_GOOGLEANALYTICS_ID' => 'Google Analytics-ID',
43+
'ACP_GOOGLEANALYTICS_ID_EXPLAIN' => 'Geben Sie Ihre Google Analytics-ID ein, z.B.: <samp>UA-0000000-00</samp>.<br /><br />Google Analytics kann Ihre registrierten Benutzer für eine genauere Benutzerzählung über mehrere Geräte und Sitzungen hinweg verfolgen. Um diese verbesserte User ID-Funktion nutzen zu können, muss sie in Ihrem Google Analytics-Account aktiviert sein. <a href="https://support.google.com/analytics/answer/3123666">Klicken Sie hier für mehr Informationen</a>.',
44+
'ACP_GOOGLEANALYTICS_ID_INVALID' => '“%s” ist keine valide Google Analytics-ID.<br />Sie sollte die folgende Form haben: “UA-0000000-00”.',
45+
));

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)