Intercom Customer Support Integration
Status: Production-ready configurationLast Updated: 2025-12-19
Aligned with: CLAUDE.md Project Values
Table of Contents
- Overview
- Current Status
- Configuration
- Initialization
- User Identification
- Usage
- Multi-Tenant Context
- Best Practices
- Troubleshooting
Overview
Purpose
Intercom provides customer support chat, help center, and user communication for the Sanctiv mobile app. This document outlines our production-ready configuration aligned with project values:- 100% Excellence - Graceful error handling, proper user identification
- Multi-Tenant Architecture - org_id support for church isolation
- Follow the Leader - Official Intercom React Native SDK
- Reuse by Default - Follows Sentry integration pattern
Key Capabilities
Currently Implemented:- ✅ Customer support chat (Messenger)
- ✅ User identification and context (best practices)
- ✅ Help center integration
- ✅ Strategic event tracking (key user actions)
- ✅ Error integration with Sentry
- ✅ Screen view tracking
- ✅ Multi-tenant support (org_id)
- 🚧 Push notifications
- 🚧 Help center UI component
Current Status
✅ What’s Working
Configuration: src/lib/intercom.ts Current Intercom configuration:- API Keys: Configured via environment variables (platform-specific or single key)
- App ID: Configured via
EXPO_PUBLIC_INTERCOM_APP_ID - Initialization: Manual initialization from JavaScript (Expo plugin configured)
- User Identification: Automatic on login/logout via auth store
- Error Handling: Graceful fallback if credentials missing
App.tsx- Initializes Intercom on app startupsrc/state/authStore.ts- Registers/logs out users automaticallysrc/lib/intercom.ts- Core integration module
- ✅ Initialization with/without credentials
- ✅ User registration on login
- ✅ User logout on sign-out
- ✅ Messenger display
- ✅ Help center access
- ✅ Multi-tenant context (org_id)
Error Integration with Sentry
Status: ✅ Fully Implemented All errors captured by Sentry are automatically logged to Intercom for support context. This provides support agents with full visibility into user issues.How It Works
- Automatic Integration: When
captureException()is called in Sentry, it automatically logs to Intercom - Error Events: Errors are logged as
app_error_occurredevents with error details - User Context: Last error timestamp is stored as a user attribute for support agents
- Non-Blocking: Error logging never blocks error reporting or app functionality
Error Event Data
User Attributes Updated
last_error_at- Unix timestamp of last errorlast_error_component- Component where error occurred (if available)
- Support agents see error history when users contact support
- Better context for troubleshooting
- Helps identify patterns in user issues
Event Tracking
Status: ✅ Fully Implemented Strategic event tracking follows Intercom best practices: track meaningful business events, not every user interaction.Tracked Events
User Lifecycle:signed_in- User logs insigned_out- User logs out
journal_entry_created- New journal entry created- Metadata:
word_count,has_content,has_tags
- Metadata:
companion_request_sent- User sends companion request- Metadata:
has_message
- Metadata:
companion_request_accepted- User accepts companion request- Metadata:
request_id
- Metadata:
flow_session_completed- Guided journal flow completed- Metadata:
flow_template_id,flow_template_name,completed_steps,total_steps,duration_seconds
- Metadata:
screen_viewed- User navigates to a screen- Metadata:
screen_name,timestamp
- Metadata:
app_error_occurred- Error captured by Sentry- Metadata:
error_name,error_message, plus context
- Metadata:
Best Practices
✅ Do Track:- Business-critical actions (journal entries, companion requests)
- Feature usage (flow completions)
- User lifecycle events (sign in/out)
- Errors (automatic via Sentry integration)
- Every button tap or scroll
- Navigation between screens (handled automatically)
- Sensitive data (PII)
- High-frequency events that don’t add value
Implementation
Events are tracked automatically in:src/state/journalStore.ts- Journal entry creationsrc/state/companionsStore.ts- Companion requestssrc/flow-engine/FlowContext.tsx- Flow session completionsrc/lib/sentryNavigation.ts- Screen viewssrc/lib/sentry.ts- Error events (via Sentry integration)
Future Enhancements
Note: The following features are not yet implemented and are planned for post-pilot:- Push Notifications - Intercom push notification handling (see Push Notifications (Future))
- Help Center UI - Add UI component for help center access (API exists, UI component needed)
- 🟢 Low: Push notifications (post-pilot)
- 🟢 Low: Help center UI component (post-pilot)
Configuration
Environment Variables
Add to your.env file:
- App ID: Intercom Settings > Install
- iOS API Key: Intercom Settings > iOS
- Android API Key: Intercom Settings > Android
Expo Configuration
The Intercom Expo plugin is configured inapp.config.js:
Initialization
Intercom initializes automatically on app startup inApp.tsx:
- ✅ Initializes if credentials are configured
- ✅ Gracefully skips if credentials are missing
- ✅ Logs success/failure to console (dev mode only)
- ✅ Non-blocking (app continues if initialization fails)
- ✅ Awaited before app render to prevent race conditions with user registration
User Identification
Automatic Registration
Users are automatically registered with Intercom when they sign in. This happens insrc/state/authStore.ts:
userId- Unique user identifieremail- User email addressname- User full nameorg_id- Organization ID (custom attribute for multi-tenant)
Manual User Updates
Update user attributes manually:Usage
Show Messenger
Display the Intercom support chat:Show Help Center
Display Intercom help articles:Log Events
Track user actions for support context:Check Unread Count
Get the number of unread conversations:Hide Messenger
Programmatically hide the messenger:Multi-Tenant Context
Organization Isolation
Intercom includesorg_id as a custom attribute for multi-tenant support:
- Support agents can filter conversations by organization
- Better context for church-specific support
- Analytics by organization
org_idis automatically included when users register- Stored as
customAttributes.org_idin Intercom - Available for filtering and segmentation
Best Practices
1. Error Handling
All Intercom functions gracefully handle errors:2. User Identification
Best Practices:- ✅ Identify immediately after login (userId + email required)
- ✅ Update attributes separately (name, org_id) after identification
- ✅ Include org_id for multi-tenant context
- ✅ Log sign-in event for analytics
- ✅ Log sign-out event before logout
registerUser()handles identification in correct order:loginUserWithUserAttributes()- Identifies user (userId + email)updateUser()- Updates additional attributes (name, org_id)logEvent("signed_in")- Tracks sign-in for analytics
- ❌ Register users before login
- ❌ Skip logout on sign-out
- ❌ Send sensitive data as custom attributes
- ❌ Update attributes before identification
3. Event Tracking
Track meaningful business events:- ✅ User lifecycle (sign in/out)
- ✅ Key actions (journal entries, companion requests, flow completions)
- ✅ Errors (automatic via Sentry integration)
- ✅ Screen views (automatic via navigation tracking)
- ❌ Tracking every tap/scroll
- ❌ Sending PII in event metadata
- ❌ Over-tracking (privacy concern)
- ❌ Redundant events (screen views are automatic)
- Use snake_case:
journal_entry_created,companion_request_sent - Be descriptive:
flow_session_completednotflow_done - Include context in metadata, not event name
4. Support Access
Make support easily accessible:- ✅ Add “Contact Support” button in Settings
- ✅ Show unread count badge
- ✅ Provide help center access
Troubleshooting
Intercom Not Initializing
Symptoms: Console shows “Intercom credentials not configured” Solutions:- Check
.envfile hasEXPO_PUBLIC_INTERCOM_APP_ID - Verify API key is set (platform-specific or single key)
- Restart Expo dev server after adding env vars
- Check
app.config.jshas Intercom plugin configured
Users Not Appearing in Intercom
Symptoms: Users sign in but don’t appear in Intercom dashboard Solutions:- Verify
registerUser()is called after login - Check user has
userIdoremail(required) - Check Intercom dashboard filters (may be filtered out)
- Verify API keys are correct for your Intercom workspace
Messenger Not Showing
Symptoms:showMessenger() called but nothing appears
Solutions:
- Verify Intercom initialized (
isIntercomReady()) - Check user is logged in to Intercom (
registerUser()called) - Verify app is in foreground (Intercom requires active app)
- Check Intercom workspace settings (messenger enabled?)
Platform-Specific Issues
iOS:- Verify camera/microphone permissions in
Info.plist - Check Expo plugin applied correctly (
npx expo prebuild) - Ensure iOS API key is correct
- Verify Android API key is correct
- Check
google-services.jsonif using push notifications - Ensure minSdkVersion >= 23
Push Notifications
Implementation Status
✅ Push notifications are now integrated! Push notifications for Intercom messages are automatically registered when users grant notification permissions.How It Works
-
Automatic Token Registration:
When
registerForPushNotificationsAsync()is called (on app start or when user enables notifications):- Gets Expo push token (for our own notifications)
- Gets native device push token (for Intercom)
- Registers device token with Intercom using
Intercom.sendTokenToIntercom()
-
Notification Handling:
When a user taps an Intercom push notification:
- Intercom SDK automatically handles the notification
- Opens Intercom messenger if app is running
- Routes to Intercom conversation
Setup Requirements
Intercom Dashboard Configuration:-
Get Apple Push Notification Credentials:
- Go to Apple Developer
- Navigate to Certificates, Identifiers & Profiles > Keys
- Click + to create a new key
- Enable Apple Push Notifications service (APNs)
- Download the
.p8file (you can only download once!) - Note the Key ID and your Apple Team ID
-
Configure in Intercom Dashboard:
- Go to Settings > Channels > Messenger > Install tab
- Scroll to “Setup push notifications” section
- Fill in:
- App name:
Sanctiv - Bundle ID:
com.sanctiv.app - Upload .p8 file: Upload the downloaded file
- Key ID: Enter the Key ID from Apple
- Apple Team ID: Enter your Team ID
- App name:
- Click Save
-
Test Push Notifications:
- Send a test message from Intercom dashboard to a user
- Verify notification appears on device
- Tap notification to verify it opens Intercom messenger
Troubleshooting
Push notifications not working:-
Check Intercom is initialized:
- Verify
isIntercomReady()returnstrue - Check Metro logs for “Device token registered with Intercom”
- Verify
-
Check device token registration:
- Look for ”✅ Device token registered with Intercom” in logs
- If you see warnings, check Intercom initialization
-
Check Intercom dashboard:
- Verify APNs credentials are correctly configured
- Ensure Bundle ID matches
com.sanctiv.app - Check that push notifications are enabled for your app
-
Check device permissions:
- Verify user granted push notification permissions
- Check device Settings > Notifications > Sanctiv
getDevicePushTokenAsync() may only work on physical devices, not simulators.
Code Reference
- Token Registration:
src/services/notifications/push.service.ts→registerForPushNotificationsAsync() - Notification Handling:
src/services/notifications/push.service.ts→initializePushNotifications() - Intercom Integration:
src/lib/intercom.ts→isIntercomReady()
Future Enhancements
Potential improvements for post-pilot:- Notification Badge Count:
Related Documentation
- Environment Variables - Environment variable management
- Sentry Integration - Error monitoring (similar pattern)
- Architecture - System architecture
- Multi-Tenant Patterns - Multi-tenant architecture
Maintained by: All contributors
Review frequency: After any Intercom changes
Last audit: 2025-12-19