trackPageView
The trackPageView() method records a page view.
Syntax
trackPageView(customPageTitle)trackPageView(customPageTitle?): voidtrackPageView(customPageTitle?): voidtrackPageView(customPageTitle?): voidtrackPageView(customPageTitle?): voidtrackPageView(customPageTitle?): voidtrackPageView(customPageTitle?): voidParameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| customPageTitle | string | The custom page title for the tracked page view. | No |
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?): voidtrackPageView(customPageTitle?): voidtrackPageView(customPageTitle?): voidimport { PageViews } from '@piwikpro/react-piwik-pro';
...
const App = () => {
PageViews.trackPageView();
return ...;
}trackPageView(customPageTitle?): voidTo 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?): voidtrackPageView(customPageTitle?): voidtrackPageView(customPageTitle?): voidimport { PageViews } from '@piwikpro/react-piwik-pro';
...
const App = () => {
PageViews.trackPageView('Homepage');
return ...;
}
export default ApptrackPageView(customPageTitle?): voidNotes
- 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 13 days ago