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
This commit is contained in:
parent
913c2f0e67
commit
9171aa88ad
6
TODO.org
6
TODO.org
|
@ -9,7 +9,11 @@ CLOSED: [2021-11-28 Sun 10:43]
|
||||||
See:
|
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]]
|
- [[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 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 Modernize javascript in [[file:js/default.js][js/default.js]]
|
||||||
* TODO Allow posts (and pages?) to be written in org-mode
|
* TODO Allow posts (and pages?) to be written in org-mode
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,6 @@
|
||||||
/*global jQuery, MathJax*/
|
/*global jQuery, MathJax*/
|
||||||
//------------------------
|
//------------------------
|
||||||
|
|
||||||
// Global array for processing piwik analytics commands
|
|
||||||
var _paq = _paq || [];
|
|
||||||
|
|
||||||
(function ($, mj) {
|
(function ($, mj) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
@ -196,49 +193,6 @@ var _paq = _paq || [];
|
||||||
return spec;
|
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 () {
|
site = (function () {
|
||||||
var status = (function () {
|
var status = (function () {
|
||||||
var messages = [],
|
var messages = [],
|
||||||
|
|
13
src/site.hs
13
src/site.hs
|
@ -151,9 +151,7 @@ main = hakyllWith myConfig $ do
|
||||||
paginateContext paginatedTaggedPosts pageNum <>
|
paginateContext paginatedTaggedPosts pageNum <>
|
||||||
constField "tag" tag <>
|
constField "tag" tag <>
|
||||||
listField "posts" (taggedPostCtx tags) (return posts)
|
listField "posts" (taggedPostCtx tags) (return posts)
|
||||||
indexCtx = if pageNum <= 2
|
indexCtx = navCtx
|
||||||
then appCacheCtx <> navCtx
|
|
||||||
else navCtx
|
|
||||||
|
|
||||||
makeItem ""
|
makeItem ""
|
||||||
>>= loadAndApplyTemplate "templates/tag-page.html" ctx
|
>>= loadAndApplyTemplate "templates/tag-page.html" ctx
|
||||||
|
@ -186,9 +184,7 @@ main = hakyllWith myConfig $ do
|
||||||
let ctx = taggedPostCtx tags <>
|
let ctx = taggedPostCtx tags <>
|
||||||
paginateContext paginatedPosts pageNum <>
|
paginateContext paginatedPosts pageNum <>
|
||||||
listField "posts" (taggedPostCtx tags) (return posts)
|
listField "posts" (taggedPostCtx tags) (return posts)
|
||||||
indexCtx = if pageNum <= 2
|
indexCtx = navCtx
|
||||||
then appCacheCtx <> navCtx
|
|
||||||
else navCtx
|
|
||||||
|
|
||||||
makeItem ""
|
makeItem ""
|
||||||
>>= loadAndApplyTemplate "templates/pages/blog.html" ctx
|
>>= loadAndApplyTemplate "templates/pages/blog.html" ctx
|
||||||
|
@ -215,7 +211,7 @@ main = hakyllWith myConfig $ do
|
||||||
listField "posts" (taggedPostCtx tags) (return posts) <>
|
listField "posts" (taggedPostCtx tags) (return posts) <>
|
||||||
tagCloudField "tagCloud" 65 135 tags <>
|
tagCloudField "tagCloud" 65 135 tags <>
|
||||||
defaultContext
|
defaultContext
|
||||||
indexCtx = navCtx <> appCacheCtx
|
indexCtx = navCtx
|
||||||
|
|
||||||
sectionCtx <- getResourceBody >>= genSectionContext
|
sectionCtx <- getResourceBody >>= genSectionContext
|
||||||
pg <- loadSnapshot (fromFilePath pageTemplate) "original"
|
pg <- loadSnapshot (fromFilePath pageTemplate) "original"
|
||||||
|
@ -286,9 +282,6 @@ postCtx = dateField "date" "%B %e, %Y" <>
|
||||||
taggedPostCtx :: Tags -> Context String
|
taggedPostCtx :: Tags -> Context String
|
||||||
taggedPostCtx tags = tagsField "tags" tags <> postCtx
|
taggedPostCtx tags = tagsField "tags" tags <> postCtx
|
||||||
|
|
||||||
appCacheCtx :: Context String
|
|
||||||
appCacheCtx = constField "appcache" "true"
|
|
||||||
|
|
||||||
pageWeight :: (Functor f, MonadMetadata f) => Item a -> f Int
|
pageWeight :: (Functor f, MonadMetadata f) => Item a -> f Int
|
||||||
pageWeight i = fmap (maybe 0 read) $ getMetadataField (itemIdentifier i) "weight"
|
pageWeight i = fmap (maybe 0 read) $ getMetadataField (itemIdentifier i) "weight"
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,7 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<!-- Piwik -->
|
$partial("templates/partials/analytics.html")$
|
||||||
<script type="text/javascript" async defer src="//analytics.rekahsoft.ca/piwik.js"></script>
|
|
||||||
<noscript><img src="//analytics.rekahsoft.ca/piwik.php?idsite=1" style="border:0;display:none;" alt="" /></noscript>
|
|
||||||
|
|
||||||
$partial("templates/partials/logo-banner.html")$
|
$partial("templates/partials/logo-banner.html")$
|
||||||
$partial("templates/partials/nav.html")$
|
$partial("templates/partials/nav.html")$
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
<script>
|
||||||
|
var ref = document.createElement("script");
|
||||||
|
ref.setAttribute("type", "text/javascript");
|
||||||
|
|
||||||
|
var script = "https://analytics.rekahsoft.ca/js/plausible.js";
|
||||||
|
|
||||||
|
switch (window.location.hostname) {
|
||||||
|
case "www.blog.rekahsoft.ca":
|
||||||
|
ref.setAttribute("data-domain", "blog.rekahsoft.ca");
|
||||||
|
break;
|
||||||
|
case "www.blog.staging.rekahsoft.ca":
|
||||||
|
ref.setAttribute("data-domain", "blog.staging.rekahsoft.ca");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
script = "https://analytics.rekahsoft.ca/js/plausible.exclusions.local.js";
|
||||||
|
ref.setAttribute("data-domain", "localhost:3000");
|
||||||
|
ref.setAttribute("data-exclude", "localhost:3000");
|
||||||
|
}
|
||||||
|
ref.setAttribute("src", script);
|
||||||
|
document.getElementsByTagName("head")[0].appendChild(ref)
|
||||||
|
</script>
|
Loading…
Reference in New Issue