How to Install GTM on Next.js and React Apps
For Next.js, use the `@next/third-parties` package or add GTM scripts to your root layout. For React SPAs, install via `react-gtm-module` or add scripts to your index.html. The key challenge with SPAs is that GTM's default Page View trigger only fires on the initial load. Use History Change triggers
Quick Summary
For Next.js, use the @next/third-parties package or add GTM scripts to your root layout. For React SPAs, install via react-gtm-module or add scripts to your index.html. The key challenge with SPAs is that GTM's default Page View trigger only fires on the initial load. Use History Change triggers in GTM to capture client-side route changes.
Process Flow
Interactive diagram — drag to pan, scroll to zoom
Step-by-Step Guide
Follow these 4 steps to complete this guide
Next.js (App Router)
Next.js (Pages Router)
React (Create React App / Vite)
Handling SPA Navigation
Was this guide helpful?
Your feedback helps us improve our guides