trackPageView
The trackPageView() method records a page view.
Syntax
trackPageView(customPageTitle)
trackPageView(customPageTitle?): void
trackPageView(customPageTitle?): void
trackPageView(customPageTitle?): void
trackPageView(customPageTitle?): void
trackPageView(customPageTitle?): void
trackPageView(customPageTitle?): void
Parameters
customPageTitle (string, optional)
The custom page title for the tracked page view.
Examples
To send a page view:
_paq.push(["trackPageView"]);
@Component(...)
export class TestPageComponent implements OnInit {
constructor(
protected pageViewsService: PageViewsService
) {}
ngOnInit() {
this.pageViewsService.trackPageView()
}
}
trackPageView(customPageTitle?): void
trackPageView(customPageTitle?): void
trackPageView(customPageTitle?): void
import { PageViews } from '@piwik-pro/react-piwik-pro';
...
const App = () => {
PageViews.trackPageView();
return ...;
}
trackPageView(customPageTitle?): void
To send a page view with a custom page title Homepage
:
_paq.push(["trackPageView","Homepage"]);
@Component(...)
export class TestPageComponent implements OnInit {
constructor(
protected pageViewsService: PageViewsService
) {}
ngOnInit() {
this.pageViewsService.trackPageView('Homepage')
}
}
trackPageView(customPageTitle?): void
trackPageView(customPageTitle?): void
trackPageView(customPageTitle?): void
import { PageViews } from '@piwik-pro/react-piwik-pro';
...
const App = () => {
PageViews.trackPageView('Homepage');
return ...;
}
export default App
trackPageView(customPageTitle?): void
Notes
- This method is part of the container code (or tracking code) that you've installed on your site to use Piwik PRO. Most likely your setup already uses it, and you don't need to track page views manually.
- You can use the setDocumentTitle() method to set custom page titles for all following events.
- A session begins with any event that was recorded on a page, not just page view.
- In single-page applications (SPA), you need to call the trackPageView() method for each virtual page view. In SPA, when a visitor moves from one page to another, the page doesn't reload. It loads only once at the beginning of the session. For this reason, page views can't be recorded in the usual way. You can use Angular or React methods described above in lifecycle hooks instead.
Updated 6 days ago