# Insta Stalker - Funnel Integration

## Visão Geral

Insta Stalker é um funil de vendas para "espionagem" de Instagram integrado ao backend do ZapSpy.

## URLs

- **Espanhol**: `/insta-es/`
- **Inglês**: `/insta-en/`

## Variáveis de Ambiente Necessárias

Adicione estas variáveis no Railway/ambiente:

```env
# ======================================
# INSTA STALKER CONFIG
# ======================================

# API key já existente no projeto (compartilhada)
# RAPIDAPI_KEY=xxx (já configurada)

# Ou usar key separada só para Insta
# RAPIDAPI_KEY_INSTA=xxx

# ======================================
# PIXEL (OBRIGATÓRIO)
# ======================================

# Pixel ID do Facebook para Insta Stalker (Espanhol)
INSTA_PIXEL_ID_ES=YOUR_PIXEL_ID_ES

# Pixel ID do Facebook para Insta Stalker (Inglês)
INSTA_PIXEL_ID_EN=YOUR_PIXEL_ID_EN

# ======================================
# PIXEL TOKEN (PARA CAPI - OPCIONAL)
# ======================================

# Access Token do Pixel para CAPI (Espanhol)
INSTA_PIXEL_TOKEN_ES=YOUR_PIXEL_TOKEN_ES

# Access Token do Pixel para CAPI (Inglês)
INSTA_PIXEL_TOKEN_EN=YOUR_PIXEL_TOKEN_EN

# Habilitar CAPI
INSTA_CAPI_ENABLED=true

# ======================================
# CHECKOUT (OBRIGATÓRIO)
# ======================================

# URL do checkout PerfectPay (Espanhol)
INSTA_CHECKOUT_URL_ES=https://pay.perfectpay.com.br/PPU3xxxx

# URL do checkout PerfectPay (Inglês)
INSTA_CHECKOUT_URL_EN=https://pay.perfectpay.com.br/PPU3yyyy
```

## Fluxo do Funil

1. **Landing** (`index.html`)
   - Usuário digita @username do Instagram
   - Evento: `ViewContent` (busca iniciada)

2. **Feed** (`feed.html`)
   - Mostra posts reais do perfil
   - Stories simulados (blur)
   - Evento: `Lead` capturado no backend

3. **Direct** (`direct.html`)
   - Mostra DMs simuladas (fake, com blur)
   - Gera curiosidade

4. **CTA** (`cta.html`)
   - Página de venda com timer
   - Mostra perfil investigado
   - Botão de checkout
   - Evento: `InitiateCheckout`

## API Endpoints (Pro-Social RapidAPI)

### Configuração
- `GET /api/insta/config` - Configuração pública (pixel IDs, checkout URLs)
- `GET /api/insta/stats` - Estatísticas para admin panel

### Leads & Tracking
- `POST /api/insta/lead` - Captura lead
- `POST /api/insta/capi` - Envia evento para Facebook CAPI

### Perfil do Usuário
- `GET /api/insta/userid?username=xxx` - ID do usuário
- `GET /api/insta/userinfo?userid=xxx` - Info do perfil por ID
- `GET /api/insta/userinfo-username?username=xxx` - Info por username

### Conexões
- `GET /api/insta/userfollowers?username_or_id=xxx` - Seguidores
- `GET /api/insta/userfollowing?username_or_id=xxx` - Seguindo

### Conteúdo
- `GET /api/insta/userposts?userid=xxx` - Posts do feed
- `GET /api/insta/userreels?userid=xxx` - Reels
- `GET /api/insta/userstories?userid=xxx` - Stories (se públicos)
- `GET /api/insta/userhighlights?userid=xxx` - Destaques
- `GET /api/insta/highlightdetail?highlight_id=xxx` - Stories de um destaque
- `GET /api/insta/usertagged?userid=xxx` - Posts em que foi marcado

### Posts Específicos
- `GET /api/insta/postinfo?shortcode=xxx` - Detalhes de um post
- `GET /api/insta/postcomments?media_id=xxx` - Comentários
- `GET /api/insta/postlikers?media_id=xxx` - Quem curtiu

### Descoberta
- `GET /api/insta/search?query=xxx` - Buscar usuários
- `GET /api/insta/similarusers?userid=xxx` - Usuários similares

### Utilidades
- `GET /api/insta/proxy-img?url=xxx` - Proxy para imagens (evita CORS)

## Cloaking

O cloaking do ZapSpy é aplicado automaticamente:
- Bots/crawlers → página segura
- Desktop → página segura (se configurado)
- Brasil → página segura (se configurado)
- VPN/Datacenter → página segura (se ativado)

## Banco de Dados

Tabela `insta_stalker_leads`:
- `id` - ID único
- `username_searched` - @ buscado
- `visitor_id` - ID do visitante
- `fbc`, `fbp` - Cookies do Facebook
- `utm_*` - Parâmetros UTM
- `language` - es/en
- `converted` - Se converteu
- `created_at` - Data/hora

## Tracking Events

| Evento | Quando | Dados |
|--------|--------|-------|
| `PageView` | Cada página | - |
| `ViewContent` | Busca perfil | username |
| `Lead` | Vê feed/direct | username |
| `InitiateCheckout` | Clica checkout | username, value |
| `Purchase` | Pós-venda | value, tx_id |

## Como Configurar

1. Configure as variáveis de ambiente no Railway
2. Crie o produto no PerfectPay
3. Configure o webhook do PerfectPay para `/api/postback/perfectpay`
4. Acesse `/insta-es/` ou `/insta-en/` para testar
