Memulai
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/id/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.
Instalasi
Section titled “Instalasi”npm install @capgo/capacitor-gtmnpx cap syncyarn add @capgo/capacitor-gtmnpx cap syncpnpm add @capgo/capacitor-gtmnpx cap syncbun add @capgo/capacitor-gtmnpx cap syncKonfigurasi Platform
Section titled “Konfigurasi Platform”- Unduh file konfigurasi container GTM Anda dari konsol Google Tag Manager
- Tambahkan file JSON container ke proyek iOS Anda di Xcode
- File tersebut harus diberi nama seperti
GTM-XXXXXX.json
Android
Section titled “Android”- Unduh file konfigurasi container GTM Anda dari konsol Google Tag Manager
- Tambahkan file JSON container ke
android/app/src/main/assets/ - File tersebut harus diberi nama seperti
GTM-XXXXXX.json
Contoh Penggunaan
Section titled “Contoh Penggunaan”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);Referensi API
Section titled “Referensi API”init(options)
Section titled “init(options)”init(options: { containerId: string }) => Promise<void>Inisialisasi Google Tag Manager dengan ID container Anda.
| Param | Type |
|---|---|
options | { containerId: string } |
pushEvent(options)
Section titled “pushEvent(options)”pushEvent(options: GTMEvent) => Promise<void>Kirim event ke dataLayer dengan parameter opsional.
| Param | Type |
|---|---|
options | GTMEvent |
setUserProperty(options)
Section titled “setUserProperty(options)”setUserProperty(options: { key: string; value: string }) => Promise<void>Tetapkan properti pengguna untuk segmentasi dan penargetan.
| Param | Type |
|---|---|
options | { key: string; value: string } |
getVariable(options)
Section titled “getVariable(options)”getVariable(options: { key: string }) => Promise<{ value: any }>Dapatkan nilai dari konfigurasi container GTM.
| Param | Type |
|---|---|
options | { key: string } |
Returns: Promise<{ value: any }>
Interface
Section titled “Interface”GTMEvent
Section titled “GTMEvent”| Prop | Type | Description |
|---|---|---|
event | string | Nama event |
parameters | Record<string, any> | Parameter event opsional (opsional) |
Contoh Event Umum
Section titled “Contoh Event Umum”Tampilan Layar
Section titled “Tampilan Layar”await CapacitorGTM.pushEvent({ event: 'screen_view', parameters: { screen_name: 'Product Details', screen_class: 'ProductScreen' }});Aksi Pengguna
Section titled “Aksi Pengguna”await CapacitorGTM.pushEvent({ event: 'button_click', parameters: { button_name: 'add_to_cart', product_id: 'SKU_12345' }});Event E-commerce
Section titled “Event 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 } ] }});Praktik Terbaik
Section titled “Praktik Terbaik”- Inisialisasi GTM lebih awal dalam lifecycle aplikasi Anda
- Gunakan konvensi penamaan event yang konsisten
- Sertakan parameter yang relevan dengan setiap event
- Test konfigurasi GTM Anda dalam mode preview
- Monitor data di konsol Google Tag Manager
- Gunakan properti pengguna untuk segmentasi yang bermakna
Debugging
Section titled “Debugging”Aktifkan mode debug di konsol Google Tag Manager untuk menguji implementasi Anda:
- Buka konsol GTM
- Masuk ke mode Preview
- Hubungkan ke aplikasi Anda menggunakan ID container
- Verifikasi bahwa event dilacak dengan benar
Kasus Penggunaan
Section titled “Kasus Penggunaan”- Lacak interaksi dan perilaku pengguna
- Monitor metrik performa aplikasi
- Kumpulkan data e-commerce
- Kelola tag pihak ketiga tanpa perubahan kode
- Implementasikan pengujian A/B dan personalisasi
- Integrasikan dengan Google Analytics dan layanan lainnya