Skip to content

Getting Started

GitHub
Terminal window
bun add @capgo/capacitor-gtm
bunx cap sync
import { GoogleTagManager } from '@capgo/capacitor-gtm';

Initializes Google Tag Manager with the specified container ID.

import { GoogleTagManager } from '@capgo/capacitor-gtm';
await GoogleTagManager.initialize({} as { containerId: string; timeout?: number });

Pushes an event to the Google Tag Manager dataLayer.

import { GoogleTagManager } from '@capgo/capacitor-gtm';
await GoogleTagManager.push({
event: 'purchase',
parameters: {
value: 99.99,
currency: 'USD'
}
});

Sets a user property in the Google Tag Manager dataLayer.

import { GoogleTagManager } from '@capgo/capacitor-gtm';
await GoogleTagManager.setUserProperty({
key: 'user_type',
value: 'premium'
});

Gets a value from the Google Tag Manager dataLayer. Searches through the dataLayer for the most recent value of the specified key.

import { GoogleTagManager } from '@capgo/capacitor-gtm';
await GoogleTagManager.getValue({} as { key: string });

Resets the Google Tag Manager instance and clears all data. This will remove all data from the dataLayer and require re-initialization.

import { GoogleTagManager } from '@capgo/capacitor-gtm';
await GoogleTagManager.reset();

This page is generated from the plugin’s src/definitions.ts. Re-run the sync when the public API changes upstream.

If you are using Getting Started to plan dashboard and API operations, connect it with Using @capgo/capacitor-gtm for the native capability in Using @capgo/capacitor-gtm, API Overview for the implementation detail in API Overview, Introduction for the implementation detail in Introduction, API Keys for the implementation detail in API Keys, and Devices for the implementation detail in Devices.