Analytics7 min read

Tracking Single Page Application Navigation

By Bob Williams

Single Page Applications (SPAs) present unique challenges for analytics tracking. Traditional page view tracking doesn't work well with client-side routing.

The Challenge

In SPAs, navigation happens without full page reloads. This means traditional analytics tools may not detect route changes.

ListenLayer's Solution

ListenLayer automatically detects route changes in popular frameworks:

  • React Router
  • Angular Router
  • Vue Router
  • Next.js App Router

Implementation Example

// ListenLayer automatically tracks this
router.push('/products');

// DataLayer event is automatically created:
{
  event: 'routeChange',
  page_path: '/products',
  page_title: 'Products',
  referrer: '/home'
}

Custom Events

Beyond automatic tracking, you can fire custom events for specific interactions:

window.dataLayer.push({
  event: 'userEngagement',
  action: 'filter_applied',
  category: 'electronics'
});

Best Practices

  • Let ListenLayer handle automatic tracking
  • Add custom events for business-specific interactions
  • Test in different browsers and devices
  • Monitor the dataLayer in development