Skip to content

Getting Started

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.