Using The Page View API

Updated 3 months ago by Michael Alon

Aptrinsic tracks page views automatically including when installed in SPA applications. Page View API allows for programmatically tracking virtual web pages for dynamic content or in applications that does not use routing. By default the Aptrinsic track page view using document.title and document.location, it can be overridden using the following API:

aptrinsic('pageView', [pageDetailsObj])

Object can contain the following fields (non are required):

Name

Type

Description

title

string

page title, this will allow to categories the page

url

string

a full URL to track (if the protocol or domain will be missing the URL will be relative to the current document.location.href)

path

string

path part of the URL, needs to start with a slash (\/)

Examples:

aptrinsic("pageView", {"url" "https://example.com/user"});

Lets say the original URL is https://examle.com/user/[userId], and you do not want to track the user id on every page view. This way only the user path is tracked, alternatively you can call Aptrinsic page view with:

aptrinsic("pageView", {"path" "/user"});

This way you only overrides the path portion on the URL

Another example can be change the page title, lets say it is SPA and you want to identify dynamic content by title. You can change the title like:

aptrinsic("pageView", {"title" "update user details""path" "/userDetails"});

This way if you had a popup with user details you can also track this action with title and a specific path. In this case only URL path and title will be overridden


How did we do?