Skip to content

Commit f66ec45

Browse files
committed
Add event listner
1 parent 9922f3f commit f66ec45

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

config/services.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
phpbb.googleanalytics.listener:
3+
class: phpbb\googleanalytics\event\listener
4+
arguments:
5+
- @config
6+
- @template
7+
tags:
8+
- { name: event.listener }

event/listener.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,52 @@
1717
*/
1818
class listener implements EventSubscriberInterface
1919
{
20+
/** @var \phpbb\config\config */
21+
protected $config;
22+
23+
/** @var \phpbb\template\template */
24+
protected $template;
25+
26+
/**
27+
* Constructor
28+
*
29+
* @param \phpbb\config\config $config Config object
30+
* @param \phpbb\template\template $template Template object
31+
* @return \phpbb\boardrules\event\listener
32+
* @access public
33+
*/
34+
public function __construct(\phpbb\config\config $config, \phpbb\template\template $template)
35+
{
36+
$this->config = $config;
37+
$this->template = $template;
38+
}
39+
40+
/**
41+
* Assign functions defined in this class to event listeners in the core
42+
*
43+
* @return array
44+
* @static
45+
* @access public
46+
*/
47+
static public function getSubscribedEvents()
48+
{
49+
return array(
50+
'core.common' => 'load_google_analytics',
51+
);
52+
}
53+
54+
/**
55+
* Load Google Analytics js code
56+
*
57+
* @param object $event The event object
58+
* @return null
59+
* @access public
60+
*/
61+
public function load_google_analytics($event)
62+
{
63+
$this->template->assign_vars(array(
64+
'S_GOOGLE_ANALYTICS_ENABLE' => (!empty($this->config['googleanalytics'])) ? true : false,
65+
'GOOGLE_ANALYTICS_ID' => $this->config['googleanalytics'],
66+
));
67+
}
2068
}

0 commit comments

Comments
 (0)