Commencer
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 syncPlatform Configuration
Section titled “Platform Configuration”- Télécharger your GTM container Configuration file from Google Tag Manager console
- Ajouter the container JSON file to your iOS project in Xcode
- The file should be named something like
GTM-XXXXXX.json
Android
Section titled “Android”- Télécharger your GTM container Configuration file from Google Tag Manager console
- Add the container JSON file to
android/app/src/main/assets/ - The file should be named something like
GTM-XXXXXX.json
Utilisation Exemple
Section titled “Utilisation Exemple”import { CapacitorGTM } from '@capgo/capacitor-gtm';
// Initialize GTM with your container IDawait CapacitorGTM.init({ containerId: 'GTM-XXXXXX'});
// Push events to dataLayerawait CapacitorGTM.pushEvent({ event: 'screen_view', parameters: { screen_name: 'Home', screen_class: 'HomeScreen' }});
// Push custom events with parametersawait CapacitorGTM.pushEvent({ event: 'purchase', parameters: { transaction_id: 'T12345', value: 25.00, currency: 'USD', items: [ { item_id: 'SKU_12345', item_name: 'Product Name', quantity: 1, price: 25.00 } ] }});
// Set user propertiesawait CapacitorGTM.setUserProperty({ key: 'user_type', value: 'premium'});
// Get values from dataLayerconst result = await CapacitorGTM.getVariable({ key: 'config_value'});console.log('Config value:', result.value);API Référence
Section titled “API Référence”init(Options)
Section titled “init(Options)”init(options: { containerId: string }) => Promise<void>Initialiser Google Tag Manager with your container ID.
| Param | Type |
|---|---|
options | { containerId: string } |
pushEvent(Options)
Section titled “pushEvent(Options)”pushEvent(options: GTMEvent) => Promise<void>Pousser an event to the dataLayer with optional Paramètres.
| Param | Type |
|---|---|
options | GTMEvent |
setUserProperty(Options)
Section titled “setUserProperty(Options)”setUserProperty(options: { key: string; value: string }) => Promise<void>Set a Utilisateur property for segmentation and targeting.
| Param | Type |
|---|---|
options | { key: string; value: string } |
getVariable(Options)
Section titled “getVariable(Options)”getVariable(options: { key: string }) => Promise<{ value: any }>Get a value from the GTM container Configuration.
| Param | Type |
|---|---|
options | { key: string } |
Returns: Promise<{ value: any }>
Interfaces
Section titled “Interfaces”GTMEvent
Section titled “GTMEvent”| Prop | Type | Description |
|---|---|---|
event | string | The event name |
parameters | Record<string, any> | Optional event parameters (optional) |
Common Event Exemples
Section titled “Common Event Exemples”Screen Views
Section titled “Screen Views”await CapacitorGTM.pushEvent({ event: 'screen_view', parameters: { screen_name: 'Product Details', screen_class: 'ProductScreen' }});Utilisateur Actions
Section titled “Utilisateur Actions”await CapacitorGTM.pushEvent({ event: 'button_click', parameters: { button_name: 'add_to_cart', product_id: 'SKU_12345' }});E-commerce Events
Section titled “E-commerce Events”await CapacitorGTM.pushEvent({ event: 'begin_checkout', parameters: { currency: 'USD', value: 75.00, items: [ { item_id: 'SKU_12345', item_name: 'Product 1', quantity: 2, price: 25.00 }, { item_id: 'SKU_67890', item_name: 'Product 2', quantity: 1, price: 25.00 } ] }});Best Practices
Section titled “Best Practices”- Initialiser GTM early in your Application lifecycle
- Use consistent event naming conventions
- Include relevant Paramètres with each event
- Test your GTM Configuration in preview mode
- Monitor data in Google Tag Manager console
- Use Utilisateur properties for meaningful segmentation
Débogage
Section titled “Débogage”Activer Débogage mode in Google Tag Manager console to Test your implementation:
- Open GTM console
- Go to Preview mode
- Connect to your Application using the container ID
- Verify events are being tracked correctly
Use Cases
Section titled “Use Cases”- Track Utilisateur interactions and behavior
- Monitor Application performance metrics
- Collect e-commerce data
- Manage third-party tags without code changes
- Implement A/B Test and personalization
- Integrate with Google Analyse and other services