Features
SPA & virtual pages
Automatic tracking is the default. If your router uses the browser history API, keep the normal script tag.
Automatic routes
The tracker records the initial page and path changes through history.pushState, history.replaceState and back/forward navigation. Replacing state or changing only the query string doesn't add another pageview.
Manual or virtual screens
Turn off automatic pageviews
Add
data-auto-pageviews="false"to your existing script tag. Don't install a second tracker.index.html<script defer src="https://metricraven.com/js/script.js" data-site-id="YOUR_SITE_ID" data-auto-pageviews="false" ></script>Call analytics.pageview from your router
Call it when a screen opens. The helper queues calls until the tracker is ready.
script.js// Call from your browser router or when a virtual screen opens. function trackPageview(path) { if (window.analytics?.pageview) { window.analytics.pageview(path); } else { window.analytics = window.analytics || { q: [] }; window.analytics.q.push(["pageview", path]); } } trackPageview("/checkout/contact"); // After the visitor advances to another virtual screen: // trackPageview("/checkout/payment");Call it for every intended view
Include the initial screen. Manual calls always record a new view, even for the same path. Passing no path records the current URL path.
You can also send manual views alongside automatic tracking for extra virtual screens. If you manually track every router change, disable automatic pageviews to avoid counting the same navigation twice.
Hash routers
For URLs like https://example.com/#/pricing or https://example.com/#!/checkout, add data-track-hash="true". It works with automatic or manual mode and with query stripping.
<script
defer
src="https://metricraven.com/js/script.js"
data-site-id="YOUR_SITE_ID"
data-track-hash="true"
data-strip-query="true"
></script>Use the full reported path, such as /#/pricing, in filters, exclusions and funnel page-prefix steps.
Verify it works
Navigate between two routes and refresh Traffic: each intended route appears once. In manual mode, loading the app alone adds no pageview until your initial screen call runs. Check a goal and the resulting journey against the same logical path.
Details
- Virtual paths must start with a single
/, stay on your current origin and be at most 500 characters after URL encoding. External URLs, backslashes and control characters are refused. - Virtual query strings and fragments are omitted unless they are recognized hash routes you enabled.
- Goals and visible-time reports follow the last logical page until the next view. Scroll goals reset per logical page; delayed goals from the previous page are canceled.
- A
truereturn value frompageview()only means the tracker accepted the call locally; verify delivery in your dashboard. - Only hash paths beginning with
#/or#!/are recognized. Hash query parameters, ordinary anchors such as#pricingand OAuth-style fragments such as#access_token=…are not stored as routes. Changing only a hash query doesn't add a view. Keep secrets out of path segments. - Browser events carry a capture time so fast views and goals keep their order even when requests arrive out of sequence. Future times are capped at receipt time; clocks more than five minutes off fall back to server receipt time. This doesn't change payment-provider transaction timestamps.