]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - plugins/piwik/piwik.php
4 * Adds tracking code on each page.
8 * Initialization function.
9 * It will be called when the plugin is loaded.
10 * This function can be used to return a list of initialization errors.
12 * @param $conf ConfigManager instance.
14 * @return array List of errors (optional).
16 function piwik_init($conf)
18 $piwikUrl = $conf->get('plugins.PIWIK_URL');
19 $piwikSiteid = $conf->get('plugins.PIWIK_SITEID');
20 if (empty($piwikUrl) || empty($piwikSiteid)) {
21 $error = 'Piwik plugin error: ' .
22 'Please define PIWIK_URL and PIWIK_SITEID in the plugin administration page.';
29 * Executed on every page redering.
31 * Template placeholders:
37 * - _PAGE_: current page
38 * - _LOGGEDIN_: true/false
40 * @param array $data data passed to plugin
42 * @return array altered $data.
44 function hook_piwik_render_footer($data, $conf)
46 $piwikUrl = $conf->get('plugins.PIWIK_URL');
47 $piwikSiteid = $conf->get('plugins.PIWIK_SITEID');
48 if (empty($piwikUrl) || empty($piwikSiteid)) {
52 // Free elements at the end of the page.
53 $data['endofpage'][] = '<!-- Piwik -->' .
54 '<script type="text/javascript">' .
55 ' var _paq = _paq || [];' .
56 ' _paq.push([\'trackPageView\']);' .
57 ' _paq.push([\'enableLinkTracking\']);' .
59 ' var u="//' . $piwikUrl . '/";' .
60 ' _paq.push([\'setTrackerUrl\', u+\'piwik.php\']);' .
61 ' _paq.push([\'setSiteId\', \'' . $piwikSiteid . '\']);' .
62 ' var d=document, g=d.createElement(\'script\'), s=d.getElementsByTagName(\'script\')[0];' .
63 ' g.type=\'text/javascript\'; g.async=true; g.defer=true; g.src=u+\'piwik.js\'; s.parentNode.insertBefore(g,s);' .
66 '<noscript><p><img src="//' . $piwikUrl . '/piwik.php?idsite=' . $piwikSiteid . '" style="border:0;" alt="" /></p></noscript>' .
67 '<!-- End Piwik Code -->';