Skip to content

Commit

Permalink
Add custom plausible page view script from docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lookupdaily committed Jul 20, 2023
1 parent 1dfbd70 commit 7c10b7b
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/_layouts/default.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta charset="utf-8" />
<meta charset="utf-8"/>
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
/>
<link rel="apple-touch-icon" sizes="180x180" href="/assets/images/favicon/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/assets/images/favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/assets/images/favicon/favicon-16x16.png">
Expand All @@ -21,14 +21,32 @@
<script src="/assets/js/redirect.js"></script>
{% endif %}

<link rel="stylesheet" href="/assets/main.css" />
<link rel="stylesheet" href="/assets/main.css"/>
<script defer data-domain="playbook.dxw.com" src="https://plausible.io/js/script.manual.js"></script>
<!-- define the `plausible` function to manually trigger events - as the pageview event is not being sent automatically with 'script.manual.js' -->
<script>
window.plausible = window.plausible || function() {
window.plausible = window.plausible || function () {
(window.plausible.q = window.plausible.q || []).push(arguments)
}
</script>

<!-- trigger pageview -->
<script>
function prepareUrl(params) {
const url = new URL(location.href)
const queryParams = new URLSearchParams(location.search)
let customUrl = url.protocol + "//" + url.hostname + url
.pathname
.replace(/\/$/, '')
for (const paramName of params) {
const paramValue = queryParams.get(paramName)
if (paramValue)
customUrl = customUrl + '/' + paramValue
}
return customUrl
}
plausible('pageview', {u: prepareUrl([])})
</script>
</head>
<body>
{% include navbar.html %}
Expand All @@ -38,4 +56,4 @@
</main>
{% include contribute.html %}
</body>
</html>
</html>

0 comments on commit 7c10b7b

Please sign in to comment.