From 9171aa88ad1c4e332cfde3caadb020efec4e395c Mon Sep 17 00:00:00 2001 From: "Collin J. Doering" Date: Sat, 18 Dec 2021 20:37:59 -0500 Subject: [PATCH] Replace broken piwiki analytics with self-hosted plausible * templates/partials/analytics.html: Upon a client load of the website, determine which site they are viewing (dev, staging, production) and setup plausible analytics appropriately. * templates/default.html: Remove non-functional piwiki script reference and replace with a reference to the new partial template for analytics * src/site.hs (main): Remove remnant of application cache support * js/default.js: Remove unneeded analytics code specific to piwiki. No additions were made here in support of plausible * TODO.org: Mark associated TODO item DONE --- TODO.org | 6 +++- js/default.js | 46 ------------------------------- src/site.hs | 13 ++------- templates/default.html | 4 +-- templates/partials/analytics.html | 21 ++++++++++++++ 5 files changed, 30 insertions(+), 60 deletions(-) create mode 100644 templates/partials/analytics.html diff --git a/TODO.org b/TODO.org index 5c3e10a..66c552f 100644 --- a/TODO.org +++ b/TODO.org @@ -9,7 +9,11 @@ CLOSED: [2021-11-28 Sun 10:43] See: - [[file:js/default.js::// Add fullscreen functionality to inline-images and figures][Fullscreen image onclik functionality is added in the router upon content loading, which doesn't occur on the intial page load]] * TODO Completely replace all references to stack -* TODO Fix analytics (pywiki is no longer in use, find and use something else) +* DONE Fix analytics (pywiki is no longer in use, find and use something else) +CLOSED: [2021-12-18 Sat 20:31] +- Note taken on [2021-12-18 Sat 20:31] \\ + Decided to use [[https://github.com/plausible/analytics][Plausible]], self hosted on my single use AWS ec2. +- State "DONE" from "TODO" [2021-12-18 Sat 20:31] * TODO Modernize javascript in [[file:js/default.js][js/default.js]] * TODO Allow posts (and pages?) to be written in org-mode diff --git a/js/default.js b/js/default.js index 220e9ca..b77f93e 100644 --- a/js/default.js +++ b/js/default.js @@ -27,9 +27,6 @@ /*global jQuery, MathJax*/ //------------------------ -// Global array for processing piwik analytics commands -var _paq = _paq || []; - (function ($, mj) { "use strict"; @@ -196,49 +193,6 @@ var _paq = _paq || []; return spec; }()), - analytics = (function () { - var inited = false, - spec = { - trackPageView: trackPageView, - debugEnable: function () { - init(); - } - }; - - function trackPageView (href) { - if (inited) { - _paq.push(["setDocumentTitle", document.domain + href]); - _paq.push(["trackPageView"]); - } - } - - function init() { - if (!inited) { - _paq.push(["setDoNotTrack", true]); - _paq.push(["enableLinkTracking"]); - _paq.push(["setTrackerUrl", "//analytics.rekahsoft.ca/piwik.php"]); - _paq.push(["setSiteId", 1]); - - inited = true; - } - } - - // Initialize piwik.js when site is initially loaded - router.onInit(function () { - if (document.domain != "localhost") { - init(); - trackPageView('/'); - } - }); - - // Track page views with piwik each time the url changes - router.onChange(function (url, dta) { - trackPageView(url); - }); - - return spec - }()), - site = (function () { var status = (function () { var messages = [], diff --git a/src/site.hs b/src/site.hs index 2241508..40a7a3f 100644 --- a/src/site.hs +++ b/src/site.hs @@ -151,9 +151,7 @@ main = hakyllWith myConfig $ do paginateContext paginatedTaggedPosts pageNum <> constField "tag" tag <> listField "posts" (taggedPostCtx tags) (return posts) - indexCtx = if pageNum <= 2 - then appCacheCtx <> navCtx - else navCtx + indexCtx = navCtx makeItem "" >>= loadAndApplyTemplate "templates/tag-page.html" ctx @@ -186,9 +184,7 @@ main = hakyllWith myConfig $ do let ctx = taggedPostCtx tags <> paginateContext paginatedPosts pageNum <> listField "posts" (taggedPostCtx tags) (return posts) - indexCtx = if pageNum <= 2 - then appCacheCtx <> navCtx - else navCtx + indexCtx = navCtx makeItem "" >>= loadAndApplyTemplate "templates/pages/blog.html" ctx @@ -215,7 +211,7 @@ main = hakyllWith myConfig $ do listField "posts" (taggedPostCtx tags) (return posts) <> tagCloudField "tagCloud" 65 135 tags <> defaultContext - indexCtx = navCtx <> appCacheCtx + indexCtx = navCtx sectionCtx <- getResourceBody >>= genSectionContext pg <- loadSnapshot (fromFilePath pageTemplate) "original" @@ -286,9 +282,6 @@ postCtx = dateField "date" "%B %e, %Y" <> taggedPostCtx :: Tags -> Context String taggedPostCtx tags = tagsField "tags" tags <> postCtx -appCacheCtx :: Context String -appCacheCtx = constField "appcache" "true" - pageWeight :: (Functor f, MonadMetadata f) => Item a -> f Int pageWeight i = fmap (maybe 0 read) $ getMetadataField (itemIdentifier i) "weight" diff --git a/templates/default.html b/templates/default.html index eaa32df..ee3a6db 100644 --- a/templates/default.html +++ b/templates/default.html @@ -24,9 +24,7 @@ - - - + $partial("templates/partials/analytics.html")$ $partial("templates/partials/logo-banner.html")$ $partial("templates/partials/nav.html")$ diff --git a/templates/partials/analytics.html b/templates/partials/analytics.html new file mode 100644 index 0000000..ae767e0 --- /dev/null +++ b/templates/partials/analytics.html @@ -0,0 +1,21 @@ +