Setup Piwik analytics

Setup Piwik tracking of page loads. The global array _paq is used to
communicate commands to the piwik tracker via the script piwik.js which
is loaded asynchronously from the analytics server. Every time a ajax
call is made successfully and content is loaded in the page, analytics
data is captured and sent to the tracker (the loadPageContent function).

Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
This commit is contained in:
Collin J. Doering 2015-08-05 02:53:53 -04:00
parent 2f16cce227
commit 05bdb874fc
3 changed files with 25 additions and 0 deletions

View File

@ -27,6 +27,20 @@
/*global jQuery, MathJax*/
//------------------------
// Global array for processing piwik analytics commands
var _paq = _paq || [];
_paq.push(["setDoNotTrack", true]);
_paq.push(['enableLinkTracking']);
// Asynchronously load piwik.js
(function() {
var u="//analytics.rekahsoft.ca/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 1]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
(function ($, mj) {
"use strict";
@ -166,6 +180,10 @@
// var pageId = '#page-content', navId = '#nav';
function loadPageContent(page_href, virt_href, handlerCallback) {
// Track page view with piwik
_paq.push(['setDocumentTitle', document.domain + '/' + virt_href]);
_paq.push(['trackPageView']);
$.ajax({
url: page_href,
type: 'GET',

View File

@ -29,6 +29,10 @@
<link href='lib/images/apple-touch-icon-114x114.png' rel='apple-touch-icon' sizes='114x114'>
</head>
<body>
<p>
<img src="//analytics.rekahsoft.ca/piwik.php?idsite=1" style="border:0;" alt="" />
</p>
<div class='container'>
$partial("templates/partials/logo-banner.html")$
$partial("templates/partials/nav-nojs.html")$

View File

@ -37,6 +37,9 @@
</head>
<body>
<!-- Piwik (no js)-->
<noscript><p><img src="//analytics.rekahsoft.ca/piwik.php?idsite=1" style="border:0;" alt="" /></p></noscript>
$partial("templates/partials/logo-banner.html")$
$partial("templates/partials/nav.html")$