メインコンテンツへスキップ

スタートガイド

GitHub

AIアシストによるセットアップでプラグインをインストールできます。以下のコマンドを使用して、お使いのAIツールに Capgo のスキルを追加してください:

ターミナル
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

次に、以下のプロンプトを使用します:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-rudderstack` plugin in my project.

手動セットアップを希望する場合は、以下のコマンドを実行してプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:

ターミナル
bun add @capgo/capacitor-rudderstack
bunx cap sync
import { nativePlugin } from '@capgo/capacitor-rudderstack';
import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.initialize({
writeKey: 'YOUR_WRITE_KEY',
dataPlaneUrl: 'https://your.dataplane.rudderstack.com',
});
await nativePlugin.identify({ userId: 'user_123', traits: { plan: 'pro' } });
await nativePlugin.track({ event: 'Signed Up', properties: { source: 'mobile' } });
await nativePlugin.screen({
screen: 'Checkout',
properties: { step: 'payment' },
});
  • 一度だけ初期化:重複の可能性 initialize() 呼び出しによって SDK の状態が重複する可能性があるため、アプリのブートストラップ時に制御してください。
  • バックグラウンド移行前にフラッシュ:呼び出し flush() iOSやAndroidでは、アップロード中にプロセスが中断される可能性があるためです。
  • 広告用ID:プライバシーポリシーでIDFAまたはGAIDの収集について明記している場合にのみ、オプトインのヘルパーを使用してください。

RudderStackクライアントを初期化します。

このメソッドはCordovaのシグネチャを維持しているため、第2引数にはconfigオブジェクトまたはRudderのoptionsオブジェクトのどちらかを渡すことができます。

import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.initialize('write-key-123');

指定したユーザーIDでidentifyコールを送信します。

import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.identify('user-id-123');

指定したグループIDでgroupコールを送信します。

import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.group('group-id-123');

指定したイベント名でtrackコールを送信します。

import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.track('event');

指定したスクリーン名でscreenコールを送信します。

import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.screen('screen');

現在のユーザーを新しい識別子にエイリアスします。

import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.alias('new-id-123');

現在のRudderStackのアイデンティティ状態をリセットします。

import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.reset();

キューに溜まっているイベントを即座にフラッシュします。

import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.flush();

RudderStackがサポートされている送信先に転送するプッシュトークンを設定します。

import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.putDeviceToken('device-token-123');

現在のコントラクトのソース定義を参照してください。

import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.setAdvertisingId('advertising-id-123');

カスタムの広告ID値を設定します。

import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.putAdvertisingId('advertising-id-123');

現在のコントラクトのソース定義を参照してください。

import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.setAnonymousId('anonymous-id-123');

カスタムの匿名IDを設定します。

import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.putAnonymousId('anonymous-id-123');

RudderStackのトラッキングオプトアウトを切り替えます。

import { nativePlugin } from '@capgo/capacitor-rudderstack';
await nativePlugin.optOut(true);

基盤となるRudderStack native SDKでサポートされている設定キーです。

export interface RudderConfiguration {
/**
* RudderStack data plane URL.
*/
dataPlaneUrl?: string;
/**
* Number of events to batch before a flush.
*/
flushQueueSize?: number;
/**
* Database row threshold that triggers pruning on Android and iOS.
*/
dbCountThreshold?: number;
/**
* Server config refresh interval in hours.
*/
configRefreshInterval?: number;
/**
* RudderStack log verbosity.
*/
logLevel?: RudderLogLevelValue;
/**
* Sleep timeout / sleep count used by the native SDK.
*/
sleepTimeOut?: number;
/**
* Android only. Lets the native SDK collect the advertising identifier automatically.
*/
autoCollectAdvertId?: boolean;
/**
* Tracks `Application Installed`, `Application Updated`, and `Application Opened` automatically.
*/
trackLifecycleEvents?: boolean;
/**
* RudderStack control plane URL.
*/
controlPlaneUrl?: string;
/**
* Enables automatic screen tracking where supported by the native SDK.
*/
recordScreenViews?: boolean;
/**
* Ignored in this Capacitor port.
*
* The Cordova SDK uses this field to bootstrap native destination factories from companion plugins.
* Those extension packages are not implemented in this first Capacitor release.
*/
factories?: any[];
}

RudderStackの呼び出しごとのオプションです。

export interface RudderOptions {
/**
* External identifiers forwarded with the event.
*/
externalIds?: Record<string, string>;
/**
* Destination enablement flags keyed by integration name.
*/
integrations?: Record<string, boolean>;
}

受け入れられるTraitsペイロード: identify と group.

export type RudderTraits = Record<string, any>;

受け入れられるPropertiesペイロード: track と screen.

export type RudderProperties = Record<string, any>;

プラグインバージョンのペイロード。

export interface PluginVersionResult {
/**
* Version identifier returned by the platform implementation.
*/
version: string;
}

移行をスムーズにするために公開されている、RudderStackのログレベル値です。

export type RudderLogLevelValue = 0 | 1 | 2 | 3 | 4 | 5;

このページはプラグインの src/definitions.tsから生成されています。upstream で公開 API が変更されたら、再度 sync を実行してください。

Getting Startedの続きを進める

「Getting Started からの続き」セクション

使用している場合 スタートガイド ダッシュボードと API の運用を計画するには、これを次と連携させます @capgo/capacitor-rudderstack の使用 @capgo/capacitor-rudderstack を使用して Native Build の機能を利用する場合、 API の概要 「API の概要」の実装の詳細については、 はじめに 「はじめに」における実装の詳細については、 API キー および「API Keys」の実装の詳細については、 デバイス 実装の詳細については Devices を参照してください。