Skip to content

Commit aef8eea

Browse files
committed
Merge pull request #6 from Pico88/temp-event
Add template file
2 parents afd0902 + 17a458b commit aef8eea

4 files changed

Lines changed: 70 additions & 0 deletions

File tree

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
"username": "VSE",
3232
"homepage": "http://mattfriedman.me",
3333
"role": "Extensions Development Team"
34+
},
35+
{
36+
"name": "Lukasz Kaczynski",
37+
"username": "Pico88",
38+
"role": "Extensions Development Team"
3439
}
3540
],
3641
"require": {

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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,49 @@
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.page_header' => '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_var('GOOGLEANALYTICS_ID', $this->config['googleanalytics_id']);
64+
}
2065
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!-- IF GOOGLEANALYTICS_ID -->
2+
<script>
3+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
4+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
5+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
6+
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
7+
8+
ga('create', '{GOOGLEANALYTICS_ID}', 'auto');
9+
ga('send', 'pageview');
10+
11+
</script>
12+
<!-- ENDIF -->

0 commit comments

Comments
 (0)