Comenzar
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/es/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.
Instalación
Section titled “Instalación”npm install @capgo/capacitor-gtmnpx cap syncyarn add @capgo/capacitor-gtmnpx cap syncpnpm add @capgo/capacitor-gtmnpx cap syncbun add @capgo/capacitor-gtmnpx cap syncConfiguración de Plataforma
Section titled “Configuración de Plataforma”- Descarga tu archivo de configuración del contenedor GTM desde la consola de Google Tag Manager
- Agrega el archivo JSON del contenedor a tu proyecto iOS en Xcode
- El archivo debe llamarse algo como
GTM-XXXXXX.json
Android
Section titled “Android”- Descarga tu archivo de configuración del contenedor GTM desde la consola de Google Tag Manager
- Agrega el archivo JSON del contenedor a
android/app/src/main/assets/ - El archivo debe llamarse algo como
GTM-XXXXXX.json
Ejemplo de Uso
Section titled “Ejemplo de Uso”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);Referencia de API
Section titled “Referencia de API”init(Opciones)
Section titled “init(Opciones)”init(options: { containerId: string }) => Promise<void>Inicializa Google Tag Manager con tu ID de contenedor.
| Param | Type |
|---|---|
options | { containerId: string } |
pushEvent(Opciones)
Section titled “pushEvent(Opciones)”pushEvent(options: GTMEvent) => Promise<void>Envía un evento al dataLayer con parámetros opcionales.
| Param | Type |
|---|---|
options | GTMEvent |
setUserProperty(Opciones)
Section titled “setUserProperty(Opciones)”setUserProperty(options: { key: string; value: string }) => Promise<void>Establece una propiedad de usuario para segmentación y targeting.
| Param | Type |
|---|---|
options | { key: string; value: string } |
getVariable(Opciones)
Section titled “getVariable(Opciones)”getVariable(options: { key: string }) => Promise<{ value: any }>Obtiene un valor de la configuración del contenedor GTM.
| Param | Type |
|---|---|
options | { key: string } |
Retorna: Promise<{ value: any }>
Interfaces
Section titled “Interfaces”GTMEvent
Section titled “GTMEvent”| Prop | Type | Description |
|---|---|---|
event | string | El nombre del evento |
parameters | Record<string, any> | Parámetros opcionales del evento (opcional) |
Ejemplos de Eventos Comunes
Section titled “Ejemplos de Eventos Comunes”Vistas de Pantalla
Section titled “Vistas de Pantalla”await CapacitorGTM.pushEvent({ event: 'screen_view', parameters: { screen_name: 'Product Details', screen_class: 'ProductScreen' }});Acciones de Usuario
Section titled “Acciones de Usuario”await CapacitorGTM.pushEvent({ event: 'button_click', parameters: { button_name: 'add_to_cart', product_id: 'SKU_12345' }});Eventos de E-commerce
Section titled “Eventos de E-commerce”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 } ] }});Mejores Prácticas
Section titled “Mejores Prácticas”- Inicializa GTM temprano en el ciclo de vida de tu aplicación
- Usa convenciones de nombres de eventos consistentes
- Incluye parámetros relevantes con cada evento
- Prueba tu configuración de GTM en modo de vista previa
- Monitorea los datos en la consola de Google Tag Manager
- Usa propiedades de usuario para segmentación significativa
Depuración
Section titled “Depuración”Habilita el modo de depuración en la consola de Google Tag Manager para probar tu implementación:
- Abre la consola de GTM
- Ve al modo de Vista Previa
- Conéctate a tu aplicación usando el ID del contenedor
- Verifica que los eventos se estén rastreando correctamente
Casos de Uso
Section titled “Casos de Uso”- Rastrear interacciones y comportamiento del usuario
- Monitorear métricas de rendimiento de la aplicación
- Recopilar datos de e-commerce
- Gestionar etiquetas de terceros sin cambios de código
- Implementar pruebas A/B y personalización
- Integrar con Google Analytics y otros servicios