始め方
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/ja/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.
インストール
Section titled “インストール”npm install @capgo/capacitor-gtmnpx cap syncyarn add @capgo/capacitor-gtmnpx cap syncpnpm add @capgo/capacitor-gtmnpx cap syncbun add @capgo/capacitor-gtmnpx cap syncプラットフォーム設定
Section titled “プラットフォーム設定”- Google Tag Managerコンソールからコンテナ設定ファイルをダウンロード
- XcodeでiOSプロジェクトにコンテナJSONファイルを追加
- ファイル名は
GTM-XXXXXX.jsonのようになります
Android
Section titled “Android”- Google Tag Managerコンソールからコンテナ設定ファイルをダウンロード
android/app/src/main/assets/にコンテナJSONファイルを追加- ファイル名は
GTM-XXXXXX.jsonのようになります
import { CapacitorGTM } from '@capgo/capacitor-gtm';
// コンテナIDでGTMを初期化await CapacitorGTM.init({ containerId: 'GTM-XXXXXX'});
// dataLayerにイベントをプッシュawait CapacitorGTM.pushEvent({ event: 'screen_view', parameters: { screen_name: 'Home', screen_class: 'HomeScreen' }});
// パラメータを持つカスタムイベントをプッシュawait 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 } ] }});
// ユーザープロパティを設定await CapacitorGTM.setUserProperty({ key: 'user_type', value: 'premium'});
// dataLayerから値を取得const result = await CapacitorGTM.getVariable({ key: 'config_value'});console.log('Config value:', result.value);APIリファレンス
Section titled “APIリファレンス”init(options)
Section titled “init(options)”init(options: { containerId: string }) => Promise<void>コンテナIDでGoogle Tag Managerを初期化します。
| パラメータ | 型 |
|---|---|
options | { containerId: string } |
pushEvent(options)
Section titled “pushEvent(options)”pushEvent(options: GTMEvent) => Promise<void>オプションのパラメータを持つイベントをdataLayerにプッシュします。
| パラメータ | 型 |
|---|---|
options | GTMEvent |
setUserProperty(options)
Section titled “setUserProperty(options)”setUserProperty(options: { key: string; value: string }) => Promise<void>セグメンテーションとターゲティングのためのユーザープロパティを設定します。
| パラメータ | 型 |
|---|---|
options | { key: string; value: string } |
getVariable(options)
Section titled “getVariable(options)”getVariable(options: { key: string }) => Promise<{ value: any }>GTMコンテナ設定から値を取得します。
| パラメータ | 型 |
|---|---|
options | { key: string } |
戻り値: Promise<{ value: any }>
インターフェース
Section titled “インターフェース”GTMEvent
Section titled “GTMEvent”| プロパティ | 型 | 説明 |
|---|---|---|
event | string | イベント名 |
parameters | Record<string, any> | オプションのイベントパラメータ (任意) |
一般的なイベントの例
Section titled “一般的なイベントの例”await CapacitorGTM.pushEvent({ event: 'screen_view', parameters: { screen_name: 'Product Details', screen_class: 'ProductScreen' }});ユーザーアクション
Section titled “ユーザーアクション”await CapacitorGTM.pushEvent({ event: 'button_click', parameters: { button_name: 'add_to_cart', product_id: 'SKU_12345' }});Eコマースイベント
Section titled “Eコマースイベント”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 } ] }});ベストプラクティス
Section titled “ベストプラクティス”- アプリのライフサイクルの早い段階でGTMを初期化する
- 一貫したイベント命名規則を使用する
- 各イベントに関連するパラメータを含める
- プレビューモードでGTM設定をテストする
- Google Tag Managerコンソールでデータを監視する
- 意味のあるセグメンテーションにユーザープロパティを使用する
実装をテストするために、Google Tag Managerコンソールでデバッグモードを有効にします:
- GTMコンソールを開く
- プレビューモードに移動
- コンテナIDを使用してアプリに接続
- イベントが正しく追跡されていることを確認
ユースケース
Section titled “ユースケース”- ユーザーのインタラクションと行動を追跡
- アプリのパフォーマンスメトリクスを監視
- Eコマースデータを収集
- コード変更なしでサードパーティタグを管理
- A/Bテストとパーソナライゼーションを実装
- Google Analyticsや他のサービスと統合