Skip to content

Instantly share code, notes, and snippets.

@isocroft
Created April 6, 2025 21:30
Show Gist options
  • Select an option

  • Save isocroft/cb735e28e8824f1257867e1e5ad00048 to your computer and use it in GitHub Desktop.

Select an option

Save isocroft/cb735e28e8824f1257867e1e5ad00048 to your computer and use it in GitHub Desktop.
Google tag manager component for ReactJS in NextJS RSC
"use client"
import { useEffect } from "react";
import TagManager from "react-gtm-module";
export default function GoogleTagManager () {
useEffect(() => {
const gtmId = process.env.NEXT_PUBLIC_GTM_ID;
if (gtmId) {
TagManager.initialize({ gtmId });
}
}, []);
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment