react-server-side-gtm is a React component library designed for integrating Google Tag Manager (GTM) into React applications, with a particular focus on robust server-side tagging capabilities. As an actively maintained fork of the `react-gtm-module` library, it addresses the original project's stagnation by providing more active development and support for newer GTM features. The current stable version is `3.0.1`, with recent `v3.0.0` releases indicating an active development cycle and a steady release cadence. Key differentiators include enhanced support for server-side tagging, offering greater control over data and improved privacy compliance. It also provides flexible options for custom and multiple `dataLayer` configurations, facilitates the integration of additional events, and allows for specific configurations for custom GTM server-side containers and different deployment environments. This library is well-suited for React projects requiring advanced GTM implementations beyond basic client-side tracking, especially those leveraging the performance, security, and data accuracy benefits of server-side Google Tag Manager.
npm install react-server-side-gtmVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes Google Tag Manager upon component mount, pushes initial page view data to the dataLayer, and demonstrates how to push custom events triggered by user actions or asynchronous operations, incorporating environment variables for GTM ID.
Thoroughly review the `react-server-side-gtm` README and API documentation for specific differences when migrating from `react-gtm-module`. Test your GTM integrations comprehensively after upgrading.
Ensure your Google Tag Manager container has a server-side client, and that your GTM server-side endpoint (e.g., `src` parameter in `TagManager.initialize`) points to your deployed GTM server container URL (e.g., `https://your-custom-gtm-server.com`). Refer to Google's official server-side tagging documentation.
Call `TagManager.initialize` only once, typically at your application's root component or entry point. For subsequent data pushes or event triggers, use `TagManager.dataLayer` method to update the dataLayer safely.
Ensure you have `npm install react-server-side-gtm` and use `import TagManager from 'react-server-side-gtm';` at the top of your file.
Double-check your `gtmId` for typos. If using server-side tagging, ensure the `src` parameter in `TagManager.initialize` points to your active GTM server container URL. Verify that `TagManager.dataLayer` calls include an `event` key and necessary parameters.
Ensure all initial `dataLayer` variables are passed in the `dataLayer` object during the initial `TagManager.initialize` call. For subsequent updates, use `TagManager.dataLayer({ dataLayer: { /* new data */ } })` to merge new data without overwriting.No dependency data recorded yet.