ENGINEERING |
February 8, 2021

Capture page navigation events in a React Application

In a single-page application, understanding which pages your customers visit and the journeys they take through your website can be challenging. Here, we’ll look at a scalable and maintainable strategy for tracking page navigation events in a React application.

Why track customer page views?

Page view tracking is one of the most important data points to capture when building a picture of how your customers interact with your site. Knowing which pages specific customers visit and how long they spend on each page allows you to eliminate blockers in common user flows, remarket to individual customers based on the content they view, and perform a wide variety of other user experience optimizations.

Websites that are not built with SPA architecture perform full HTTP request-response cycles each time a user navigates to a new different page, which makes implementing page view analytics relatively straightforward. Typically, in this type of “traditional” website, all it takes is placing a snippet of code in a tag at the bottom of the document to tell analytics services when and for how long users visit specific pages. Since single-page applications use client-side rendering to handle page navigation dynamically, however, tracking page views can be slightly more complicated.

Firing analytics tracking with lifecycle hooks

As we can see, as in our last example, ViewDetail events are being sent to mParticle. When customers click on specific products, that product’s name, SKU, price and quantity are visible in the mParticle Live Stream. Now that we have separate pages in our application, however, we don’t just want to track the individual products our customers view. We would like to know which pages they visit, in what order, and how much time they spend on each page.

Websites that are not built with SPA architecture perform full HTTP request-response cycles each time a user navigates to a new different page, which makes implementing page view analytics relatively straightforward. Typically, in this type of “traditional” website, all it takes is placing a snippet of code in a tag at the bottom of the document to tell analytics services when and for how long users visit specific pages. Since single-page applications use client-side rendering to handle page navigation dynamically, however, tracking page views can be slightly more complicated.

Making it scalable

As we can see, as in our last example, ViewDetail events are being sent to mParticle. When customers click on specific products, that product’s name, SKU, price and quantity are visible in the mParticle Live Stream. Now that we have separate pages in our application, however, we don’t just want to track the individual products our customers view. We would like to know which pages they visit, in what order, and how much time they spend on each page.

  • Call trackPageView() to run the first time the component renders.
  • Call trackPageView() to run the first time the component renders.
  • Call trackPageView() to run the first time the component renders.

You Might Also Want To Read

Growth
March 08, 2022
Strategische erneute Kundenansprache mit zentralisierter Zielgruppen-Orchestrierung
Growth
March 08, 2022
Strategische erneute Kundenansprache mit zentralisierter Zielgruppen-Orchestrierung
Growth
March 08, 2022
Strategische erneute Kundenansprache mit zentralisierter Zielgruppen-Orchestrierung
Growth
March 08, 2022
Strategische erneute Kundenansprache mit zentralisierter Zielgruppen-Orchestrierung

More From The Expert

Growth
March 08, 2022
Strategische erneute Kundenansprache mit zentralisierter Zielgruppen-Orchestrierung
Growth
March 08, 2022
Strategische erneute Kundenansprache mit zentralisierter Zielgruppen-Orchestrierung
Growth
March 08, 2022
Strategische erneute Kundenansprache mit zentralisierter Zielgruppen-Orchestrierung
Growth
March 08, 2022
Strategische erneute Kundenansprache mit zentralisierter Zielgruppen-Orchestrierung
FROM EARLY-STAGE START-UPS TO FORTUNE 500 COMPANIES

EMPOWERING PROFESSIONALS GLOBALLY

Apple
Amgen
Brother
Boston Childrens Hospital

LIVE

Online & In-Person Events by Industry Experts

We use cookies to make interactions, with our websites and services, easy and meaningful.

Read our privacy policy to know more.