Skip to content

Latest commit

 

History

History
40 lines (33 loc) · 690 Bytes

gtag_setup.md

File metadata and controls

40 lines (33 loc) · 690 Bytes

Gtag setup

For Nextjs

app.tsx

import { LoadGA4 } from '@freshheads/analytics-essentials/google';

const App = () => {
  return (
    <>
      {process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID && (
        <LoadGA4
          measurementID={process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID}
          debug={true} // optional
          defaultConsent={{
            ad_storage: 'denied',
            analytics_storage: 'denied',
          }} // optional
        />
      )}
    </>
  );
};

Usage

import {
  EventType,
  pushGaEvent,
} from '@freshheads/analytics-essentials/google';

pushGaEvent({ 
    type: EventType.CLICK,
    name: 'hero_button_click' 
});