Infinity Campus

Single page application call tracking

Written by Infinity | Nov 19, 2026, 11:52:05 PM

Single page application call tracking needs a little more set-up than a standard website. If your website or application is a Single Page Application (SPA, also known as a browser application), the usual page load events are not dispatched by the visitor's browser as they navigate. This guide explains what SPA Mode does, how to add the SPA plugin to your tracking code, how to set your auto discovery numbers, and how to add callbacks to SPA code.

What is SPA Mode?

If the website or application you want to track with Infinity is a Single Page Application (SPA, also known as a browser application), the usual page load events are not dispatched by the visitor's browser as they navigate around your site.

SPA Mode puts you, and your application, in more control of what happens and when. Rather than relying on the library to perform tasks based on native browser events, you decide the timing.

To track an SPA, you also need to add the Infinity JavaScript to your SPA, and populate the auto discovery number fields in the Infinity Platform, so that number replacement works. We recommend that someone with JavaScript knowledge completes the set-up, because the code is integrated directly into your SPA.

Adding the SPA plugin to the Infinity tracking code

Single page applications behave differently from a standard website. You can change the URL and content of a page without the browser loading a new page. Infinity supports automatic tracking of page views and changes to your page content, without any modifications to your website code. If your website, or part of it, is handled by an SPA, we recommend that you add the SPA plugin to the Infinity tracking code, so that all visitor data is captured.

The additional SPA plugin line of code is shown below:

JavaScript
{ plugins: { spa: {} } }

Add this snippet at the end of the window._its('init', 'XXXX') call, within its brackets, and replace the XXXX with your installation ID:

JavaScript
window._its('init', 'XXXX', { plugins: { spa: {} } });

Below is a sample of the full script with SPA code present:

HTML
<script>
  (function(i,n,f,t,y,x,z) {
    y=i._its=function(){return y.queue.push(arguments)};y.version='2.0';y.queue=[];z=n.createElement(f);z.async=!0;z.src=t;x=n.getElementsByTagName(f)[0];x.parentNode.insertBefore(z,x)})(window, document,'script','https://script.infinity-tracking.com/infinitytrack.js?i=xxxx');
  window._its('init', 'xxxx', { plugins: { spa: {} } });
  window._its('track');
</script>

The sample above is for illustration only and must not be used as it is. Use the script from your Infinity Platform installation, then make the changes listed above. To find the script, go to Settings > Tracking > Tracking Script in the Infinity Platform.

Auto discovery numbers for single page application call tracking

The auto discovery number tells our code which number to find and replace with a dynamic number. The auto discovery number must match the number on your website for website call tracking to activate. The tracking script scans pages for any phone numbers, then tries to find a matching tracking pool and allocates a dynamic number. For single page application call tracking, the same rule applies to every page the SPA renders.

To enter your auto discovery number, go to Settings > Telephony Settings > Tracking Pools Editor > Edit Config in the Infinity Platform.

Tracking pools

If you have multiple tracking pools, you need multiple auto discovery numbers, so that our JavaScript can serve the correct phone numbers to the correct place.

Number formatting

We recommend that you enter all auto discovery numbers in E.164 format. This is the most flexible option. In most cases, the tracking script then works without any changes to the existing markup of your site.

You can use your destination number as your auto discovery number. It is displayed if the dynamic number fails to load.

Adding callbacks to SPA code

Note: Only applicable for an older version of our JavaScript code. Contact support@infinity.co before you follow these steps.

If you want to include callbacks and you are using SPA Mode, add them in the same place as your _track call is made.

The structure of callbacks is identical to non-SPA code. However, before the callbacks are added to the config, and before _track, call _resetCallbacks. This makes sure the callbacks run, and can run again, against the correct browser and application state.

JavaScript
Router.reopen({
  performInfinityTracking: () => {
    _ictt.push(['_resetCallbacks']);
    _ictt.push(['_addCallback', () => { console.log('Callback was Fired'); } ]);
    _ictt.push(['_track']);
  }.on('didTransition')
});