はじめる
-
パッケージをインストールします
Terminal window npm i @capgo/capacitor-crispTerminal window pnpm add @capgo/capacitor-crispTerminal window yarn add @capgo/capacitor-crispTerminal window bun add @capgo/capacitor-crisp -
ネイティブ プロジェクトと同期
Terminal window npx cap syncTerminal window pnpm cap syncTerminal window yarn cap syncTerminal window bunx cap sync -
Crisp ウェブサイト ID を取得します
- crisp.chat に登録してください
- ウェブサイト/プロジェクトを作成する
- [設定] > [セットアップ手順] で Web サイト ID を見つけます。
基本的な使い方
Section titled “基本的な使い方”プラグインをインポートし、Web サイト ID を使用して設定します。
import { CapacitorCrisp } from '@capgo/capacitor-crisp';
// Configure Crisp with your website IDconst configureCrisp = async () => { await CapacitorCrisp.configure({ websiteID: 'YOUR_WEBSITE_ID' });};
// Open the chatconst openChat = async () => { await CapacitorCrisp.openMessenger();};
// Set user informationconst setUserInfo = async () => { await CapacitorCrisp.setUser({ email: 'user@example.com', nickname: 'John Doe', phone: '+1234567890', avatar: 'https://example.com/avatar.jpg' });};
// Reset user session (logout)const logout = async () => { await CapacitorCrisp.resetChatSession();};API リファレンス
Section titled “API リファレンス”設定(オプション)
Section titled “設定(オプション)”Web サイト ID とオプション設定を使用して Crisp を構成します。
interface ConfigureOptions { websiteID: string; locale?: string; // e.g., 'en', 'fr', 'es' tokenID?: string; // For authenticated sessions}
await CapacitorCrisp.configure({ websiteID: 'YOUR_WEBSITE_ID', locale: 'en'});openMessenger()
Section titled “openMessenger()”Crisp チャット インターフェイスを開きます。
await CapacitorCrisp.openMessenger();setUser(オプション)
Section titled “setUser(オプション)”チャットセッションのユーザー情報を設定します。
interface UserOptions { email?: string; nickname?: string; phone?: string; avatar?: string;}
await CapacitorCrisp.setUser({ email: 'user@example.com', nickname: 'John Doe'});setUserCompany(オプション)
Section titled “setUserCompany(オプション)”ビジネスユーザー向けに会社情報を設定します。
interface CompanyOptions { name: string; url?: string; description?: string; employment?: { title?: string; role?: string; }; geolocation?: { city?: string; country?: string; };}
await CapacitorCrisp.setUserCompany({ name: 'Acme Corp', url: 'https://acme.com', employment: { title: 'CEO', role: 'Leadership' }});プッシュイベント(オプション)
Section titled “プッシュイベント(オプション)”カスタム イベントを送信してユーザーのアクションを追跡します。
interface EventOptions { name: string; color?: 'red' | 'orange' | 'yellow' | 'green' | 'blue' | 'purple' | 'pink' | 'brown' | 'grey' | 'black'; data?: { [key: string]: any };}
await CapacitorCrisp.pushEvent({ name: 'checkout_completed', color: 'green', data: { price: 99.99, currency: 'USD' }});setSessionSegment(セグメント)
Section titled “setSessionSegment(セグメント)”チャットセッションを分類するセグメントを設定します。
await CapacitorCrisp.setSessionSegment('premium_customer');###resetChatSession()
現在のチャット セッションをリセットします (ログアウトに役立ちます)。
await CapacitorCrisp.resetChatSession();カスタム ユーザー データ
Section titled “カスタム ユーザー データ”// Set multiple custom data fieldsawait CapacitorCrisp.setSessionData({ key: 'plan', value: 'premium'});
await CapacitorCrisp.setSessionData({ key: 'signup_date', value: '2024-01-15'});メッセージプリセット
Section titled “メッセージプリセット”チャット入力に事前入力メッセージを設定します。
await CapacitorCrisp.setMessageText( "Hello, I need help with my order #12345");チャットの可用性
Section titled “チャットの可用性”チャット ウィジェットをいつ利用できるかを制御します。
// Hide chat temporarilyawait CapacitorCrisp.setTokenID('user_token_12345');import { CapacitorCrisp } from '@capgo/capacitor-crisp';
export class ChatService { async initialize() { // Configure Crisp await CapacitorCrisp.configure({ websiteID: 'YOUR_WEBSITE_ID', locale: 'en' }); }
async loginUser(user: any) { // Set user information await CapacitorCrisp.setUser({ email: user.email, nickname: user.name, phone: user.phone, avatar: user.avatarUrl });
// Set custom data await CapacitorCrisp.setSessionData({ key: 'user_id', value: user.id });
await CapacitorCrisp.setSessionData({ key: 'account_type', value: user.accountType });
// Set segment if (user.isPremium) { await CapacitorCrisp.setSessionSegment('premium'); }
// Track login event await CapacitorCrisp.pushEvent({ name: 'user_login', color: 'blue', data: { method: 'email' } }); }
async openSupport(context?: string) { if (context) { await CapacitorCrisp.setMessageText( `I need help with: ${context}` ); }
await CapacitorCrisp.openMessenger(); }
async logout() { await CapacitorCrisp.resetChatSession(); }}スタイルとカスタマイズ
Section titled “スタイルとカスタマイズ”Crisp はアプリのテーマに自動的に適応しますが、Crisp ダッシュボードを通じてさらにカスタマイズできます。
1.Crisp ダッシュボードに移動します 2. [設定] > [ウェブサイトの設定] > [チャットボックスと電子メールの設定] に移動します。 3. 色、位置、動作をカスタマイズする
ベストプラクティス
Section titled “ベストプラクティス”-
早めに初期化する すぐに利用できるように、アプリの初期化中に Crisp を構成します。
import { App } from '@capacitor/app';App.addListener('appStateChange', async ({ isActive }) => {if (isActive) {await CapacitorCrisp.configure({websiteID: 'YOUR_WEBSITE_ID'});}}); -
ユーザーコンテキストを設定 より良いサポートを提供できる場合は、常にユーザー情報を提供してください。
if (user.isAuthenticated) {await CapacitorCrisp.setUser({email: user.email,nickname: user.name});} -
重要なイベントを追跡する イベントを使用してサポート エージェントにコンテキストを提供します。
await CapacitorCrisp.pushEvent({name: 'error_occurred',color: 'red',data: {error: error.message,screen: 'checkout'}}); -
ログアウトを適切に処理する ユーザーがログアウトするときは、必ずセッションをリセットします。
async logout() {await CapacitorCrisp.resetChatSession();// Your other logout logic}
プラットフォームに関する注意事項
Section titled “プラットフォームに関する注意事項”- iOS 10.0+が必要です
- ネイティブ Crisp iOS SDK を使用
- プッシュ通知をサポート (Crisp ダッシュボードで設定)
Android
Section titled “Android”- Android 5.0 (API 21)+ が必要です
- ネイティブ Crisp Android SDK を使用します
- マテリアルデザイン準拠
- Crisp JavaScript SDK にフォールバックします
- ネイティブ プラットフォームと同等のフル機能