Skip to content

Files

Latest commit

 

History

History
24 lines (17 loc) · 546 Bytes

next-script-for-ga.md

File metadata and controls

24 lines (17 loc) · 546 Bytes

Pattern: Plain script for Google Analytics

Issue: -

Description

Google Analytics scripts should use Next.js's Script component with the strategy prop set appropriately. This ensures proper loading and execution timing for analytics code.

Examples

Example of incorrect code:

<script async src="https://www.googletagmanager.com/gtag/js?id=GA_ID" />

Example of correct code:

import Script from 'next/script'

<Script
  src="https://www.googletagmanager.com/gtag/js?id=GA_ID"
  strategy="afterInteractive"
/>