From 05bdb874fcfb84907b7f084f55fa8f68473e1e80 Mon Sep 17 00:00:00 2001 From: "Collin J. Doering" Date: Wed, 5 Aug 2015 02:53:53 -0400 Subject: [PATCH] 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 --- js/default.js | 18 ++++++++++++++++++ templates/default-nojs.html | 4 ++++ templates/default.html | 3 +++ 3 files changed, 25 insertions(+) diff --git a/js/default.js b/js/default.js index 2a435b4..d324622 100644 --- a/js/default.js +++ b/js/default.js @@ -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', diff --git a/templates/default-nojs.html b/templates/default-nojs.html index 3773d56..d59eae1 100644 --- a/templates/default-nojs.html +++ b/templates/default-nojs.html @@ -29,6 +29,10 @@ +

+ +

+
$partial("templates/partials/logo-banner.html")$ $partial("templates/partials/nav-nojs.html")$ diff --git a/templates/default.html b/templates/default.html index c15a23a..75e642f 100644 --- a/templates/default.html +++ b/templates/default.html @@ -37,6 +37,9 @@ + + + $partial("templates/partials/logo-banner.html")$ $partial("templates/partials/nav.html")$