# BuzzTrail Wix Integration Guide

## 🎯 **Overview**

This guide covers how to integrate BuzzTrail video demos into your Wix website using the NX-integrated build system. The integration creates a professional embedded experience where users can interact with Tom, your AI avatar, directly within your site without any external redirects.

## 📋 **Demo Available**

**BuzzTrail Tom Video Demo**
- **Persona**: Tom (`p527c5d8b826`)
- **Replica**: Tom's Avatar (`rca8a38779a8`)  
- **Duration**: 60 seconds
- **Theme**: Purple gradient with professional styling
- **Experience**: Embedded conversation within your Wix section

## 🚀 **Quick Integration (3 Steps)**

### **Step 1: Build Production Code**
```bash
# In the extension directory
pnpm wix
# or
pnpm nx build:wix demos
```

### **Step 2: Add Custom Code**
1. **Go to Site Settings → Custom Code** in Wix
2. **Choose "Add Code to Pages" → Body - end** (important!)
3. **Copy entire contents** from `wix-custom-code-production.html`
4. **Paste and Save**

### **Step 3: Configure Section**
The code is pre-configured for section ID: `comp-mfdtv4rf5`

If your section has a different ID:
1. **Right-click your section** → Inspect Element
2. **Find the section ID** (format: `comp-xxxxxxxx`)
3. **Update `sectionId` in `src/wix-demo.js`**
4. **Rebuild**: `pnpm wix`
5. **Re-deploy** the updated code

### **Testing**
- **Preview your page** - the demo should appear in your section after 2 seconds
- **Check console** for "🚀 BuzzTrail Demo initialized" message
- **Test conversation** flow end-to-end

## ✅ **How The Experience Works**

### **Landing State**
- **Left Panel**: Hero text and "Talk to Tom" button
- **Right Panel**: Tom's looping video (your Wix-hosted video)
- **Mobile**: Video stacks on top, text below
- **Professional design** with purple gradient button

### **Conversation State (60 seconds)**  
- **Embedded interface**: Replaces landing content
- **Header**: Shows "Talking with Tom" and countdown timer
- **Timer**: 60s → 1s countdown (green → red at 10s)
- **End Call**: Red button for manual termination
- **Full permissions**: Camera/microphone work in embedded iframe

### **After Conversation**
- **Returns to landing**: Automatically restores original content
- **Ready for next user**: Button resets to "Talk to Tom"
- **Clean transition**: No external URLs or redirects

## 🔧 **Technical Specifications**

### **Build System**
- **Architecture**: NX + Vite with Terser minification
- **Source**: Single `src/wix-demo.js` file
- **Environment Variables**: Injected via Vite define plugin
- **React-Safe**: Handles Wix platform React conflicts

