# Google Analytics 4 Tag

> Adds the Google Analytics 4 (gtag.js) tracking code to the head of every public page.

- Type: HTML
- Runs: Site-wide header
- Category: [Analytics & Tracking](https://wpide.com/library/category/analytics/)
- Tags: analytics, google-analytics, ga4, tracking
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/google-analytics-4/

## Code

```html
<!-- Google Analytics 4. Replace G-XXXXXXXXXX with your Measurement ID (two places). -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-XXXXXXXXXX');
</script>
```

## Notes

Find your Measurement ID in Google Analytics under Admin > Data streams. G-XXXXXXXXXX is a placeholder. Check your privacy and consent obligations before enabling.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Google Analytics 4 Tag" in its snippet library and add it in one click; or create a new HTML snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
