Skip to content

Commit 71ec788

Browse files
viteksafronoviMattPro
authored andcommitted
Added an ability to track user id
1 parent 532608d commit 71ec788

4 files changed

Lines changed: 61 additions & 3 deletions

File tree

event/listener.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ static public function getSubscribedEvents()
6666
public function load_google_analytics()
6767
{
6868
$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+
}
6973
}
7074

7175
/**
@@ -94,6 +98,12 @@ public function add_googleanalytics_configs($event)
9498
'type' => 'text:40:20',
9599
'explain' => true,
96100
),
101+
'googleanalytics_track_user_id' => array(
102+
'lang' => 'ACP_GOOGLEANALYTICS_TRACK_USER_ID',
103+
'validate' => 'bool',
104+
'type' => 'radio:yes_no',
105+
'explain' => true,
106+
),
97107
);
98108

99109
// Add the new config vars after board_timezone in the display_vars config array

language/en/googleanalytics_acp.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
//
3939

4040
$lang = array_merge($lang, array(
41-
'ACP_GOOGLEANALYTICS_ID' => 'Google Analytics ID',
42-
'ACP_GOOGLEANALYTICS_ID_EXPLAIN' => 'Enter your Google Analytics ID code, e.g.: <samp>UA-0000000-00</samp>.',
43-
'ACP_GOOGLEANALYTICS_ID_INVALID' => '“%s” is not a valid Google Analytics ID code.<br />It should be in the form “UA-0000000-00”.',
41+
'ACP_GOOGLEANALYTICS_ID' => 'Google Analytics ID',
42+
'ACP_GOOGLEANALYTICS_ID_EXPLAIN' => 'Enter your Google Analytics ID code, e.g.: <samp>UA-0000000-00</samp>.',
43+
'ACP_GOOGLEANALYTICS_ID_INVALID' => '“%s” is not a valid Google Analytics ID code.<br />It should be in the form “UA-0000000-00”.',
44+
'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.',
4446
));
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+
namespace phpbb\googleanalytics\migrations\v10x;
12+
13+
/**
14+
* Migration stage 2: Add default config value for user id tracking
15+
*/
16+
class m2_track_user_id extends \phpbb\db\migration\migration
17+
{
18+
/**
19+
* Assign migration file dependencies for this migration
20+
*
21+
* @return array Array of migration files
22+
* @static
23+
* @access public
24+
*/
25+
static public function depends_on()
26+
{
27+
return array(
28+
'\phpbb\db\migration\data\v310\gold',
29+
'\phpbb\googleanalytics\migrations\v10x\m1_initial_data'
30+
);
31+
}
32+
33+
/**
34+
* Add Google Analytics data to the database.
35+
*
36+
* @return array Array of table data
37+
* @access public
38+
*/
39+
public function update_data()
40+
{
41+
return array(
42+
array('config.add', array('googleanalytics_track_user_id', 0)),
43+
);
44+
}
45+
}

styles/all/template/event/overall_header_stylesheets_after.html

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

88
ga('create', '{GOOGLEANALYTICS_ID}', 'auto');
9+
{GOOGLEANALYTICS_USER_ID}
910
<!-- EVENT phpbb_googleanalytics_alter_ga_requirements -->
1011
ga('send', 'pageview');
1112
</script>

0 commit comments

Comments
 (0)