### **Code Metrics**
- **Size**: ~14,993 characters (99.95% of Wix's 15,000 limit)
- **Format**: Aggressively minified and optimized
- **Dependencies**: None (completely self-contained)
- **Loading**: 2-second delay for React settlement

### **Configuration** (in `src/wix-combined.js`)
```javascript
// Configuration is now environment-driven via .env files
// Local: Uses .env.local with fake server
// Production: Uses .env.production with real Tavus API

const DEMO_CONFIG = getEnvironmentConfig();
// Includes: proxyUrl, videoUrl, conversationDuration, etc.
```

### **Responsive Breakpoints**
- **Desktop**: Side-by-side layout (text | video)
- **Tablet (≤768px)**: Stacked (video top, text bottom)
- **Phone (≤480px)**: Optimized spacing and full-width button

## 🎨 **Design & Branding**

### **Landing Page Design**
- **Typography**: System fonts with proper hierarchy
- **Colors**: BuzzTrail purple gradient (`#a855f7` to `#ec4899`)
- **Video**: Rounded corners with subtle overlay
- **Button**: Hover effects and professional styling
- **Footer**: Branded tagline

### **Conversation Interface**
- **Header**: Dark overlay with branding and timer
- **Container**: Rounded corners, professional appearance  
- **Controls**: Touch-friendly button sizes
- **Timer**: Color-coded countdown (green → red)

### **Mobile Optimization**
- **Video Heights**: 300px tablet, 250px phone
- **Button**: Full width on mobile devices
- **Typography**: Responsive scaling (3.5rem → 1.8rem)
- **Spacing**: Optimized padding for small screens

## 🔒 **Privacy & Security Benefits**

### **Domain Control**
- ✅ **No external URLs**: Users never see `tavus.daily.co`
- ✅ **Stays on your domain**: Entire experience on your site
- ✅ **No new tabs**: Everything embedded in-page
- ✅ **Professional branding**: Only your branding visible

### **Permissions & Access**
- **HTTPS Required**: For camera/microphone access
- **Iframe Permissions**: Full media access configured
- **No Popup Blockers**: Embedded, not pop-up based
- **Cross-Origin**: Properly configured for security

## 📊 **Performance**

### **Loading & Initialization**
- **Fast startup**: Minimal JavaScript execution
- **Smart timing**: Waits for Wix to load completely  
- **Efficient CSS**: All styles minified and optimized
- **Small footprint**: 11KB total compressed code

### **Runtime Performance**
- **Timer updates**: Only every second (efficient)
- **Memory usage**: Minimal impact on page performance
- **Network calls**: Only when starting/ending conversations
- **Cleanup**: Automatic resource management

## 🚨 **Troubleshooting**

### **Demo Doesn't Appear**
```javascript
// Check console for this message:
"🚀 BuzzTrail Demo initialized"

// If not found:
1. Check section ID matches your section
2. Ensure custom code is in "Body - end" (not Head)
3. Wait for 2-second React settlement delay
4. Check for JavaScript errors in console
```

### **Video Issues**
- **Video URL**: Must be publicly accessible Wix video
- **Format**: MP4 recommended for compatibility
- **Size**: Optimized videos load faster
- **Hosting**: Use Wix Media Manager for best performance

### **Conversation Issues** 
- **Proxy Service**: Check `https://buzztrail-proxy.vercel.app/api/health`
- **Network**: Ensure API calls can reach proxy
- **HTTPS**: Camera requires secure connection
- **Permissions**: Allow browser camera/microphone prompts

### **Mobile Issues**
- **Responsive CSS**: All breakpoints use `!important`
- **Touch targets**: Buttons sized for touch interaction
- **Video height**: Fixed heights prevent layout shift
- **Scroll behavior**: Container manages overflow properly

## 📱 **Mobile Experience Details**

### **Responsive Design**
The system automatically adjusts for different screen sizes:

- **Desktop**: 720px × 405px video (16:9 aspect ratio)
- **Tablet (≤768px)**: 480px × 270px video
- **Mobile (≤480px)**: 280px × 350px video (4:5 aspect ratio)

All handled automatically by the responsive CSS system.

## 🔄 **Customization Options**

### **Update Video**
1. Upload new video to Wix Media Manager
2. Copy the new video URL
3. Update `VITE_VIDEO_URL` in `.env.production`
4. Rebuild: `pnpm nx build:wix demos`
5. Deploy updated code to Wix

### **Change Duration**
Update `VITE_CONVERSATION_DURATION` in `.env.production`:
```bash
VITE_CONVERSATION_DURATION=300  # Change to desired seconds
```
Then rebuild with `pnpm nx build:wix demos` and redeploy.

### **Update Text Content**
Edit the HTML content in the `generateBuzzTrailHTML` function in `src/shared-demo.js`:
```javascript
<h1 class="buzztrail-hero-title">Your Custom Title</h1>
<p class="buzztrail-hero-description">Your custom description</p>
```
Then rebuild and redeploy.

### **Modify Colors**
Update the CSS in the `generateBuzzTrailCSS` function in `src/shared-demo.js`:
```css
background: linear-gradient(135deg, #YOUR_COLOR1 0%, #YOUR_COLOR2 100%)
```
Then rebuild and redeploy.

## 🎯 **Success Tracking**

### **Key Metrics**
- **Landing Page Views**: Users who see the demo
- **Conversation Starts**: Button clicks / API calls
- **Completion Rate**: 60-second completions
- **Return Usage**: Repeat conversations
- **Mobile vs Desktop**: Usage patterns by device

### **Console Logging**
The integration includes detailed logging:
```javascript
"🚀 BuzzTrail Demo initialized"           // Successful setup
"✅ Conversation created"                 // API success
"❌ Failed to start conversation"         // API errors  
"🔚 Ending conversation"                  // Manual/auto end
```

## 🏆 **Final Implementation**

### **What You Get**
- ✅ **Professional landing page** with Tom's video
- ✅ **Embedded 60-second conversations** 
- ✅ **No external branding** or redirects
- ✅ **Mobile-optimized** responsive design
- ✅ **Zero maintenance** required
- ✅ **Full camera permissions** 
- ✅ **Automatic cleanup** and reset

### **User Journey**
1. **Lands on your page** → Sees professional demo interface
2. **Clicks "Talk to Tom"** → Embedded conversation starts instantly  
3. **Talks with Tom** → 60-second qualified conversation
4. **Conversation ends** → Returns to landing page for next user

### **Business Impact**
- **Higher engagement**: No friction from external redirects
- **Professional appearance**: Maintains your branding throughout
- **Better conversions**: Users stay on your domain
- **Mobile friendly**: Works perfectly on all devices
- **Qualified leads**: 60-second limit ensures quality interactions

Your Wix integration is now ready to deliver professional, embedded AI conversations that keep users on your site and deliver qualified leads directly to your sales team!

## 📞 **Support**

### **Health Checks**
- **Proxy Service**: `https://buzztrail-proxy.vercel.app/api/health`
- **API Endpoints**: Create, End conversation functionality
- **Console Logging**: Detailed error messages for debugging

### **File Locations**
- **Production Build**: `wix-custom-code-production.html`
- **Local Build**: `wix-custom-code-local.html`
- **Source Code**: `src/wix-demo.js`
- **Build Config**: `vite.wix.config.ts`
- **Integration Guide**: `/apps/demos/WIX-INTEGRATION-GUIDE.md` (this file)