Track page views yourself
Turn off automatic page views and send them from your own code.
Loomduct tracks page views on its own, on load and on every path change in single-page apps. If you need to decide when a page view happens, for example after your app has loaded its data, turn that off and send page views yourself.
Before you start
- Loomduct installed on your site. See the Quick start.
What counts as a page view
With automatic page views on:
| Case | Page view? |
|---|---|
| Page load | Yes |
The path changes (pushState, replaceState, back, forward) | Yes |
| Only the query string changes (search, filters, pages) | No |
| Only the hash changes | No |
A redirect with replaceState right after load | One page view, for the new path |
| Page opened in a background tab | Counted when the visitor first shows the tab |
Steps
Turn off automatic page views
import { Loomduct } from '@loomduct/js'
import { webAnalytics } from '@loomduct/js/web-analytics'
export const loomduct = new Loomduct({
token: 'lmt_your_project_token',
plugins: [webAnalytics({ autoPageviews: false })],
})Send a page view
Call page() whenever a page is shown:
loomduct.plugins.webAnalytics.page()With the script tag, loomduct.plugins exists only after the SDK has loaded.
Do not call page() while automatic page views are on, or page views are counted twice.
Check that it worked
Open a few pages of your site. In the dashboard, the Pages card on the Overview lists each page you opened, and the Pageviews chart counts them.