cdp-edge 2.2.0 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -8
- package/extracted-skill/tracking-events-generator/agents/database-agent.md +5 -4
- package/extracted-skill/tracking-events-generator/agents/fraud-detection-agent.md +0 -1
- package/extracted-skill/tracking-events-generator/agents/linkedin-agent.md +1 -1
- package/extracted-skill/tracking-events-generator/agents/ltv-predictor-agent.md +4 -4
- package/extracted-skill/tracking-events-generator/agents/ml-clustering-agent.md +81 -70
- package/extracted-skill/tracking-events-generator/agents/page-analyzer.md +6 -2
- package/extracted-skill/tracking-events-generator/models/lancamento-imobiliario.md +344 -0
- package/package.json +1 -1
- package/server-edge-tracker/index.js +1 -1
- package/server-edge-tracker/modules/ml/fraud.js +1 -16
- package/server-edge-tracker/modules/ml/ltv.js +7 -1
- package/server-edge-tracker/modules/ml/segmentation.js +157 -127
- package/server-edge-tracker/modules/utils.js +5 -3
- package/server-edge-tracker/worker.js +190 -122
- package/server-edge-tracker/wrangler.toml +22 -4
- package/templates/lancamento-imobiliario.md +344 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
# Modelo: Lançamento Imobiliário (Cloudflare Native)
|
|
2
|
+
|
|
3
|
+
Template para páginas de lançamento imobiliário com formulário de interesse, galeria, mapa/localização, simulador de financiamento, vídeo de tour, calendário de agendamento e botão WhatsApp.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🏗️ ARQUITETURA TÉCNICA (Quantum Tier)
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
Browser (cdpTrack.js)
|
|
11
|
+
├─ PageView → ao carregar
|
|
12
|
+
├─ ViewContent → ao entrar na galeria
|
|
13
|
+
├─ FindLocation → ao interagir com mapa/localização
|
|
14
|
+
├─ video_25/50/75/complete → ao assistir tour virtual
|
|
15
|
+
├─ CustomizeProduct → ao usar simulador de financiamento
|
|
16
|
+
├─ AddToWishlist → ao favoritar imóvel
|
|
17
|
+
├─ Contact → ao clicar em WhatsApp/telefone
|
|
18
|
+
├─ Schedule → ao confirmar agendamento de visita
|
|
19
|
+
└─ Lead → ao enviar formulário (PII completo)
|
|
20
|
+
│
|
|
21
|
+
▼
|
|
22
|
+
Cloudflare Worker (same-domain /track)
|
|
23
|
+
├─ Fraud Gate
|
|
24
|
+
├─ LTV Prediction (Granite 4.0 Micro) + score por eventType
|
|
25
|
+
├─ D1: upsertProfile, identity graph, distanceKm
|
|
26
|
+
└─ CAPI dispatch: Meta v22.0 + GA4 + TikTok v1.3
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 📘 MAPA DE EVENTOS
|
|
32
|
+
|
|
33
|
+
| Evento | Gatilho | Sinal para as plataformas |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| `PageView` | Carregamento | Topo do funil |
|
|
36
|
+
| `ViewContent` | Entra na galeria de fotos | Interesse no produto |
|
|
37
|
+
| `FindLocation` | Clica em mapa / "Como chegar" / abre localização | Intenção de visita física — +10 LTV |
|
|
38
|
+
| `video_25` / `video_50` / `video_75` / `video_complete` | Tour virtual / VSL em % assistido | Engajamento profundo |
|
|
39
|
+
| `CustomizeProduct` | Usa simulador de financiamento/parcelas/FGTS | Intenção de compra máxima — +15 LTV |
|
|
40
|
+
| `AddToWishlist` | Clica em "Favoritar" / coração | Interesse persistente — +8 LTV |
|
|
41
|
+
| `Contact` | Clica em WhatsApp ou telefone | Alta intenção de contato |
|
|
42
|
+
| `Schedule` | Confirma agendamento de visita | Conversão de visita |
|
|
43
|
+
| `Lead` | Envia formulário (nome/email/telefone) | Conversão principal com PII |
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## 🛠️ PASSO 1: CONFIGURAÇÃO DO SDK
|
|
48
|
+
|
|
49
|
+
### 1.1 Header
|
|
50
|
+
```html
|
|
51
|
+
<script src="/js/cdpTrack.js" async></script>
|
|
52
|
+
<script>
|
|
53
|
+
window.cdpConfig = {
|
|
54
|
+
metaId: 'SEU_PIXEL_ID',
|
|
55
|
+
ttId: 'SEU_TIKTOK_ID',
|
|
56
|
+
trackEndpoint: '/track'
|
|
57
|
+
};
|
|
58
|
+
</script>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 🛠️ PASSO 2: EVENTOS DE COMPORTAMENTO
|
|
64
|
+
|
|
65
|
+
### 2.1 PageView (automático via SDK)
|
|
66
|
+
O SDK dispara automaticamente. Não precisa de código adicional.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
### 2.2 ViewContent — Galeria de fotos
|
|
71
|
+
```javascript
|
|
72
|
+
// Dispara quando usuário abre/rola a galeria de imagens
|
|
73
|
+
document.querySelector('.galeria-imovel, [data-section="gallery"]')?.addEventListener('click', () => {
|
|
74
|
+
cdpTrack.track('ViewContent', {
|
|
75
|
+
contentName: 'Galeria — [NOME DO EMPREENDIMENTO]',
|
|
76
|
+
contentCategory: 'imovel',
|
|
77
|
+
funnel_stage: 'gallery_view',
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
### 2.3 FindLocation — Mapa / Localização
|
|
85
|
+
```javascript
|
|
86
|
+
// Dispara quando usuário clica no mapa, "Como chegar" ou "Ver localização"
|
|
87
|
+
document.querySelectorAll(
|
|
88
|
+
'a[href*="maps"], a[href*="waze"], [data-section="localizacao"], #mapa, .btn-localizacao, .btn-como-chegar'
|
|
89
|
+
).forEach(el => {
|
|
90
|
+
el.addEventListener('click', () => {
|
|
91
|
+
cdpTrack.track('FindLocation', {
|
|
92
|
+
contentName: 'Localização — [NOME DO EMPREENDIMENTO]',
|
|
93
|
+
contentCategory: 'imovel',
|
|
94
|
+
funnel_stage: 'map_view',
|
|
95
|
+
// Coordenadas do empreendimento (preencher):
|
|
96
|
+
property_lat: -23.5505, // latitude
|
|
97
|
+
property_lng: -46.6333, // longitude
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### 2.4 Vídeo / Tour Virtual
|
|
106
|
+
```javascript
|
|
107
|
+
// Para vídeo HTML5 nativo:
|
|
108
|
+
const video = document.querySelector('video#tour-virtual, video.tour-360');
|
|
109
|
+
if (video) {
|
|
110
|
+
const fired = new Set();
|
|
111
|
+
video.addEventListener('timeupdate', () => {
|
|
112
|
+
const pct = Math.floor((video.currentTime / video.duration) * 100);
|
|
113
|
+
if (pct >= 25 && !fired.has(25)) {
|
|
114
|
+
fired.add(25);
|
|
115
|
+
cdpTrack.track('video_25', { contentName: 'Tour Virtual — [NOME DO EMPREENDIMENTO]' });
|
|
116
|
+
}
|
|
117
|
+
if (pct >= 50 && !fired.has(50)) {
|
|
118
|
+
fired.add(50);
|
|
119
|
+
cdpTrack.track('video_50', { contentName: 'Tour Virtual — [NOME DO EMPREENDIMENTO]' });
|
|
120
|
+
}
|
|
121
|
+
if (pct >= 75 && !fired.has(75)) {
|
|
122
|
+
fired.add(75);
|
|
123
|
+
cdpTrack.track('video_75', { contentName: 'Tour Virtual — [NOME DO EMPREENDIMENTO]' });
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
video.addEventListener('ended', () => {
|
|
127
|
+
cdpTrack.track('video_complete', { contentName: 'Tour Virtual — [NOME DO EMPREENDIMENTO]' });
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Para YouTube embed (via YouTube API):
|
|
132
|
+
// Adicionar ?enablejsapi=1 na URL do iframe e usar onStateChange
|
|
133
|
+
// Ver: https://developers.google.com/youtube/iframe_api_reference
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
### 2.5 CustomizeProduct — Simulador de Financiamento
|
|
139
|
+
```javascript
|
|
140
|
+
// Dispara quando usuário interage com o simulador de parcelas/FGTS/Caixa
|
|
141
|
+
const simulador = document.querySelector(
|
|
142
|
+
'#simulador, .simulador-financiamento, [data-section="simulacao"], form.simulador'
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
if (simulador) {
|
|
146
|
+
// Dispara ao 1º interact (foco em qualquer campo do simulador)
|
|
147
|
+
let simuladorFired = false;
|
|
148
|
+
simulador.addEventListener('focusin', () => {
|
|
149
|
+
if (simuladorFired) return;
|
|
150
|
+
simuladorFired = true;
|
|
151
|
+
cdpTrack.track('CustomizeProduct', {
|
|
152
|
+
contentName: 'Simulador de Financiamento — [NOME DO EMPREENDIMENTO]',
|
|
153
|
+
contentCategory: 'imovel',
|
|
154
|
+
funnel_stage: 'financing_simulation',
|
|
155
|
+
intentionLevel: 'comprador',
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Dispara também ao clicar em "Simular" / "Calcular"
|
|
160
|
+
simulador.querySelector('button[type="submit"], .btn-simular, .btn-calcular')?.addEventListener('click', () => {
|
|
161
|
+
const valorImovel = simulador.querySelector('input[name="valor"], #valor-imovel')?.value;
|
|
162
|
+
cdpTrack.track('CustomizeProduct', {
|
|
163
|
+
contentName: 'Simulação Concluída — [NOME DO EMPREENDIMENTO]',
|
|
164
|
+
contentCategory: 'imovel',
|
|
165
|
+
funnel_stage: 'financing_simulation',
|
|
166
|
+
intentionLevel: 'comprador',
|
|
167
|
+
value: valorImovel ? parseFloat(valorImovel.replace(/\D/g, '')) : undefined,
|
|
168
|
+
currency: 'BRL',
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
### 2.6 AddToWishlist — Favoritar Imóvel
|
|
177
|
+
```javascript
|
|
178
|
+
// Dispara quando usuário clica em favoritar / ícone de coração
|
|
179
|
+
document.querySelectorAll('.btn-favoritar, .icon-heart, [data-action="favoritar"], .favorito').forEach(el => {
|
|
180
|
+
el.addEventListener('click', () => {
|
|
181
|
+
cdpTrack.track('AddToWishlist', {
|
|
182
|
+
contentName: '[NOME DO EMPREENDIMENTO]',
|
|
183
|
+
contentCategory: 'imovel',
|
|
184
|
+
funnel_stage: 'wishlist',
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
### 2.7 Contact — WhatsApp / Telefone
|
|
193
|
+
```javascript
|
|
194
|
+
// WhatsApp
|
|
195
|
+
document.querySelectorAll('a[href*="wa.me"], a[href*="whatsapp.com"], .btn-whatsapp').forEach(el => {
|
|
196
|
+
el.addEventListener('click', () => {
|
|
197
|
+
cdpTrack.track('Contact', {
|
|
198
|
+
contentName: 'WhatsApp — [NOME DO EMPREENDIMENTO]',
|
|
199
|
+
contentCategory: 'imovel_whatsapp',
|
|
200
|
+
funnel_stage: 'whatsapp_click',
|
|
201
|
+
intentionLevel: 'comprador',
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// Telefone
|
|
207
|
+
document.querySelectorAll('a[href^="tel:"], .btn-ligar, .btn-telefone').forEach(el => {
|
|
208
|
+
el.addEventListener('click', () => {
|
|
209
|
+
cdpTrack.track('Contact', {
|
|
210
|
+
contentName: 'Telefone — [NOME DO EMPREENDIMENTO]',
|
|
211
|
+
contentCategory: 'imovel_telefone',
|
|
212
|
+
funnel_stage: 'phone_click',
|
|
213
|
+
intentionLevel: 'comprador',
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
### 2.8 Schedule — Calendário de Agendamento de Visita
|
|
222
|
+
```javascript
|
|
223
|
+
// Dispara quando usuário CONFIRMA o agendamento (não ao abrir o calendário)
|
|
224
|
+
// Adaptar ao provider: Calendly, Google Calendar, formulário próprio
|
|
225
|
+
|
|
226
|
+
// Exemplo com Calendly:
|
|
227
|
+
window.addEventListener('message', (e) => {
|
|
228
|
+
if (e.data?.event === 'calendly.event_scheduled') {
|
|
229
|
+
cdpTrack.track('Schedule', {
|
|
230
|
+
contentName: 'Visita Agendada — [NOME DO EMPREENDIMENTO]',
|
|
231
|
+
contentCategory: 'imovel',
|
|
232
|
+
funnel_stage: 'schedule_confirmed',
|
|
233
|
+
intentionLevel: 'comprador',
|
|
234
|
+
// Dados do lead do Calendly (se disponíveis via payload):
|
|
235
|
+
email: e.data?.payload?.invitee?.email,
|
|
236
|
+
firstName: e.data?.payload?.invitee?.first_name,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// Exemplo com formulário próprio de agendamento:
|
|
242
|
+
document.querySelector('#form-agendamento')?.addEventListener('submit', async (e) => {
|
|
243
|
+
e.preventDefault();
|
|
244
|
+
const data = new FormData(e.target);
|
|
245
|
+
await cdpTrack.track('Schedule', {
|
|
246
|
+
contentName: 'Visita Agendada — [NOME DO EMPREENDIMENTO]',
|
|
247
|
+
contentCategory: 'imovel',
|
|
248
|
+
funnel_stage: 'schedule_confirmed',
|
|
249
|
+
intentionLevel: 'comprador',
|
|
250
|
+
email: data.get('email'),
|
|
251
|
+
phone: data.get('phone'),
|
|
252
|
+
firstName: data.get('nome')?.split(' ')[0],
|
|
253
|
+
});
|
|
254
|
+
e.target.submit();
|
|
255
|
+
});
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
### 2.9 Lead — Formulário Principal de Interesse
|
|
261
|
+
```javascript
|
|
262
|
+
document.querySelector('#form-interesse, #form-lead, form.form-contato')?.addEventListener('submit', async (e) => {
|
|
263
|
+
e.preventDefault();
|
|
264
|
+
|
|
265
|
+
await cdpTrack.track('Lead', {
|
|
266
|
+
// PII — enviados hasheados pelo Worker
|
|
267
|
+
email: e.target.email?.value?.trim(),
|
|
268
|
+
phone: e.target.phone?.value?.trim() || e.target.telefone?.value?.trim(),
|
|
269
|
+
firstName: e.target.nome?.value?.split(' ')[0]?.trim(),
|
|
270
|
+
lastName: e.target.nome?.value?.split(' ').slice(1).join(' ')?.trim(),
|
|
271
|
+
|
|
272
|
+
// Contexto
|
|
273
|
+
contentName: '[NOME DO EMPREENDIMENTO]',
|
|
274
|
+
contentCategory: 'imovel',
|
|
275
|
+
intentionLevel: 'comprador',
|
|
276
|
+
funnel_stage: 'lead_form',
|
|
277
|
+
|
|
278
|
+
// UTMs capturados pelo SDK automaticamente
|
|
279
|
+
// Coordenadas do imóvel para distância geoespacial no Worker:
|
|
280
|
+
property_lat: -23.5505,
|
|
281
|
+
property_lng: -46.6333,
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// Redirecionar para obrigado
|
|
285
|
+
window.location.href = '/obrigado';
|
|
286
|
+
});
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## 📊 LTV por Evento — O que o Worker calcula
|
|
292
|
+
|
|
293
|
+
| Evento | Bonus LTV Score | Multiplicador Valor |
|
|
294
|
+
|---|---|---|
|
|
295
|
+
| `Lead` (utm_source=facebook, intention=comprador) | ~65–80 pts | 3.5× → **High** |
|
|
296
|
+
| `CustomizeProduct` | +15 pts automático | Score sobe para High |
|
|
297
|
+
| `FindLocation` | +10 pts automático | Puxa Medium → High |
|
|
298
|
+
| `AddToWishlist` | +8 pts automático | Sinal de retargeting |
|
|
299
|
+
| `Schedule` (visita confirmada) | intention=comprador → +20 pts | Máximo High |
|
|
300
|
+
| `Contact` (WhatsApp) | Sem LTV (evento de sinal) | — |
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## 🔄 FLUXO COMPLETO DO LEAD IMOBILIÁRIO
|
|
305
|
+
|
|
306
|
+
```
|
|
307
|
+
Usuário chega na landing
|
|
308
|
+
│
|
|
309
|
+
├─ PageView → sinal de alcance
|
|
310
|
+
├─ ViewContent (galeria) → interesse qualificado
|
|
311
|
+
├─ video_50 (tour) → engajamento profundo
|
|
312
|
+
├─ FindLocation (mapa) → intenção de visita física (+10 LTV)
|
|
313
|
+
├─ CustomizeProduct (simulador) → intenção máxima (+15 LTV)
|
|
314
|
+
├─ Contact (WhatsApp) → ação de contato
|
|
315
|
+
├─ Schedule (agendamento) → visita confirmada
|
|
316
|
+
└─ Lead (formulário) → conversão principal
|
|
317
|
+
│
|
|
318
|
+
▼
|
|
319
|
+
Worker: LTV score ~75-90 → High → valor 3.5× injetado
|
|
320
|
+
│
|
|
321
|
+
▼
|
|
322
|
+
Meta CAPI + GA4 + TikTok recebem Lead com value=R$689
|
|
323
|
+
│
|
|
324
|
+
▼
|
|
325
|
+
Algoritmo de Meta aprende a buscar mais leads de alto valor
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## 📋 CHECKLIST DE IMPLEMENTAÇÃO
|
|
331
|
+
|
|
332
|
+
- [ ] SDK `cdpTrack.js` carregando no `<head>`
|
|
333
|
+
- [ ] `PageView` disparando (automático)
|
|
334
|
+
- [ ] `ViewContent` na galeria
|
|
335
|
+
- [ ] `FindLocation` no mapa e botão "Como chegar"
|
|
336
|
+
- [ ] Vídeo/tour instrumentado (`video_25`, `video_75`, `video_complete`)
|
|
337
|
+
- [ ] `CustomizeProduct` no simulador de financiamento
|
|
338
|
+
- [ ] `AddToWishlist` no botão de favoritar
|
|
339
|
+
- [ ] `Contact` nos botões de WhatsApp e telefone
|
|
340
|
+
- [ ] `Schedule` no calendário (Calendly ou formulário próprio)
|
|
341
|
+
- [ ] `Lead` no formulário principal com PII e `property_lat/lng`
|
|
342
|
+
- [ ] Verificar `/health` retornando `d1: ok, kv: ok, ai: ok`
|
|
343
|
+
- [ ] Testar evento `Lead` no Meta Events Manager → Test Events
|
|
344
|
+
- [ ] Confirmar LTV na resposta JSON do `/track` (`class: "High"`)
|
package/package.json
CHANGED
|
@@ -6,13 +6,6 @@
|
|
|
6
6
|
import { sha256, tryParseJson } from '../utils.js';
|
|
7
7
|
|
|
8
8
|
// ── Listas de detecção ────────────────────────────────────────────────────────
|
|
9
|
-
export const DISPOSABLE_EMAIL_DOMAINS = new Set([
|
|
10
|
-
'mailinator.com','guerrillamail.com','tempmail.com','throwaway.email',
|
|
11
|
-
'yopmail.com','sharklasers.com','guerrillamailblock.com','spam4.me',
|
|
12
|
-
'10minutemail.com','trashmail.com','maildrop.cc','fakeinbox.com',
|
|
13
|
-
'dispostable.com','getairmail.com','mailnull.com',
|
|
14
|
-
]);
|
|
15
|
-
|
|
16
9
|
export const DATACENTER_PATTERNS = /amazon|google|microsoft|digitalocean|linode|ovh|vultr|hetzner|contabo|cloudflare|packet|rackspace|leaseweb/i;
|
|
17
10
|
|
|
18
11
|
// ── checkFraudGate — roda ANTES de qualquer processamento de evento ────────────
|
|
@@ -64,15 +57,7 @@ export async function checkFraudGate(env, request, payload) {
|
|
|
64
57
|
result.score += 20; result.reasons.push('no_accept_language');
|
|
65
58
|
}
|
|
66
59
|
|
|
67
|
-
// 6.
|
|
68
|
-
if (email) {
|
|
69
|
-
const domain = email.split('@')[1]?.toLowerCase();
|
|
70
|
-
if (domain && DISPOSABLE_EMAIL_DOMAINS.has(domain)) {
|
|
71
|
-
result.score += 25; result.reasons.push('disposable_email');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 7. Velocity check via KV
|
|
60
|
+
// 6. Velocity check via KV
|
|
76
61
|
if (env.GEO_CACHE && ip) {
|
|
77
62
|
const velKey1h = `fraud_velocity:${ip}:h`;
|
|
78
63
|
const velStr = await env.GEO_CACHE.get(velKey1h);
|
|
@@ -100,6 +100,12 @@ export async function predictLtv(env, payload, request, customSystemPrompt = nul
|
|
|
100
100
|
if (payload.phone) score += 4;
|
|
101
101
|
if (payload.firstName) score += 2;
|
|
102
102
|
|
|
103
|
+
// 5b. Tipo de evento imobiliário (0–15) — sinais de intenção de compra física
|
|
104
|
+
const evType = (payload.eventType || '').toLowerCase();
|
|
105
|
+
if (evType === 'customizeproduct') score += 15; // simulação de financiamento → intenção máxima
|
|
106
|
+
else if (evType === 'findlocation') score += 10; // viu mapa/localização → visita física iminente
|
|
107
|
+
else if (evType === 'addtowishlist') score += 8; // favoritou → interesse persistente
|
|
108
|
+
|
|
103
109
|
// 6. Proximidade ao imóvel físico (0–15) — apenas quando distância calculada
|
|
104
110
|
const distKm = parseFloat(payload.distanceKm ?? payload.user_distance_km ?? -1);
|
|
105
111
|
if (distKm >= 0) {
|
|
@@ -161,7 +167,7 @@ export async function predictLtv(env, payload, request, customSystemPrompt = nul
|
|
|
161
167
|
{ role: 'system', content: systemContent },
|
|
162
168
|
{ role: 'user', content: JSON.stringify(userContext) },
|
|
163
169
|
];
|
|
164
|
-
const aiRes = await env.AI.run('@cf/
|
|
170
|
+
const aiRes = await env.AI.run('@cf/ibm-granite/granite-4.0-h-micro', { messages: prompt, max_tokens: 32 });
|
|
165
171
|
const parsed = JSON.parse(aiRes.response.trim());
|
|
166
172
|
if (typeof parsed.adjustment === 'number') {
|
|
167
173
|
aiAdjustment = Math.max(-10, Math.min(10, parsed.adjustment));
|