# `googleTagManager`

The `googleTagManager` registry script. It loads `https://www.googletagmanager.com/gtm.js?id=GTM-ABC1234` for the input of the example. Call `useScriptGoogleTagManager(input, options?)` from `@hamur/scripts/<library>` in a component, or list it under `scripts.registry.googleTagManager` to load it on every page.

| | |
|---|---|
| Config key | `scripts.registry.googleTagManager` |
| Function | `useScriptGoogleTagManager` of `@hamur/scripts/<library>` |
| Input keys | `id` (required), `l`, `auth`, `preview` |
| Default trigger | `client` |
| Script | `https://www.googletagmanager.com/gtm.js?id=GTM-ABC1234` |
| Hosts | `www.googletagmanager.com` |
| Bundle | yes: `scripts.bundle: ["googleTagManager"]` |
| Collection proxy | no |
| Consent | told by `useScriptTriggerConsent`: Google Consent Mode v2 |

## Example

````ts [scripts/registry/google-tag-manager.ts]
import { defineConfig } from "hamur";
import scripts from "@hamur/scripts";

export default defineConfig({
  framework: "react",
  modules: [scripts],
  scripts: {
    registry: {
      googleTagManager: { id: "GTM-ABC1234" },
    },
  },
});
````

It loads after the app mounted and the first idle callback. List `googleTagManager` in `scripts.bundle` and the build serves the file from your origin with a SHA-384 `integrity` (see [Bundling](/scripts#bundle-a-script-into-your-build)). The script sends its own requests to the vendor.

Every key is checked when the config loads and again in `useScriptGoogleTagManager`: a wrong value stops the build with a message that starts with `scripts.registry.googleTagManager`. The registry list is on the [registry](/scripts/registry) page, and the shared options are in [Scripts](/scripts).
