# Google Tag Manager (Head)

> Adds the Google Tag Manager container script to the head of every page. Use it together with the GTM body snippet.

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

## Code

```html
<!-- Google Tag Manager. Replace GTM-XXXXXXX with your container ID. -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
```

## Notes

GTM-XXXXXXX is a placeholder for your container ID from tagmanager.google.com.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Google Tag Manager (Head)" 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/
