1<?php
2/**
3 * DokuWiki plugin for hubspot
4 *
5 * Generates the inserted js/html code that is inserted into dom (HTML-HEAD)
6 *
7 * @license GPLv3 (http://www.gnu.org/licenses/gpl.html)
8 * @author  Pieter van Os (info@pkservices.nl)
9 */
10require_once(DOKU_INC . 'inc/auth.php');
11
12
13/**
14 * Injects the necessary trackingcodes for hubspot tracking into DOM
15 * Original code base for this plugin is the Matomo tracking plugin
16 */
17function hubspot_tracking()
18{
19    global $conf;
20
21    if (isset($conf['plugin']['hubspot']['js_tracking_code']))
22      {
23        // Config does not contain keys if they are default;
24        // so check whether they are set & to non-default value
25
26        // default 0, so check if it's not set or 0
27        if (!isset($conf['plugin']['hubspot']['track_admin_user'])
28            || $conf['plugin']['hubspot']['track_admin_user'] == 0
29        ) {
30            if (isset($_SERVER['REMOTE_USER']) && auth_isadmin()) {
31                return;
32            }
33        }
34
35        // default 1, so check if it's set and 0
36        if (isset($conf['plugin']['hubspot']['track_user'])
37            && $conf['plugin']['hubspot']['track_user'] == 0
38        ) {
39            if (isset($_SERVER['REMOTE_USER'])) {
40                return;
41            }
42        }
43
44        // Changes made by Pieter van Os (info@pkservices.nl)
45        $trackingCode = (isset($conf['plugin']['hubspot']['js_tracking_code']))
46            ? $conf['plugin']['hubspot']['js_tracking_code'] : '';
47        ptln($trackingCode);
48    } else {
49        // Show configuration tip for admin
50        if (isset($_SERVER['REMOTE_USER']) && auth_isadmin()) {
51            msg('Please configure the hubspot plugin <a href="doku.php?id=start&do=admin&page=config#plugin____hubspot____plugin_settings_name">here</a>');
52        }
53    }
54}
55