Getting Started
このプラグインのインストール手順とマークダウンガイドの全てを含む設定プロンプトをコピーする。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-notifications`
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/docs/plugins/notifications/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.
@capgo/capacitor-notifications Capgoは、ネイティブiOSおよびAndroidプッシュ通知の第一パーティーCapgoプラグインです。APIのダッシュボード、パブリックAPI、Analytics Engineデバイスレジストリ、キャンペーン統計、バッジ更新、サイレントライブアップデートチェックのために構築されています。
要件
要件- CapacitorアプリがCapgoに追加されていること。
- Capgoアプリの通知タブへのアクセス。
- CapgoアプリのAPIキーがバックエンドの証明印刷とAPI送信のために書き込みアクセス権を持っていること。
- iOSおよび/またはAndroidプラットフォームのプッシュ権限がアプリに設定されていること。
@capgo/capacitor-updatersilent push update checks が必要な場合
1. Capgo Platform Credentials を設定
セクション “1. Capgo Platform Credentials”Capgo でアプリを開き、次に 通知.
各プラットフォームをサポートするために、1 つのプラットフォーム認証情報エントリを追加します:
- Android - アプリパッケージIDとAndroidプッシュプロジェクトメタデータ
- iOS - バンドルID、チームID、キーアイディー、iOSプッシュキーのメタデータに一致するもの
Capgo は、プラットフォームが設定済みとマークされる前に、API ワーカー内に存在する必要がある環境シークレット名を示します。ダッシュボードはメタデータと期待されるシークレット参照を保存します。ワーカー環境内にプライベート認証情報が残ります。
2. インストール
2. インストール最速のセットアップのために、Capgo CLI をアプリプロジェクトから実行してください。
npx @capgo/cli@latest notifications setup com.example.appCapacitor パッケージをインストールし、Capacitor プラグインの設定を保存し、小さなヘルパーファイルを作成し、Capacitor 同期を実行します。このパスを新しいアプリで使用する場合は、ファイルを手動で接続する必要がある場合を除きます。
手動インストール:
npm install @capgo/capacitor-notifications @capgo/capacitor-updaternpx cap syncCapgo シャットダウンチェックを使用していない場合、Capgo を省略できます。 @capgo/capacitor-updater.
3. プラグインの設定
3. プラグインの設定アプリが起動したときに一度だけプラグインを設定してください。
import { CapgoNotifications } from '@capgo/capacitor-notifications'
await CapgoNotifications.configure({ appId: 'com.example.app', autoUpdater: true, updateInstallMode: 'next',})使用 updateInstallMode: 'next' 更新をダウンロードして、次の再起動またはバックグラウンドサイクルでインストールします。使用するには、__CAPGO_KEEP_0__ をすぐにインストールできるようにアップデーターが安全にできる時点でインストールすることを望む場合のみです。 updateInstallMode: 'set' only when you want Capgo to install the update as soon as the updater can safely do it.
セクション「4. ID証明書を発行する」
__CAPGO_KEEP_0__ __CAPGO_KEEP_1__ キーをモバイルアプリに置かないでください。バックエンドは、ユーザー認証が成功したあとに__CAPGO_KEEP_2__ からID証明書を取得するように求めます。Do not put your Capgo API key in the mobile app. Your backend should ask Capgo for an identityProof クリップボードにコピー
curl -X POST 'https://api.capgo.app/notifications/recipients/proof' \ -H 'Content-Type: application/json' \ -H 'x-api-key: CAPGO_API_KEY' \ -d '{ "appId": "com.example.app", "externalId": "customer-user-123" }'__CAPGO_KEEP_1__ identityProof __CAPGO_KEEP_2__
5. デバイスの登録
セクション: 5. デバイスの登録利用者がサインインしているカスタマーユーザーを知るまでに、登録しないでください。
const registration = await CapgoNotifications.register({ externalId: 'customer-user-123', identityProof, tags: ['paid', 'beta'], attributes: { plan: 'team', locale: 'en-US', }, consent: true,})
console.log(registration.recipientKey, registration.deviceKey)呼び出し register コンテキスト: Appflowの比較/移行のマーケティングコピー (親キー `appflow_migration_step2`). ページ/エリア: Appflowの比較/移行のマーケティングコピー。ロール: ウェブサイトのコピー文。ページ: ionic-appflow.astro。保管: Capgo製品/ブランドと開発者用語を完全に保存。
- 再度呼び出す場合:
- アプリが起動します。
- ネイティブプッシュトークンが変更されます。
- サインインしているユーザーが変更されます。
- タグ、属性、または同意が変更されます。
アプリが長い間登録の更新を実行していない場合。
6. イベントリスナを追加するアプリ起動時にリスナを登録して、JavaScriptでフォアグラウンド、オープン、バックグラウンドイベントを表示します。
await CapgoNotifications.addListener('registrationChanged', () => { void CapgoNotifications.register({ externalId: currentUser.id, identityProof: currentUser.capgoNotificationProof, tags: currentUser.notificationTags, consent: currentUser.pushConsent, })})
await CapgoNotifications.addListener('notificationReceived', (notification) => { console.log('Notification received', notification)})
await CapgoNotifications.addListener('notificationOpened', (event) => { console.log('Notification opened', event.notification.id)})
await CapgoNotifications.addListener('backgroundNotification', async (event) => { try { console.log('Background notification', event.notification.data) } finally { await event.finish() }})常にバックグラウンド通知の後に作業を実行してください。作業は短く、idempotentでなければなりません。 finish() 7. iOS設定
7. iOS設定
Xcodeでアプリのターゲットを開いて、次の設定を有効にします:プッシュ通知
- バックグラウンドモード > Remote notifications
- リモート通知を
コピー ios/App/App/AppDelegate.swift:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { NotificationCenter.default.post(name: Notification.Name("CapgoNotificationsRemoteNotification"), object: userInfo) completionHandler(.newData)}次に、以下のコマンドを実行してください。
npx cap sync ios物理的なiOSデバイスを使用してバックグラウンド通知をテストすることをお勧めします。シミュレータはUI作業に便利ですが、実際のバックグラウンドプッシュの動作を表すものではありません。
8. Androidの設定
8. Androidの設定次に、以下のコマンドを実行してください。
npx cap sync android次に、以下を確認してください。
- Androidプラットフォームの資格情報は、Capgoに設定されています。
- アプリのパッケージIDは、プラットフォームプッシュの設定で使用されているパッケージIDと一致しています。
- Android 13以上の通知許可は、可視化された通知を期待する前に要求されます。
- アプリは、ブランドに合った通知アイコンとチャンネル戦略を持ちます。
- 実機またはエミュレータでGoogle Playサービスを搭載したデバイスでテストします。
アプリが起動したときにデフォルトのAndroidチャンネルを作成します:
await CapgoNotifications.configure({ appId: 'com.example.app' })
await CapgoNotifications.register({ externalId: currentUser.id, identityProof: currentUser.capgoNotificationProof, consent: true,})プラグインはAndroidプッシュメッセージングサービスを宣言します。ホストアプリでアプリバックアップ、データ抽出、ネットワークセキュリティ、通知アイコンポリシーを管理してください。
9. テスト通知を送信します
セクション:9. テスト通知を送信します使用 通知>テスト送信 Capgo内で、またはバックエンドからAPIを公開して呼び出してください:
curl -X POST 'https://api.capgo.app/notifications/send' \ -H 'Content-Type: application/json' \ -H 'x-api-key: CAPGO_API_KEY' \ -d '{ "appId": "com.example.app", "target": { "externalId": "customer-user-123" }, "payload": { "title": "Hello from Capgo", "body": "This is a test notification.", "data": { "screen": "inbox" } } }'キャンペーンを作成するには、ダッシュボードで作成するか、呼び出す /notifications/campaigns、外部ID、タグ、セグメント、またはブロードキャストアウディエンスに送信します。
10. 付箋を設定
「10. 付箋を設定」のセクションawait CapgoNotifications.setBadge(4)await CapgoNotifications.incrementBadge()await CapgoNotifications.clearBadge()バックエンドから:
curl -X POST 'https://api.capgo.app/notifications/badge' \ -H 'Content-Type: application/json' \ -H 'x-api-key: CAPGO_API_KEY' \ -d '{ "appId": "com.example.app", "target": { "externalId": "customer-user-123" }, "badge": 4 }'11. 静音の更新チェックを有効にする
「11. 静音の更新チェックを有効にする」のセクション静音の更新チェックは、このプラグインを @capgo/capacitor-updater.
アプリ内で:
await CapgoNotifications.enableUpdaterIntegration({ enabled: true, installMode: 'next',})Capgoで ユーザーにプッシュアップデートを送信 APIからダッシュボードまたはターミナルウィンドウでアップデートチェックを実行
curl -X POST 'https://api.capgo.app/notifications/update-check' \ -H 'Content-Type: application/json' \ -H 'x-api-key: CAPGO_API_KEY' \ -d '{ "appId": "com.example.app", "target": { "externalId": "customer-user-123" }, "installMode": "next" }'通知は静音で、コラプスIDを使用して繰り返しアップデートチェックを置き換えるため、プラットフォームがコラプス動作をサポートしている場合にのみ機能します。
検証チェックリスト
「検証チェックリスト」のセクション- Capgoの受信者検索で、予想どおりのアプリが表示されます。
externalId. - 許可が得られている
grantedまたはユーザーが通知の許可を承知している場合。 - 登録されたプラットフォームは
androidまたはios. registrationChangedCapacitorライブアップデートの代替オプションの比較ページ。- Appflowの比較/移行のマーケティングコピー。
notificationReceived. - Capawesomeの比較ページ。
notificationOpened. - コンサルティングサービスページ。
- Appflowの比較/移行のマーケティングコピー。
runUpdateCheckAppflowプラグインまたは
トークン更新後、発生します。
フロントエンドのテストログ通知を開くログ デバッグ codeを変更する前に