Tracking Website Visitors in a Single Page Application

What You'll Learn


How to Trigger a Page View “Manually” via a Single Page Application

Some websites and web pages are built such that it may be useful to track different sections on a single page as separate page views.

This is possible with Net-Results. Here is what is required:

  • Ensure that the Net-Results Tracking Beacon is loaded on the site/page in question
  • Use javascript to trigger a page view event in the Net-Results Tracking Beacon

Some Background

Once you’ve added the Net-Results Tracking Beacon to your website, it continually tracks every page view made by every visitor to your site (with the exception of visitors using certain ad blockers that interfere with marketing tracking beacons). The Tracking Beacon does this by sending data about each page view back to our servers.

The URL of each page viewed is simply text – something like www.yoursite.com/contact. Net-Results records these page views and organizes them into visits. Page views and visits stream continually into the Net-Results platform from websites around the world.

Triggering Page Views Manually

The Net-Results Tracking Beacon loads a javascript object called __MA (the MA stands for Marketing Automation).

Note: there must be two underscores between the “$” symbol and MA.

This $__MA object has multiple properties, some of which are javascript functions. One of these is accessible as __MA.doCapture().

The $__MA.doCapture() function is used by the Net-Results Tracking Beacon to send page view data to Net-Results. Conveniently, you may call this function yourself using javascript based on any events you choose.

If you have a web page divided into discrete sections and you would like to track each of those sections as if it were a separate page view, it’s quite simple:

Call the $__MA.doCapture() function passing 3 parameters:

  • The full URL of the page you would like tracked
  • The referring URL. You may choose to pass the URL of the site itself
  • Your Net-Results Product ID which can be found in the upper right area of the My Account page in Net-Results

When setting this up, you can do so dynamically or static, or any combination of the two

Lets say you have a single web page with sections for About, Pricing and Contact, and that you’d like to record a page view in Net-Results each time one of these sections is viewed.

Here is how to record a static page view for the Pricing section:

$__MA.doCapture(‘www.yourSite.com/Pricing, ‘www.yourSite.com, X);

(X represents your Net-Results Product ID).

Making this a bit more dynamic it may look something like this:

const productId = X;

const sectionName = Y;

$__MA.doCapture(document.location + sectionName, document.referrer, productId);

Example:

var sectionName = "/mySection";
$__MA.doCapture(document.location + sectionName, document.referrer, document.getElementById('__maSrc').getAttribute('data-pid'));

Importantly, Net-Results makes no attempt to validate that a particular URL actually exists. This means you may pass data on page views for web pages that do not exist: simply send a unique URL to Net-Results for each distinct section on your web page.

Updated on September 27, 2023

Was this article helpful?

Related Articles