Erste Schritte
Copy a setup prompt with the install steps and the full markdown guide for this plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-gtm`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/de/docs/plugins/gtm/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Installation
Section titled “Installation”npm install @capgo/capacitor-gtmnpx cap syncyarn add @capgo/capacitor-gtmnpx cap syncpnpm add @capgo/capacitor-gtmnpx cap syncbun add @capgo/capacitor-gtmnpx cap syncPlattformkonfiguration
Section titled “Plattformkonfiguration”- Laden Sie Ihre GTM-Container-Konfigurationsdatei von der Google Tag Manager-Konsole herunter
- Fügen Sie die Container-JSON-Datei zu Ihrem iOS-Projekt in Xcode hinzu
- Die Datei sollte etwa
GTM-XXXXXX.jsonheißen
Android
Section titled “Android”- Laden Sie Ihre GTM-Container-Konfigurationsdatei von der Google Tag Manager-Konsole herunter
- Fügen Sie die Container-JSON-Datei zu
android/app/src/main/assets/hinzu - Die Datei sollte etwa
GTM-XXXXXX.jsonheißen
Verwendungsbeispiel
Section titled “Verwendungsbeispiel”import { CapacitorGTM } from '@capgo/capacitor-gtm';
// GTM mit Ihrer Container-ID initialisierenawait CapacitorGTM.init({ containerId: 'GTM-XXXXXX'});
// Ereignisse an dataLayer sendenawait CapacitorGTM.pushEvent({ event: 'screen_view', parameters: { screen_name: 'Home', screen_class: 'HomeScreen' }});
// Benutzerdefinierte Ereignisse mit Parametern sendenawait CapacitorGTM.pushEvent({ event: 'purchase', parameters: { transaction_id: 'T12345', value: 25.00, currency: 'USD', items: [ { item_id: 'SKU_12345', item_name: 'Produktname', quantity: 1, price: 25.00 } ] }});
// Benutzereigenschaften festlegenawait CapacitorGTM.setUserProperty({ key: 'user_type', value: 'premium'});
// Werte aus dataLayer abrufenconst result = await CapacitorGTM.getVariable({ key: 'config_value'});console.log('Konfigurationswert:', result.value);API-Referenz
Section titled “API-Referenz”init(options)
Section titled “init(options)”init(options: { containerId: string }) => Promise<void>Initialisiert Google Tag Manager mit Ihrer Container-ID.
| Param | Typ |
|---|---|
options | { containerId: string } |
pushEvent(options)
Section titled “pushEvent(options)”pushEvent(options: GTMEvent) => Promise<void>Sendet ein Ereignis mit optionalen Parametern an den dataLayer.
| Param | Typ |
|---|---|
options | GTMEvent |
setUserProperty(options)
Section titled “setUserProperty(options)”setUserProperty(options: { key: string; value: string }) => Promise<void>Legt eine Benutzereigenschaft für Segmentierung und Targeting fest.
| Param | Typ |
|---|---|
options | { key: string; value: string } |
getVariable(options)
Section titled “getVariable(options)”getVariable(options: { key: string }) => Promise<{ value: any }>Ruft einen Wert aus der GTM-Container-Konfiguration ab.
| Param | Typ |
|---|---|
options | { key: string } |
Gibt zurück: Promise<{ value: any }>
Schnittstellen
Section titled “Schnittstellen”GTMEvent
Section titled “GTMEvent”| Prop | Typ | Beschreibung |
|---|---|---|
event | string | Der Ereignisname |
parameters | Record<string, any> | Optionale Ereignisparameter (optional) |
Häufige Ereignisbeispiele
Section titled “Häufige Ereignisbeispiele”Bildschirmansichten
Section titled “Bildschirmansichten”await CapacitorGTM.pushEvent({ event: 'screen_view', parameters: { screen_name: 'Produktdetails', screen_class: 'ProductScreen' }});Benutzeraktionen
Section titled “Benutzeraktionen”await CapacitorGTM.pushEvent({ event: 'button_click', parameters: { button_name: 'add_to_cart', product_id: 'SKU_12345' }});E-Commerce-Ereignisse
Section titled “E-Commerce-Ereignisse”await CapacitorGTM.pushEvent({ event: 'begin_checkout', parameters: { currency: 'USD', value: 75.00, items: [ { item_id: 'SKU_12345', item_name: 'Produkt 1', quantity: 2, price: 25.00 }, { item_id: 'SKU_67890', item_name: 'Produkt 2', quantity: 1, price: 25.00 } ] }});Bewährte Methoden
Section titled “Bewährte Methoden”- Initialisieren Sie GTM früh im Lebenszyklus Ihrer App
- Verwenden Sie konsistente Ereignisbenennungskonventionen
- Fügen Sie relevante Parameter zu jedem Ereignis hinzu
- Testen Sie Ihre GTM-Konfiguration im Vorschaumodus
- Überwachen Sie Daten in der Google Tag Manager-Konsole
- Verwenden Sie Benutzereigenschaften für sinnvolle Segmentierung
Debugging
Section titled “Debugging”Aktivieren Sie den Debug-Modus in der Google Tag Manager-Konsole, um Ihre Implementierung zu testen:
- Öffnen Sie die GTM-Konsole
- Gehen Sie in den Vorschaumodus
- Verbinden Sie sich mit Ihrer App über die Container-ID
- Überprüfen Sie, ob Ereignisse korrekt verfolgt werden
Anwendungsfälle
Section titled “Anwendungsfälle”- Benutzerinteraktionen und -verhalten verfolgen
- App-Leistungsmetriken überwachen
- E-Commerce-Daten sammeln
- Drittanbieter-Tags ohne Codeänderungen verwalten
- A/B-Tests und Personalisierung implementieren
- Mit Google Analytics und anderen Diensten integrieren