Passer au contenu

Commencer

  1. Installer the package

    Fenêtre de terminal
    npm i @capgo/capacitor-crisp
  2. Synchroniser with Natif projects

    Fenêtre de terminal
    npx cap sync
  3. Get your Crisp Website ID

    • Sign up at crisp.chat
    • Créer a website/project
    • Find your Website ID in Paramètres > Configuration Instructions

Importer the plugin and configure it with your Website ID:

import { CapacitorCrisp } from '@capgo/capacitor-crisp';
// Configure Crisp with your website ID
const configureCrisp = async () => {
await CapacitorCrisp.configure({
websiteID: 'YOUR_WEBSITE_ID'
});
};
// Open the chat
const openChat = async () => {
await CapacitorCrisp.openMessenger();
};
// Set user information
const 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();
};

Configure Crisp with your website ID and optional Paramètres.

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'
});

Opens the Crisp chat interface.

await CapacitorCrisp.openMessenger();

Sets Utilisateur Information for the chat session.

interface UserOptions {
email?: string;
nickname?: string;
phone?: string;
avatar?: string;
}
await CapacitorCrisp.setUser({
email: 'user@example.com',
nickname: 'John Doe'
});

Sets company Information for business Utilisateurs.

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'
}
});

Send custom events to track Utilisateur actions.

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'
}
});

Set a segment to categorize the chat session.

await CapacitorCrisp.setSessionSegment('premium_customer');

Réinitialiser the current chat session (useful for Déconnexion).

await CapacitorCrisp.resetChatSession();
// Set multiple custom data fields
await CapacitorCrisp.setSessionData({
key: 'plan',
value: 'premium'
});
await CapacitorCrisp.setSessionData({
key: 'signup_date',
value: '2024-01-15'
});

Set a pre-filled message in the chat input:

await CapacitorCrisp.setMessageText(
"Hello, I need help with my order #12345"
);

Control when the chat widget is Disponible:

// Hide chat temporarily
await 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();
}
}

Crisp automatically adapts to your Application’s theme, but you can customize it further through the Crisp Tableau de bord:

  1. Go to your Crisp Tableau de bord
  2. Navigate to Paramètres > Website Paramètres > Chatbox & Email Paramètres
  3. Customize colors, position, and behavior
  1. Initialiser early Configure Crisp during Application Initialisation for immediate availability:

    import { App } from '@capacitor/app';
    App.addListener('appStateChange', async ({ isActive }) => {
    if (isActive) {
    await CapacitorCrisp.configure({
    websiteID: 'YOUR_WEBSITE_ID'
    });
    }
    });
  2. Set Utilisateur context Always provide Utilisateur Information when Disponible for better Support:

    if (user.isAuthenticated) {
    await CapacitorCrisp.setUser({
    email: user.email,
    nickname: user.name
    });
    }
  3. Track Important events Use events to provide context to Support agents:

    await CapacitorCrisp.pushEvent({
    name: 'error_occurred',
    color: 'red',
    data: {
    error: error.message,
    screen: 'checkout'
    }
    });
  4. Handle Déconnexion properly Always Réinitialiser the session when Utilisateurs Journal out:

    async logout() {
    await CapacitorCrisp.resetChatSession();
    // Your other logout logic
    }
  • Requires iOS 10.0+
  • Uses Natif Crisp iOS SDK
  • Supports Pousser notifications (configure in Crisp Tableau de bord)
  • Requires Android 5.0 (API 21)+
  • Uses Natif Crisp Android SDK
  • Material Design compliant
  • Falls Retour to Crisp JavaScript SDK
  • Full Fonctionnalité parity with Natif platforms