Hash-based routes
View as MarkdownCount `/#/settings` style routes as separate pages in single-page apps that route with the URL hash.
On this page
Most single-page apps change pages with the History API (/pricing, /settings), which the script follows on its own. Some apps route with the hash instead: https://example.com/#/pricing. By default the script ignores the part after #, because on ordinary sites it only points to a heading on the same page, so every hash route would count as one page, /.
Add data-hash="true" to count each hash route as its own page:
<script
defer
data-website-id="ws_your_tracking_id"
data-hash="true"
src="https://reveata.com/js/script.js"
></script>Tag managers and builders that can't set attributes can use the script address instead: https://reveata.com/js/script.js?website-id=ws_your_tracking_id&hash=true. With the npm packages, pass hash: true.
What changes
- A pageview on every hash change. The script listens for
hashchangeas well as History API changes. Changing only the query string is not a new page. - The route becomes part of the path.
https://example.com/app/#/settings/billingis stored as the page/app/#/settings/billing. Hashbang routes (#!/settings) work the same way. A hash that doesn't start with/or!/(a plain#pricinganchor) is not added to the path. - Query strings inside the route are filtered.
#/signup?utm_source=newsletter&token=abckeeps only the campaign parameters (utm_*,ref,via,sourceand ad click ids), exactly like a normal query string. Other values, such as tokens, are never stored. - Campaigns are read from both places. UTM tags and
?ref=work in the real query string (/?utm_source=x#/home) and in the route's own query (/#/home?utm_source=x).
Which routers need it
| Router | Setting that uses the hash | Needs data-hash |
|---|---|---|
| Vue Router | createWebHashHistory() |
Yes |
| React Router | createHashRouter or <HashRouter> |
Yes |
| Angular | withHashLocation() or useHash: true |
Yes |
| Any router in History mode | createWebHistory(), createBrowserRouter, Angular's default |
No |
Install guides: Vue, React Router, Angular.
Goals and filters
Page filters, funnels and page-visit goals match the stored path, so include the hash: a goal for /#/checkout/done, or a filter Page starts with /#/settings. Wildcards work as usual, for example /#/docs/*.
Check it works
Open your app, move between a few routes, and watch the Realtime view: each route should appear as its own page. Add data-debug="true" to see each pageview the script sends in the browser console.