Single-page Application Tracking
DXA can be implemented on Single-page applications (SPAs) using technologies such as AngularJS or Backbone.js by deploying the regular tracking code. If the application is designed using the HTML 5 History API, virtual page views will be automatically detected and tracked by DXA.
trackPageView
endpoint.Example code
Passing data layer variables
PRODUCT-PRODUCTNAME-D12345
With this being the case, we are able to use the above example trackPageView call, which would send the page to DXA as the below:
URL fragment and query changes
Arguments
The below outlines the arguments that can be passed as part of the trackPageView endpoint.
- path (string) — Absolute path of the page (optional). If not provided, the path currently displayed in the browser will be used.
- params (object) — An object containing one or more properties (optional). Parameters may include any of:
- title: Title of the page. If not provided, the title currently displayed in the browser will be used.
- queryString — The query string part of the URL for the page (for example "?page=2"). If not provided, the query string currently displayed in the browser address bar will be used.
- fragment — The fragment part of the URL for the page (for example "#/Page/1"). If not provided, the fragment currently displayed in the browser address bar will be used.
- waitTime — The time in milliseconds that it took the page or state to load.
Further examples
Testing trackPageView
In order to test if triggering trackPageView has been successful, you can do this by using the DXA Google Chrome extension. Ensure you have logging enabled and are logged into the DXA platform within the same browser session that you're testing.
If the trackPageView call has been configured correctly, you should see a log in the console that references DXA, followed by the website ID, followed by "Page", while you will also see a log in the console called API, with the endpoint set to trackPageView. The Page log represents a page call being made to DXA. You will then be able to see the URL that is passed to DXA in the URL section of this log, such as in the image above. You can also click the arrow icon on the second line of the page console log to view this in more detail, such as in the image below: