# Contact Component - Data Capture Activity Documentation

This document provides a comprehensive inventory of all data captured by the Contact component, including current fields and recommended enhancements for improved support operations, AI agent utilization, and customer insights.

## Current Data Fields

### ContactData (Root Object)

| Field | Type | Source | Required | Description | Use Case |
|-------|------|--------|----------|-------------|----------|
| `name` | `string` | User input | Configurable | Customer's display name | Personalization, addressing in responses |
| `email` | `string` | User input | Configurable | Customer's email address | Response delivery, account lookup |
| `topic` | `string` | User input (dropdown) | Configurable | Selected support category | Initial routing, queue assignment |
| `message` | `string` | User input | Yes | Free-form support request | Issue understanding, AI analysis |
| `user` | `ContactUser` | App injection | No | Authenticated user context | Identity verification, history lookup |
| `context` | `Record<string, unknown>` | App injection | No | App-specific context data | Feature flags, page state, custom data |
| `metadata` | `ContactMetadata` | Auto-captured | No | Browser/session metadata | Device context, debugging |

### ContactUser (Authenticated User Data)

| Field | Type | Source | Required | Description | Use Case |
|-------|------|--------|----------|-------------|----------|
| `id` | `string` | Auth system | No | Unique user identifier | Account lookup, ticket linking |
| `email` | `string` | Auth system | No | Verified email from auth | Email pre-fill, verification |
| `name` | `string` | Auth system | No | User's profile name | Form pre-fill, personalization |

### ContactMetadata (Auto-Captured)

| Field | Type | Source | Required | Description | Use Case |
|-------|------|--------|----------|-------------|----------|
| `url` | `string` | `window.location.href` | Yes | Current page URL | Context understanding, feature identification |
| `timestamp` | `string` | `new Date().toISOString()` | Yes | Submission time (ISO 8601) | SLA tracking, timezone detection |
| `viewport` | `{ width: number; height: number }` | `window.innerWidth/Height` | Yes | Browser viewport dimensions | Device type inference, responsive issues |
| `userAgent` | `string` | `navigator.userAgent` | Yes | Browser/OS identification | Browser-specific bugs, compatibility |

---

## Recommended Additional Fields

### Timing & Session Data

| Field | Type | Source | Required | Description | Use Case |
|-------|------|--------|----------|-------------|----------|
| `sessionId` | `string` | App/analytics | No | Unique session identifier | Cross-reference with analytics, replay lookup |
| `sessionStartTime` | `string` | Session storage | No | When user session began | Session duration, engagement level |
| `formOpenTime` | `string` | Component state | No | When contact form was opened | Time-to-submit calculation |
| `formSubmitTime` | `string` | Component state | No | Actual submission timestamp | Distinguish from `metadata.timestamp` |
| `timeToComplete` | `number` | Calculated | No | Milliseconds from form open to submit | Urgency indicator, form UX analysis |
| `pageLoadTime` | `string` | Performance API | No | When current page loaded | Session context, time spent on page |

### Customer Status (B2B/SaaS Context)

| Field | Type | Source | Required | Description | Use Case |
|-------|------|--------|----------|-------------|----------|
| `customerId` | `string` | Billing system | No | Customer/organization ID | Account lookup, billing context |
| `planTier` | `string` | Subscription data | No | Current plan (free/pro/enterprise) | Priority routing, feature eligibility |
| `subscriptionStatus` | `string` | Billing system | No | active/trialing/past_due/canceled | Churn risk, billing issues |
| `accountAge` | `number` | CRM/database | No | Days since account creation | New user vs established customer |
| `mrr` | `number` | Billing system | No | Monthly recurring revenue | Revenue-based prioritization |
| `isPayingCustomer` | `boolean` | Billing system | No | Has active paid subscription | Support tier determination |
| `contractEndDate` | `string` | CRM | No | Enterprise contract expiration | Renewal-sensitive routing |

### Organization Context (B2B)

| Field | Type | Source | Required | Description | Use Case |
|-------|------|--------|----------|-------------|----------|
| `organizationId` | `string` | App context | No | Company/workspace ID | Multi-tenant context |
| `organizationName` | `string` | App context | No | Company name | B2B personalization |
| `organizationSize` | `string` | CRM | No | Company size tier | Support resource allocation |
| `industry` | `string` | CRM | No | Customer's industry vertical | Specialized support routing |
| `accountManager` | `string` | CRM | No | Assigned account manager email | Escalation routing |

### Support History

| Field | Type | Source | Required | Description | Use Case |
|-------|------|--------|----------|-------------|----------|
| `previousTicketCount` | `number` | Support system | No | Total historical tickets | Frequent requester identification |
| `openTicketCount` | `number` | Support system | No | Currently open tickets | Duplicate detection, frustration signal |
| `lastTicketDate` | `string` | Support system | No | Most recent ticket timestamp | Recency of issues |
| `averageResolutionTime` | `number` | Support system | No | Avg hours to resolve past tickets | Expectation setting |
| `satisfactionScore` | `number` | Support system | No | CSAT from previous interactions | At-risk customer identification |
| `escalationHistory` | `boolean` | Support system | No | Has escalated tickets before | Proactive escalation routing |

### Session Context

| Field | Type | Source | Required | Description | Use Case |
|-------|------|--------|----------|-------------|----------|
| `pagesVisited` | `string[]` | Analytics/state | No | URLs visited this session | Journey context, feature discovery |
| `lastActions` | `string[]` | Event tracking | No | Recent user actions (clicks, submissions) | Immediate context, error reproduction |
| `errorLogs` | `object[]` | Error tracking | No | Recent console errors | Technical issue diagnosis |
| `featureUsage` | `Record<string, boolean>` | Feature flags | No | Which features user has accessed | Feature-specific support |
| `recentSearches` | `string[]` | App state | No | Recent search queries | Intent understanding |
| `documentationVisited` | `string[]` | Analytics | No | Help/docs pages viewed | Self-service attempt tracking |

### Device & Environment

| Field | Type | Source | Required | Description | Use Case |
|-------|------|--------|----------|-------------|----------|
| `deviceType` | `string` | UA parsing | No | desktop/tablet/mobile | Device-specific issues |
| `browserName` | `string` | UA parsing | No | Chrome/Firefox/Safari/etc | Browser-specific debugging |
| `browserVersion` | `string` | UA parsing | No | Browser version number | Version-specific bugs |
| `osName` | `string` | UA parsing | No | Windows/macOS/iOS/Android | OS-specific issues |
| `osVersion` | `string` | UA parsing | No | OS version number | OS compatibility |
| `screenResolution` | `{ width: number; height: number }` | `screen` object | No | Full screen resolution | Display/responsive issues |
| `devicePixelRatio` | `number` | `window.devicePixelRatio` | No | Retina/HiDPI detection | Rendering issues |
| `connectionType` | `string` | Network Information API | No | 4g/3g/wifi/etc | Performance context |
| `language` | `string` | `navigator.language` | No | Browser language setting | Localization, routing |
| `timezone` | `string` | `Intl.DateTimeFormat` | No | User's timezone | Support hours routing |

### Urgency & Sentiment

| Field | Type | Source | Required | Description | Use Case |
|-------|------|--------|----------|-------------|----------|
| `urgencyLevel` | `string` | User input (optional) | No | low/medium/high/critical | Priority queue assignment |
| `impactScope` | `string` | User input | No | just_me/team/company/customers | Business impact assessment |
| `sentimentScore` | `number` | AI analysis | No | -1 to 1 sentiment from message | Escalation triggers |
| `frustrationIndicators` | `string[]` | Text analysis | No | Detected frustration signals | Proactive escalation |
| `keywordsDetected` | `string[]` | Text analysis | No | Important terms from message | Topic classification |

### Attribution & Source

| Field | Type | Source | Required | Description | Use Case |
|-------|------|--------|----------|-------------|----------|
| `referrer` | `string` | `document.referrer` | No | Previous page URL | Traffic source, context |
| `utmSource` | `string` | URL params | No | Marketing source tag | Campaign attribution |
| `utmMedium` | `string` | URL params | No | Marketing medium tag | Channel analysis |
| `utmCampaign` | `string` | URL params | No | Marketing campaign tag | Campaign-specific support |
| `entryPoint` | `string` | App tracking | No | Where contact was triggered | UI flow optimization |
| `triggerContext` | `string` | Component state | No | What prompted contact (error/help/etc) | Intent classification |

### Attachments & Evidence

| Field | Type | Source | Required | Description | Use Case |
|-------|------|--------|----------|-------------|----------|
| `screenshotAvailable` | `boolean` | Component feature | No | User captured screenshot | Visual debugging |
| `screenshotUrl` | `string` | Upload service | No | URL to uploaded screenshot | Issue visualization |
| `consoleSnapshot` | `object[]` | Console capture | No | Recent console output | Technical debugging |
| `networkErrors` | `object[]` | Network capture | No | Recent failed requests | API issue diagnosis |
| `localStorageKeys` | `string[]` | Storage inspection | No | Keys present in localStorage | State debugging |

---

## AI Agent Utilization

### Support Routing & Prioritization

AI agents can leverage this data to automatically:

1. **Intelligent Queue Assignment**
   - Route paying customers (`isPayingCustomer`, `planTier`, `mrr`) to priority queues
   - Direct enterprise accounts (`organizationSize`, `contractEndDate`) to dedicated support
   - Assign based on `topic` and `keywordsDetected` to specialized teams

2. **Urgency Detection**
   - Analyze `sentimentScore` and `frustrationIndicators` for escalation
   - Consider `impactScope` for business-critical issues
   - Factor in `openTicketCount` to identify frustrated repeat contacts
   - Use `timeToComplete` as urgency signal (quick submissions often indicate urgency)

3. **Context-Aware Response Generation**
   - Reference `pagesVisited` and `lastActions` to understand user journey
   - Check `documentationVisited` to avoid recommending already-tried solutions
   - Use `featureUsage` to tailor responses to user's experience level

4. **Proactive Issue Detection**
   - Correlate `errorLogs` and `networkErrors` with reported issues
   - Match `browserVersion` and `osVersion` against known compatibility issues
   - Identify patterns across `topic` and `url` for systemic problems

5. **SLA Management**
   - Calculate response windows based on `planTier` and `subscriptionStatus`
   - Route to appropriate timezone support using `timezone` and `language`
   - Prioritize based on `contractEndDate` proximity for renewal-sensitive accounts

### Customer Insights & Analytics

Aggregating this data enables:

- **Churn prediction**: Correlate support frequency, sentiment trends, and subscription status
- **Feature friction identification**: Map support topics to specific URLs and features
- **Documentation gap analysis**: High contact volume + low documentation visits = missing docs
- **Product quality metrics**: Error log patterns, browser/device distribution of issues
- **Customer health scoring**: Combine satisfaction, usage, and support history

### Response Time Optimization

- **Staffing optimization**: Analyze `timezone` distribution for support coverage
- **Self-service opportunities**: Identify common issues from `topic` + `message` clustering
- **Bot deflection candidates**: Simple queries with positive resolution history
- **Escalation prediction**: Early routing of likely-to-escalate tickets

---

## Implementation Notes

### Privacy Considerations
- All customer status and history fields require explicit data sharing agreements
- Device/browser data should be anonymized for analytics
- Support history should be opt-in or disclosed in privacy policy
- Error logs may contain sensitive data requiring sanitization

### Performance Considerations
- Session/history data should be cached, not fetched on every form open
- Heavy metadata capture should be deferred until form submission
- Large arrays (errorLogs, pagesVisited) should be capped/truncated

### Data Freshness
- `subscriptionStatus` and `planTier` should reflect real-time billing state
- `openTicketCount` requires support system integration
- `sentimentScore` requires async AI processing post-submission
