Skip to content

Commit

Permalink
feat: load matomo only when doNotTrack allows it (#476)
Browse files Browse the repository at this point in the history
* feat: load matomo only when doNotTrack allows it

* chore: update var name for clarity
  • Loading branch information
saenai255 authored Jul 18, 2023
1 parent 1d2b244 commit 1808751
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 38 deletions.
2 changes: 1 addition & 1 deletion client/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
Expand Down
82 changes: 45 additions & 37 deletions client/index.production.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
Expand All @@ -24,44 +24,52 @@
<meta name="next-head-count" content="20" />
<link rel="stylesheet" href="/styles/global.css" />
<script>
var _paq = (window._paq = window._paq || [])
const IS_TRACKING_ALLOWED = navigator.doNotTrack !== '1'

_paq.push(['trackPageView'])
_paq.push(['enableLinkTracking'])
;(function () {
var u = '//pacstall.dev/matomo/'
_paq.push(['setTrackerUrl', u + 'matomo.php'])
_paq.push(['setSiteId', '1'])
var d = document,
g = d.createElement('script'),
s = d.getElementsByTagName('script')[0]
g.async = true
g.src = u + 'matomo.js'
s.parentNode.insertBefore(g, s)
})()
;(function () {
var url = window.location.href
setInterval(function () {
if (url != window.location.href) {
url = window.location.href
if (IS_TRACKING_ALLOWED) {
enableMatomoTracking()
}

// Track page view after 0.75s to catch the title change
setTimeout(function () {
_paq.push([
'setCustomUrl',
window.location.href.split(
'https://pacstall.dev',
)[1],
])
_paq.push([
'setDocumentTitle',
window.document.title,
])
_paq.push(['trackPageView'])
}, 750)
}
}, 100)
})()
function enableMatomoTracking() {
var _paq = (window._paq = window._paq || [])

_paq.push(['trackPageView'])
_paq.push(['enableLinkTracking'])
;(function () {
var u = '//pacstall.dev/matomo/'
_paq.push(['setTrackerUrl', u + 'matomo.php'])
_paq.push(['setSiteId', '1'])
var d = document,
g = d.createElement('script'),
s = d.getElementsByTagName('script')[0]
g.async = true
g.src = u + 'matomo.js'
s.parentNode.insertBefore(g, s)
})()
;(function () {
var url = window.location.href
setInterval(function () {
if (url != window.location.href) {
url = window.location.href

// Track page view after 0.75s to catch the title change
setTimeout(function () {
_paq.push([
'setCustomUrl',
window.location.href.split(
'https://pacstall.dev',
)[1],
])
_paq.push([
'setDocumentTitle',
window.document.title,
])
_paq.push(['trackPageView'])
}, 750)
}
}, 100)
})()
}
</script>
</head>

Expand Down

0 comments on commit 1808751

Please sign in to comment.