Referral program

API

Account

Trigger custom page views

Normally you want to trigger a custom page view for Single Page Apps (SPA’s) like React, Vue, and Angular. Because pages are not completely reloaded on navigation we need a way to track those navigations as page views.

For some analytics tools like Google Analytics you need to trigger a page view via their script. For Simple Analytics this is different.

You don’t have to implement anything to detect page views in SPA’s

Technical explanation

We make this work by overwriting the native pushState-function of the browser.

// We check if the browser supports pushStateif(history.pushState&&Event&&dispatchEvent){// We create a listener based on the original browser featurevarstateListener=function(type){varorig=history[type]returnfunction(){varrv=orig.apply(this,arguments)varevent=newEvent(type)event.arguments=argumentsdispatchEvent(event)returnrv}}// We connect our own created a listener to the pushState featurehistory.pushState=stateListener('pushState')// Now we can listen for pushState events and keep the original feature of the browser workingwindow.addEventListener('pushState',function(){// Here we trigger the page view})}

Simple, clean, privacy-friendly analytics

We are very passionate about privacy and believe we can create valuable products without invading it. Our main servers are located in Iceland and your data is always encrypted – Adriaan CEO (follow on Twitter)