Skip to content

Commit d68214d

Browse files
viteksafronoviMattPro
authored andcommitted
Template code for user trackig moved to the template. Event test rewritten to match new settings set.
1 parent 71ec788 commit d68214d

5 files changed

Lines changed: 56 additions & 8 deletions

File tree

event/listener.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ static public function getSubscribedEvents()
6565
*/
6666
public function load_google_analytics()
6767
{
68-
$this->template->assign_var('GOOGLEANALYTICS_ID', $this->config['googleanalytics_id']);
69-
if ($this->config['googleanalytics_track_user_id'] && $this->user->data['is_registered'])
70-
{
71-
$this->template->assign_var('GOOGLEANALYTICS_USER_ID', "ga('set', 'userId', {$this->user->data['user_id']});");
72-
}
68+
$this->template->assign_vars(array(
69+
'GOOGLEANALYTICS_ID' => $this->config['googleanalytics_id'],
70+
'GOOGLEANALYTICS_USER_ID' => $this->user->data['user_id'],
71+
'S_GOOGLEANALYTICS_USER_ID' => ($this->config['googleanalytics_track_user_id'] && $this->user->data['is_registered']),
72+
));
7373
}
7474

7575
/**

language/en/googleanalytics_acp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@
4242
'ACP_GOOGLEANALYTICS_ID_EXPLAIN' => 'Enter your Google Analytics ID code, e.g.: <samp>UA-0000000-00</samp>.',
4343
'ACP_GOOGLEANALYTICS_ID_INVALID' => '“%s” is not a valid Google Analytics ID code.<br />It should be in the form “UA-0000000-00”.',
4444
'ACP_GOOGLEANALYTICS_TRACK_USER_ID' => 'Track user id',
45-
'ACP_GOOGLEANALYTICS_TRACK_USER_ID_EXPLAIN' => 'If enabled, Google Analytics will track the unique userId value for each authenticated user.',
45+
'ACP_GOOGLEANALYTICS_TRACK_USER_ID_EXPLAIN' => 'If enabled, Google Analytics will track the unique userId value for each authenticated user. This functionality must be enabled and set up according to <a href="https://support.google.com/analytics/answer/3123666">this article</a>.',
4646
));
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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_ID' => 'Google Analytics ID',
42+
'ACP_GOOGLEANALYTICS_ID_EXPLAIN' => 'Введите ваш идентификатор Google Analytics, например: <samp>UA-0000000-00</samp>.',
43+
'ACP_GOOGLEANALYTICS_ID_INVALID' => '“%s” не является корректным идентификатором Google Analytics.<br />Он должен быть в формате “UA-0000000-00”.',
44+
'ACP_GOOGLEANALYTICS_TRACK_USER_ID' => 'Отслеживать ID пользователя',
45+
'ACP_GOOGLEANALYTICS_TRACK_USER_ID_EXPLAIN' => 'Если включено, Google Analytics будет отслеживать уникальное значение userId для каждого аутентифицированного пользователя. Данная функциональность должна быть включена и настроена согласно <a href="https://support.google.com/analytics/answer/3123666">этой статье</a>.',
46+
));

styles/all/template/event/overall_header_stylesheets_after.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
77

88
ga('create', '{GOOGLEANALYTICS_ID}', 'auto');
9-
{GOOGLEANALYTICS_USER_ID}
9+
<!-- IF S_GOOGLEANALYTICS_USER_ID -->
10+
ga('set', 'userId', {GOOGLEANALYTICS_USER_ID});
11+
<!-- ENDIF -->
1012
<!-- EVENT phpbb_googleanalytics_alter_ga_requirements -->
1113
ga('send', 'pageview');
1214
</script>

tests/event/listener_test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function add_googleanalytics_configs_data()
106106
array( // expected config and mode
107107
'settings',
108108
array('vars' => array('board_timezone' => array())),
109-
array('board_timezone', 'googleanalytics_id'),
109+
array('board_timezone', 'googleanalytics_id', 'googleanalytics_track_user_id'),
110110
),
111111
array( // unexpected mode
112112
'foobar',

0 commit comments

Comments
 (0)