Bart Veneman

Creator of Project Wallace, analytics for CSS. <noscript>-fanboy. Serverless clearfix engineer. I can lift node_modules twice my own weight.

Anonimized user pages with Fathom Analytics

My Fathom Analytics dashboard for Project Wallace was showing me all url's of the app, including the ones where a profile and project name were part of the url, like so: www.projectwallace.com/~bartveneman/my-project. I don't want this, because:

The solution

To get around this problem, I need to convert every url that contains user-data to a generic URL.

original url analytics url
/~bartveneman /~:user
/~bartveneman/my-project /~:user/:project
/~bartveneman/my-project/imports /~:user/:project/imports

Luckily I have a routes.js file in the Project Wallace Express app, which lists routes like this:

const routes = {
userProfile: "/~:user",
userProject: "/~:user/:project",
userProjectImports: "/~:user/:project/imports",
// etc.
};

Every route with user data starts with /~, so I use that to determine whether Fathom should do it's regular reporting or whether I should inject my own. Fathom has an option to disable automatic tracking on a page and to manually call trackPageview(). This is what it looks like in Project Wallace:

//- NOTE: auto='false' to disable Fathom's auto-tracking. I'm implementing my own.
script(src='https://cdn.usefathom.com/script.js' site=SITE_ID auto='false' defer id='fathom')

if currentUrl.startsWith('/~')
script.
document.querySelector('#fathom')
.addEventListener('load', function () {
fathom.trackPageview({
url: '#{req.route.path}' // req.route.path => /~:user/:project
})
})

else
script.
document.querySelector('#fathom')
.addEventListener('load', function () {
fathom.trackPageview()
})

The result

Fathom dashboard with anonimized user urls

More privacy. More better.