React library for use easily the Google Tag Manager
npm install @tracktor/react-google-tag-manager
Very light React library for use easily the Google Tag Manager
- Installation
- Usage
- Props and options
- Hooks
``console`
yarn add @tracktor/react-google-tag-manager
or
`console`
npm install @tracktor/react-google-tag-manager
or
`console`
bun add @tracktor/react-google-tag-manager
`typescript jsx
import { GoogleTagManagerProvider, useGoogleTagManager } from "@tracktor/react-google-tag-manager";
const App = () => (
);
const YourComponent = () => {
const { sendEvent } = useGoogleTagManager();
return (
Your Component
);
};
export default App;
`
Your can provide some props and options to the provider.
`typescript jsx
import { GoogleTagManagerProvider } from "@tracktor/react-google-tag-manager";
const App = () => (
...
);
export default App;
`
| Props | Type | Default | Description |
|---------|------------|-----------|-------------------------------------------------------------------------------------------------------------------------------|
| id | GTM-XXXXXX | undefined | Define the Google Tag Manager ID id. You can create an account to get an ID here : https://tagmanager.google.com/?hl=fr#/home |
| options | object | undefined | Provider options |
| Option | Type | Default | Description |
|---------------|--------|-----------------------------------------|-------------------------|
| scriptUrl | string | https://www.googletagmanager.com/gtm.js | Set script url to load |
| dataLayerName | string | dataLayer | Set the data layer name |
| Export | type | Description |
|-----------|----------|----------------|
| sendEvent | function | Send GTM event |
| id | string | The GTM id |