cdp-edge 2.3.9 → 2.5.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 +54 -4
- package/bin/cdp-edge.js +3 -2
- package/contracts/agent-versions.json +383 -83
- package/dist/commands/validate.js +248 -84
- package/dist/sdk/cdpTrack.js +2095 -0
- package/dist/sdk/cdpTrack.min.js +64 -0
- package/dist/sdk/install-snippet.html +10 -0
- package/extracted-skill/tracking-events-generator/agents/ab-ltv-agent.md +1 -1
- package/extracted-skill/tracking-events-generator/agents/ab-testing-agent.md +1 -1
- package/extracted-skill/tracking-events-generator/agents/attribution-agent.md +18 -18
- package/extracted-skill/tracking-events-generator/agents/bidding-agent.md +1 -1
- package/extracted-skill/tracking-events-generator/agents/bing-agent.md +1 -1
- package/extracted-skill/tracking-events-generator/agents/code-guardian-agent.md +1 -1
- package/extracted-skill/tracking-events-generator/agents/compliance-agent.md +5 -5
- package/extracted-skill/tracking-events-generator/agents/crm-integration-agent.md +10 -10
- package/extracted-skill/tracking-events-generator/agents/dashboard-agent.md +3 -3
- package/extracted-skill/tracking-events-generator/agents/database-agent.md +17 -25
- package/extracted-skill/tracking-events-generator/agents/debug-agent.md +9 -9
- package/extracted-skill/tracking-events-generator/agents/devops-agent.md +18 -1
- package/extracted-skill/tracking-events-generator/agents/domain-setup-agent.md +5 -5
- package/extracted-skill/tracking-events-generator/agents/email-agent.md +3 -3
- package/extracted-skill/tracking-events-generator/agents/fingerprint-agent.md +4 -4
- package/extracted-skill/tracking-events-generator/agents/fraud-detection-agent.md +2 -0
- package/extracted-skill/tracking-events-generator/agents/google-agent.md +2 -2
- package/extracted-skill/tracking-events-generator/agents/intelligence-agent.md +23 -29
- package/extracted-skill/tracking-events-generator/agents/linkedin-agent.md +3 -3
- package/extracted-skill/tracking-events-generator/agents/localization-agent.md +1 -1
- package/extracted-skill/tracking-events-generator/agents/ltv-predictor-agent.md +1 -1
- package/extracted-skill/tracking-events-generator/agents/master-feedback-loop.md +16 -16
- package/extracted-skill/tracking-events-generator/agents/master-orchestrator.md +13 -13
- package/extracted-skill/tracking-events-generator/agents/memory-agent.md +14 -14
- package/extracted-skill/tracking-events-generator/agents/meta-agent.md +2 -2
- package/extracted-skill/tracking-events-generator/agents/ml-clustering-agent.md +9 -9
- package/extracted-skill/tracking-events-generator/agents/page-analyzer.md +1 -0
- package/extracted-skill/tracking-events-generator/agents/performance-agent.md +12 -12
- package/extracted-skill/tracking-events-generator/agents/performance-optimization-agent.md +7 -7
- package/extracted-skill/tracking-events-generator/agents/pinterest-agent.md +6 -6
- package/extracted-skill/tracking-events-generator/agents/premium-tracking-intelligence-agent.md +3 -3
- package/extracted-skill/tracking-events-generator/agents/r2-setup-agent.md +8 -8
- package/extracted-skill/tracking-events-generator/agents/reddit-agent.md +7 -7
- package/extracted-skill/tracking-events-generator/agents/security-enterprise-agent.md +21 -21
- package/extracted-skill/tracking-events-generator/agents/server-tracking.md +15 -15
- package/extracted-skill/tracking-events-generator/agents/spotify-agent.md +6 -6
- package/extracted-skill/tracking-events-generator/agents/tiktok-agent.md +3 -3
- package/extracted-skill/tracking-events-generator/agents/tracking-plan-agent.md +5 -5
- package/extracted-skill/tracking-events-generator/agents/validator-agent.md +9 -9
- package/extracted-skill/tracking-events-generator/agents/webhook-agent.md +4 -4
- package/extracted-skill/tracking-events-generator/agents/whatsapp-agent.md +1 -1
- package/extracted-skill/tracking-events-generator/agents/whatsapp-ctwa-setup-agent.md +3 -3
- package/extracted-skill/tracking-events-generator/agents/youtube-agent.md +9 -9
- package/extracted-skill/tracking-events-generator/anti-blocking.js +1 -1
- package/extracted-skill/tracking-events-generator/cdpTrack.js +0 -10
- package/extracted-skill/tracking-events-generator/engagement-scoring.js +2 -2
- package/extracted-skill/tracking-events-generator/micro-events.js +1 -1
- package/extracted-skill/tracking-events-generator/tracking.config.js +3 -3
- package/package.json +5 -1
- package/scripts/build-sdk.js +106 -0
- package/server-edge-tracker/index.ts +93 -0
- package/server-edge-tracker/schema-utm.sql +5 -3
- package/server-edge-tracker/wrangler.toml +1 -1
- package/extracted-skill/tracking-events-generator/agents/intelligence-scheduling.md +0 -10
|
@@ -17,7 +17,7 @@ O CDP Edge é uma fábrica. Você é a memória **temporária** da sessão de tr
|
|
|
17
17
|
| Pixel IDs e credenciais de plataformas | Apenas em memória | Ao final do projeto |
|
|
18
18
|
|
|
19
19
|
**NUNCA** persista dados reais do cliente em arquivos do projeto CDP Edge.
|
|
20
|
-
**NUNCA** salve IDs, tokens ou URLs reais no `wrangler.toml`, `
|
|
20
|
+
**NUNCA** salve IDs, tokens ou URLs reais no `wrangler.toml`, `index.ts` ou qualquer arquivo do repositório.
|
|
21
21
|
**SEMPRE** apague o `memory-agent.json` ao encerrar o projeto.
|
|
22
22
|
|
|
23
23
|
O destino final de todos os dados reais é exclusivamente dentro da **Cloudflare** — via `wrangler secret put` e `wrangler.toml` do projeto do cliente, nunca aqui.
|
|
@@ -58,7 +58,7 @@ Quando o Master Orchestrator solicitar um deploy, você fornece os dados ao DevO
|
|
|
58
58
|
|
|
59
59
|
Qualquer agente pode consultar o Memory Agent com a seguinte chamada:
|
|
60
60
|
|
|
61
|
-
```
|
|
61
|
+
```typescript
|
|
62
62
|
// Consultar qualquer dado salvo na memória da sessão
|
|
63
63
|
const memoryQuery = async (query) => {
|
|
64
64
|
const checkpoint = await readMemoryCheckpoint(); // lê memory-agent.json
|
|
@@ -328,7 +328,7 @@ O Memory Agent não é só um conceito — ele tem uma implementação técnica
|
|
|
328
328
|
"generated_at": "2025-03-27T15:00:00.000Z"
|
|
329
329
|
},
|
|
330
330
|
{
|
|
331
|
-
"file": "
|
|
331
|
+
"file": "index.ts",
|
|
332
332
|
"agent": "server-tracking-agent",
|
|
333
333
|
"status": "generated",
|
|
334
334
|
"size_bytes": 28456,
|
|
@@ -387,7 +387,7 @@ Quando o Master Orchestrator invocar o Memory Agent na FASE 0, seguir este fluxo
|
|
|
387
387
|
|
|
388
388
|
### PASSO 1 — Ler Checkpoint Atual
|
|
389
389
|
|
|
390
|
-
```
|
|
390
|
+
```typescript
|
|
391
391
|
// Master Orchestrator — FASE 0
|
|
392
392
|
const memoryCheckpoint = await readMemoryCheckpoint();
|
|
393
393
|
|
|
@@ -404,7 +404,7 @@ if (memoryCheckpoint) {
|
|
|
404
404
|
|
|
405
405
|
### PASSO 2 — Carregar Contexto para Outros Agentes
|
|
406
406
|
|
|
407
|
-
```
|
|
407
|
+
```typescript
|
|
408
408
|
// Quando spawnar qualquer agente, passar contexto do Memory Agent
|
|
409
409
|
const agentContext = {
|
|
410
410
|
api_versions: memoryCheckpoint.api_versions,
|
|
@@ -423,7 +423,7 @@ await spawnAgent('meta-agent', {
|
|
|
423
423
|
|
|
424
424
|
### PASSO 3 — Verificar Consistência
|
|
425
425
|
|
|
426
|
-
```
|
|
426
|
+
```typescript
|
|
427
427
|
// Memory Agent deve verificar inconsistências no checkpoint
|
|
428
428
|
function validateCheckpointConsistency(checkpoint) {
|
|
429
429
|
const warnings = [];
|
|
@@ -461,7 +461,7 @@ Quando o Master Orchestrator finalizar a FASE 5, seguir este fluxo de escrita:
|
|
|
461
461
|
|
|
462
462
|
### PASSO 1 — Compilar Resumo da Sessão
|
|
463
463
|
|
|
464
|
-
```
|
|
464
|
+
```typescript
|
|
465
465
|
// Master Orchestrator — FASE 5
|
|
466
466
|
const sessionSummary = {
|
|
467
467
|
session_metadata: {
|
|
@@ -488,7 +488,7 @@ const sessionSummary = {
|
|
|
488
488
|
|
|
489
489
|
### PASSO 2 — Atualizar Arquivo de Checkpoint
|
|
490
490
|
|
|
491
|
-
```
|
|
491
|
+
```typescript
|
|
492
492
|
// Escrever no arquivo principal de memória
|
|
493
493
|
await writeMemoryCheckpoint(sessionSummary);
|
|
494
494
|
|
|
@@ -504,7 +504,7 @@ await cleanupOldSessions(10);
|
|
|
504
504
|
|
|
505
505
|
Se o projeto tiver Cloudflare Worker configurado:
|
|
506
506
|
|
|
507
|
-
```
|
|
507
|
+
```typescript
|
|
508
508
|
// Master Orchestrator — Persistência em KV para próxima sessão
|
|
509
509
|
async function persistToCloudflareKV(summary) {
|
|
510
510
|
const key = `memory_session_${summary.session_metadata.session_id}`;
|
|
@@ -529,7 +529,7 @@ Outros agentes podem consultar o Memory Agent para obter informações específi
|
|
|
529
529
|
|
|
530
530
|
### API de Consulta (para outros agentes)
|
|
531
531
|
|
|
532
|
-
```
|
|
532
|
+
```typescript
|
|
533
533
|
// Qualquer agente pode chamar:
|
|
534
534
|
const memoryQuery = async (query) => {
|
|
535
535
|
const checkpoint = await readMemoryCheckpoint();
|
|
@@ -768,7 +768,7 @@ Quando os testes passarem, o Master Orchestrator executa:
|
|
|
768
768
|
|
|
769
769
|
**Se usuário confirmar (SIM):**
|
|
770
770
|
|
|
771
|
-
```
|
|
771
|
+
```typescript
|
|
772
772
|
async function purgeCredentials() {
|
|
773
773
|
// 1. Zerar secrets_configured no checkpoint
|
|
774
774
|
checkpoint.secrets_configured = {};
|
|
@@ -809,7 +809,7 @@ async function purgeCredentials() {
|
|
|
809
809
|
|
|
810
810
|
### Função de Formatação de Data
|
|
811
811
|
|
|
812
|
-
```
|
|
812
|
+
```typescript
|
|
813
813
|
function formatDate(date) {
|
|
814
814
|
const d = new Date(date);
|
|
815
815
|
const year = d.getFullYear();
|
|
@@ -821,7 +821,7 @@ function formatDate(date) {
|
|
|
821
821
|
|
|
822
822
|
### Função de Mask de Segredos
|
|
823
823
|
|
|
824
|
-
```
|
|
824
|
+
```typescript
|
|
825
825
|
function maskSecret(secret) {
|
|
826
826
|
if (!secret || secret.length < 10) return 'NOT_SET';
|
|
827
827
|
const visibleChars = 4;
|
|
@@ -836,7 +836,7 @@ function maskSecret(secret) {
|
|
|
836
836
|
|
|
837
837
|
### Função de Cleanup de Histórico
|
|
838
838
|
|
|
839
|
-
```
|
|
839
|
+
```typescript
|
|
840
840
|
async function cleanupOldSessions(maxSessions) {
|
|
841
841
|
const historyDir = 'agents/memory-agent/history';
|
|
842
842
|
const files = await listFiles(historyDir);
|
|
@@ -23,7 +23,7 @@ Especialista exclusivo em Meta Pixel (browser via cdpTrack) + Meta Conversions A
|
|
|
23
23
|
|
|
24
24
|
### PASSO 0 — Ler Versões Atuais
|
|
25
25
|
|
|
26
|
-
```
|
|
26
|
+
```typescript
|
|
27
27
|
// Ler versões do arquivo centralizado
|
|
28
28
|
const apiVersions = await readJSON('contracts/api-versions.json');
|
|
29
29
|
const metaVersion = apiVersions.meta;
|
|
@@ -99,7 +99,7 @@ Gere payloads para o Worker seguir a API oficial da Meta:
|
|
|
99
99
|
{
|
|
100
100
|
"arquivos_gerados": {
|
|
101
101
|
"browser": "cdpTrack.js (eventos Meta injetados)",
|
|
102
|
-
"server": "
|
|
102
|
+
"server": "modules/dispatch/meta.ts"
|
|
103
103
|
},
|
|
104
104
|
"versao_api": "v22.0",
|
|
105
105
|
"eventos_implementados": ["PageView", "Lead", "InitiateCheckout", "Purchase", "ViewContent"],
|
|
@@ -155,7 +155,7 @@ is_business_hours = 1 if 9 <= hour_of_day <= 18 else 0
|
|
|
155
155
|
|
|
156
156
|
### 2.3 Perfil textual por lead (input para embedding)
|
|
157
157
|
|
|
158
|
-
```
|
|
158
|
+
```typescript
|
|
159
159
|
function _buildLeadProfile(l) {
|
|
160
160
|
return [
|
|
161
161
|
`LTV: ${l.predicted_ltv_class || 'desconhecido'}`,
|
|
@@ -173,7 +173,7 @@ function _buildLeadProfile(l) {
|
|
|
173
173
|
|
|
174
174
|
### 2.4 Chamada de embeddings em batch
|
|
175
175
|
|
|
176
|
-
```
|
|
176
|
+
```typescript
|
|
177
177
|
// Embeds até 100 perfis em uma única chamada
|
|
178
178
|
const embRes = await env.AI.run('@cf/baai/bge-m3', { text: profiles });
|
|
179
179
|
const vectors = embRes.data; // float32[][] — shape [N, 768]
|
|
@@ -181,15 +181,15 @@ const vectors = embRes.data; // float32[][] — shape [N, 768]
|
|
|
181
181
|
|
|
182
182
|
### 2.5 K-means vetorial (cosine distance)
|
|
183
183
|
|
|
184
|
-
```
|
|
184
|
+
```typescript
|
|
185
185
|
// Inicialização K-means++ → iterações até convergência → assignments finais
|
|
186
|
-
const { assignments } = _kmeansRun(vectors, nClusters); // implementado em
|
|
186
|
+
const { assignments } = _kmeansRun(vectors, nClusters); // implementado em index.ts
|
|
187
187
|
const silhouetteScore = _silhouette(vectors, assignments, nClusters); // score real
|
|
188
188
|
```
|
|
189
189
|
|
|
190
190
|
### 2.6 Naming dos clusters via Granite (único uso de LLM)
|
|
191
191
|
|
|
192
|
-
```
|
|
192
|
+
```typescript
|
|
193
193
|
// Granite recebe apenas as estatísticas agregadas por cluster
|
|
194
194
|
// Retorna nome descritivo + recomendação de campanha em português
|
|
195
195
|
const nameRes = await env.AI.run('@cf/ibm-granite/granite-4.0-h-micro', {
|
|
@@ -200,7 +200,7 @@ const nameRes = await env.AI.run('@cf/ibm-granite/granite-4.0-h-micro', {
|
|
|
200
200
|
|
|
201
201
|
### 2.2 Features para K-Means
|
|
202
202
|
|
|
203
|
-
```
|
|
203
|
+
```typescript
|
|
204
204
|
// Features recomendadas para clustering (com base na análise D1)
|
|
205
205
|
|
|
206
206
|
const RECOMMENDED_FEATURES = [
|
|
@@ -461,7 +461,7 @@ CREATE INDEX IF NOT EXISTS idx_ml_segment_members_lead ON ml_segment_members(lea
|
|
|
461
461
|
|
|
462
462
|
### 7.1 Endpoint de Clustering
|
|
463
463
|
|
|
464
|
-
```
|
|
464
|
+
```typescript
|
|
465
465
|
// server-edge-tracker/functions/api/segmentation/cluster.ts
|
|
466
466
|
|
|
467
467
|
export async function onRequestGet(context: EventContext<Env>) {
|
|
@@ -515,7 +515,7 @@ export async function onRequestGet(context: EventContext<Env>) {
|
|
|
515
515
|
|
|
516
516
|
### 7.2 Endpoint de Consulta de Segmentos
|
|
517
517
|
|
|
518
|
-
```
|
|
518
|
+
```typescript
|
|
519
519
|
// server-edge-tracker/functions/api/segmentation/list.ts
|
|
520
520
|
|
|
521
521
|
export async function onRequestGet(context: EventContext<Env>) {
|
|
@@ -546,7 +546,7 @@ export async function onRequestGet(context: EventContext<Env>) {
|
|
|
546
546
|
|
|
547
547
|
### 7.3 Endpoint de Anomalias (DBSCAN)
|
|
548
548
|
|
|
549
|
-
```
|
|
549
|
+
```typescript
|
|
550
550
|
// server-edge-tracker/functions/api/segmentation/outliers.ts
|
|
551
551
|
|
|
552
552
|
export async function onRequestGet(context: EventContext<Env>) {
|
|
@@ -12,6 +12,7 @@ Toda a sua análise deve ser baseada na infraestrutura nativa da Cloudflare.
|
|
|
12
12
|
- Eventos de formulário servem para captura de PII direto para o **D1 Database**.
|
|
13
13
|
- Conversões externas cruzam dados via Webhook + D1.
|
|
14
14
|
- **Human-Behavior Engine**: Micro-eventos são obrigatórios em TODA página.
|
|
15
|
+
- **Worker:** `server-edge-tracker/index.ts` (TypeScript nativo, compilado via wrangler/esbuild)
|
|
15
16
|
|
|
16
17
|
---
|
|
17
18
|
|
|
@@ -36,7 +36,7 @@ Prover **monitoramento contínuo e profissional** da performance do sistema de t
|
|
|
36
36
|
|
|
37
37
|
### 1.1 Latência do Worker
|
|
38
38
|
|
|
39
|
-
```
|
|
39
|
+
```typescript
|
|
40
40
|
// Monitorar tempo de resposta do Cloudflare Worker
|
|
41
41
|
export async function measureWorkerLatency() {
|
|
42
42
|
const sampleSize = 100;
|
|
@@ -115,7 +115,7 @@ function evaluateLatencyPerformance(latencyMetrics) {
|
|
|
115
115
|
|
|
116
116
|
### 1.2 Error Rate das APIs
|
|
117
117
|
|
|
118
|
-
```
|
|
118
|
+
```typescript
|
|
119
119
|
// Monitorar taxa de falhas em todas as APIs
|
|
120
120
|
export async function measureApiErrorRate(env, hours = 24) {
|
|
121
121
|
const platforms = ['meta', 'google', 'tiktok', 'pinterest', 'reddit'];
|
|
@@ -167,7 +167,7 @@ function evaluateErrorRate(errorRate) {
|
|
|
167
167
|
|
|
168
168
|
### 1.3 Throughput do Sistema
|
|
169
169
|
|
|
170
|
-
```
|
|
170
|
+
```typescript
|
|
171
171
|
// Monitorar eventos processados por segundo/minuto
|
|
172
172
|
export async function measureThroughput(env, hours = 24) {
|
|
173
173
|
const now = new Date();
|
|
@@ -237,7 +237,7 @@ function evaluateThroughputTrend(recent, historical) {
|
|
|
237
237
|
|
|
238
238
|
### 1.4 Performance de D1
|
|
239
239
|
|
|
240
|
-
```
|
|
240
|
+
```typescript
|
|
241
241
|
// Monitorar performance do banco de dados D1
|
|
242
242
|
export async function measureD1Performance(env, hours = 24) {
|
|
243
243
|
// Queries lentas
|
|
@@ -331,7 +331,7 @@ function evaluateD1Health(slowQueries, locks, dbSize) {
|
|
|
331
331
|
|
|
332
332
|
### 1.5 Cache Performance (KV)
|
|
333
333
|
|
|
334
|
-
```
|
|
334
|
+
```typescript
|
|
335
335
|
// Monitorar eficiência do cache KV
|
|
336
336
|
export async function measureCachePerformance(env, hours = 24) {
|
|
337
337
|
// Cache hits e misses
|
|
@@ -549,7 +549,7 @@ alerts:
|
|
|
549
549
|
|
|
550
550
|
### Implementação com Server-Sent Events (SSE)
|
|
551
551
|
|
|
552
|
-
```
|
|
552
|
+
```typescript
|
|
553
553
|
// Endpoint SSE para atualizações em tempo real do dashboard
|
|
554
554
|
export async function handleMonitoringStream(request, env) {
|
|
555
555
|
const headers = {
|
|
@@ -856,7 +856,7 @@ cpu_ms = 50 # Aumentar de 10ms para 50ms
|
|
|
856
856
|
**Problema:** Queries repetidas ao D1 degradam performance.
|
|
857
857
|
|
|
858
858
|
**Solução:**
|
|
859
|
-
```
|
|
859
|
+
```typescript
|
|
860
860
|
// Cache de métricas globais por 1 hora
|
|
861
861
|
const cacheKey = `metrics:global:${getHourBucket()}`;
|
|
862
862
|
const cached = await env.GEO_CACHE.get(cacheKey);
|
|
@@ -881,7 +881,7 @@ return metrics;
|
|
|
881
881
|
**Problema:** Processar eventos um por um é ineficiente.
|
|
882
882
|
|
|
883
883
|
**Solução:**
|
|
884
|
-
```
|
|
884
|
+
```typescript
|
|
885
885
|
// Agrupar eventos em batches de 10
|
|
886
886
|
const eventBatches = [];
|
|
887
887
|
for (let i = 0; i < events.length; i += 10) {
|
|
@@ -950,7 +950,7 @@ WHERE e.created_at > datetime('now', '-1 day')
|
|
|
950
950
|
**Problema:** Enviar eventos muito rápido causa 429 errors.
|
|
951
951
|
|
|
952
952
|
**Solução:**
|
|
953
|
-
```
|
|
953
|
+
```typescript
|
|
954
954
|
// Rate limiting com token bucket algorithm
|
|
955
955
|
const RATE_LIMITS = {
|
|
956
956
|
meta: { tokens: 200, refill_rate: 10 }, // 200 req/min, recarrega 10/min
|
|
@@ -985,7 +985,7 @@ async function consumeToken(platform, env) {
|
|
|
985
985
|
**Problema:** Perda de eventos durante rate limits.
|
|
986
986
|
|
|
987
987
|
**Solução:**
|
|
988
|
-
```
|
|
988
|
+
```typescript
|
|
989
989
|
// Cloudflare Queue para eventos bloqueados
|
|
990
990
|
export async function queueEventForRetry(event, platform, reason) {
|
|
991
991
|
await QUEUE.send('cdp-edge-events', {
|
|
@@ -1018,7 +1018,7 @@ setInterval(async () => {
|
|
|
1018
1018
|
**Problema:** TTL muito baixo causa cache misses frequentes.
|
|
1019
1019
|
|
|
1020
1020
|
**Solução:**
|
|
1021
|
-
```
|
|
1021
|
+
```typescript
|
|
1022
1022
|
// TTLs otimizados por tipo de dado
|
|
1023
1023
|
const CACHE_TTL = {
|
|
1024
1024
|
metrics_global: 3600, // 1 hora para métricas globais
|
|
@@ -1038,7 +1038,7 @@ const CACHE_TTL = {
|
|
|
1038
1038
|
**Problema:** Cache desatualizado causa dados incorretos.
|
|
1039
1039
|
|
|
1040
1040
|
**Solução:**
|
|
1041
|
-
```
|
|
1041
|
+
```typescript
|
|
1042
1042
|
// Invalidar cache quando dados mudarem
|
|
1043
1043
|
async function invalidateCacheOnChange(eventType, env) {
|
|
1044
1044
|
const patterns = {
|
|
@@ -75,7 +75,7 @@ Agente especializado em otimização de performance para o sistema CDP Edge (Clo
|
|
|
75
75
|
|
|
76
76
|
### L1: Memory Cache (Request-Scoped)
|
|
77
77
|
|
|
78
|
-
```
|
|
78
|
+
```typescript
|
|
79
79
|
/**
|
|
80
80
|
* L1 Memory Cache - In-request cache with automatic expiration
|
|
81
81
|
*/
|
|
@@ -163,7 +163,7 @@ let l1Cache = new L1Cache();
|
|
|
163
163
|
|
|
164
164
|
### L2: KV Cache (Global Edge Cache)
|
|
165
165
|
|
|
166
|
-
```
|
|
166
|
+
```typescript
|
|
167
167
|
/**
|
|
168
168
|
* L2 KV Cache - Global distributed cache with automatic invalidation
|
|
169
169
|
*/
|
|
@@ -314,7 +314,7 @@ let l2Cache = null;
|
|
|
314
314
|
|
|
315
315
|
### Cache Strategy Implementation
|
|
316
316
|
|
|
317
|
-
```
|
|
317
|
+
```typescript
|
|
318
318
|
/**
|
|
319
319
|
* Multi-Layer Cache Manager
|
|
320
320
|
* Orchestrates L1 and L2 caches with fallback logic
|
|
@@ -485,7 +485,7 @@ CREATE INDEX IF NOT EXISTS idx_channel_performance_updated
|
|
|
485
485
|
|
|
486
486
|
### Query Optimization Patterns
|
|
487
487
|
|
|
488
|
-
```
|
|
488
|
+
```typescript
|
|
489
489
|
/**
|
|
490
490
|
* Optimized Query Builder for D1
|
|
491
491
|
*/
|
|
@@ -676,7 +676,7 @@ let queryOptimizer = null;
|
|
|
676
676
|
|
|
677
677
|
### Batch Processing for Attribution
|
|
678
678
|
|
|
679
|
-
```
|
|
679
|
+
```typescript
|
|
680
680
|
/**
|
|
681
681
|
* Batch Attribution Processor
|
|
682
682
|
* Processes multiple attributions in parallel with batching
|
|
@@ -938,7 +938,7 @@ let batchProcessor = null;
|
|
|
938
938
|
|
|
939
939
|
### Performance Monitoring
|
|
940
940
|
|
|
941
|
-
```
|
|
941
|
+
```typescript
|
|
942
942
|
/**
|
|
943
943
|
* Latency Profiler
|
|
944
944
|
* Monitors and tracks performance metrics
|
|
@@ -1209,7 +1209,7 @@ let latencyProfiler = new LatencyProfiler();
|
|
|
1209
1209
|
|
|
1210
1210
|
### Worker API Endpoints
|
|
1211
1211
|
|
|
1212
|
-
```
|
|
1212
|
+
```typescript
|
|
1213
1213
|
/**
|
|
1214
1214
|
* Performance Monitoring Endpoints
|
|
1215
1215
|
*/
|
|
@@ -34,7 +34,7 @@ Buscar: "Pinterest", "pintrk", "pin_id", "Pinterest Conversions API", "PINTEREST
|
|
|
34
34
|
|
|
35
35
|
### PASSO 0 obrigatório — Ler Versões de API (api-versions.json)
|
|
36
36
|
|
|
37
|
-
```
|
|
37
|
+
```typescript
|
|
38
38
|
// Ler versões do arquivo centralizado
|
|
39
39
|
const apiVersions = await readJSON('contracts/api-versions.json');
|
|
40
40
|
const pinterestVersion = apiVersions.pinterest;
|
|
@@ -86,7 +86,7 @@ if (isDeprecated) {
|
|
|
86
86
|
|
|
87
87
|
**Ler do template:** `models/pinterest/tag-template.js`
|
|
88
88
|
|
|
89
|
-
```
|
|
89
|
+
```typescript
|
|
90
90
|
import { PINTEREST_TAG_TEMPLATE } from '../models/pinterest/tag-template.js';
|
|
91
91
|
|
|
92
92
|
// Substituir placeholders
|
|
@@ -193,7 +193,7 @@ Seu código gerado será incorporado pelo **Browser Tracking Agent** e **Server
|
|
|
193
193
|
[Função de inicialização + pintrk('load') + pintrk('page')]
|
|
194
194
|
|
|
195
195
|
### PINTEREST_CONVERSIONS_API_FUNCTION
|
|
196
|
-
[função sendPinterestApi() para o
|
|
196
|
+
[função sendPinterestApi() para o index.ts]
|
|
197
197
|
|
|
198
198
|
### PINTEREST_HEAD_TAGS
|
|
199
199
|
[tags <script> e <noscript> para inserir no <head>]
|
|
@@ -205,7 +205,7 @@ Seu código gerado será incorporado pelo **Browser Tracking Agent** e **Server
|
|
|
205
205
|
[Referência ao models/pinterest/event-mappings.json]
|
|
206
206
|
```
|
|
207
207
|
|
|
208
|
-
O Master Orchestrator usará esses blocos para injetar no `tracking.js` e `
|
|
208
|
+
O Master Orchestrator usará esses blocos para injetar no `tracking.js` e `index.ts` via Write/Edit.
|
|
209
209
|
|
|
210
210
|
---
|
|
211
211
|
|
|
@@ -254,7 +254,7 @@ wrangler secret put PINTEREST_AD_ACCOUNT_ID --name server-edge-tracker
|
|
|
254
254
|
Quando o Master Orchestrator solicitar código do Pinterest Agent:
|
|
255
255
|
|
|
256
256
|
1. **Ler versões da API:**
|
|
257
|
-
```
|
|
257
|
+
```typescript
|
|
258
258
|
const apiVersions = await readJSON('contracts/api-versions.json');
|
|
259
259
|
const pinterestVersion = apiVersions.pinterest.conversions_api.current; // "v5"
|
|
260
260
|
```
|
|
@@ -302,7 +302,7 @@ Quando o Master Orchestrator solicitar código do Pinterest Agent:
|
|
|
302
302
|
{
|
|
303
303
|
"blocos_gerados": {
|
|
304
304
|
"PINTEREST_BROWSER_SNIPPET": "pintrk('load') + pintrk('page') + eventos",
|
|
305
|
-
"PINTEREST_CONVERSIONS_API_FUNCTION": "sendPinterestApi() para
|
|
305
|
+
"PINTEREST_CONVERSIONS_API_FUNCTION": "sendPinterestApi() para index.ts",
|
|
306
306
|
"PINTEREST_HEAD_TAGS": "<script> + <noscript> para <head>",
|
|
307
307
|
"PINTEREST_CSP_DOMAINS": ["ct.pinterest.com", "log.pinterest.com"]
|
|
308
308
|
},
|
package/extracted-skill/tracking-events-generator/agents/premium-tracking-intelligence-agent.md
CHANGED
|
@@ -711,10 +711,10 @@ const browserTracking = {
|
|
|
711
711
|
};
|
|
712
712
|
```
|
|
713
713
|
|
|
714
|
-
### O que roda no Servidor (Cloudflare Worker)
|
|
714
|
+
### O que roda no Servidor (Cloudflare Worker — TypeScript)
|
|
715
715
|
|
|
716
|
-
```
|
|
717
|
-
// Server Tracking - Processamento e despacho para plataformas
|
|
716
|
+
```typescript
|
|
717
|
+
// Server Tracking - Processamento e despacho para plataformas (index.ts)
|
|
718
718
|
const serverTracking = {
|
|
719
719
|
// 1. Receber evento do browser
|
|
720
720
|
handleEvent: async (eventData, env, ctx) => {
|
|
@@ -111,13 +111,13 @@ bucket_name = "cdp-edge-logs"
|
|
|
111
111
|
|
|
112
112
|
---
|
|
113
113
|
|
|
114
|
-
## Fase 4 — Ativar saveAuditLog() no
|
|
114
|
+
## Fase 4 — Ativar saveAuditLog() no index.ts
|
|
115
115
|
|
|
116
|
-
O
|
|
116
|
+
O index.ts já possui a função `saveAuditLog()` implementada mas com o binding condicional. Após descomentar o binding, ela passa a salvar automaticamente.
|
|
117
117
|
|
|
118
|
-
### Verificar a função no
|
|
118
|
+
### Verificar a função no index.ts:
|
|
119
119
|
|
|
120
|
-
```
|
|
120
|
+
```typescript
|
|
121
121
|
// Buscar por: saveAuditLog ou AUDIT_LOGS
|
|
122
122
|
async function saveAuditLog(env, eventId, eventType, payload, platforms) {
|
|
123
123
|
if (!env.AUDIT_LOGS) return; // Skip se R2 não configurado (graceful degradation)
|
|
@@ -139,9 +139,9 @@ async function saveAuditLog(env, eventId, eventType, payload, platforms) {
|
|
|
139
139
|
}
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
-
Se a função não existir ainda, adicionar ao
|
|
142
|
+
Se a função não existir ainda, adicionar ao index.ts (seção de funções utilitárias):
|
|
143
143
|
|
|
144
|
-
```
|
|
144
|
+
```typescript
|
|
145
145
|
// ── R2 Audit Log ─────────────────────────────────────────────────────────────
|
|
146
146
|
async function saveAuditLog(env, eventId, eventType, payload, platforms) {
|
|
147
147
|
if (!env.AUDIT_LOGS) return;
|
|
@@ -161,7 +161,7 @@ async function saveAuditLog(env, eventId, eventType, payload, platforms) {
|
|
|
161
161
|
|
|
162
162
|
Adicionar ao `Promise.allSettled` no endpoint `/track` (dentro de `ctx.waitUntil`):
|
|
163
163
|
|
|
164
|
-
```
|
|
164
|
+
```typescript
|
|
165
165
|
// Adicionar como última entrada no allSettled:
|
|
166
166
|
saveAuditLog(env, eventId, eventType, payload, ['meta', 'ga4', 'tiktok']),
|
|
167
167
|
```
|
|
@@ -226,7 +226,7 @@ R2 Dashboard
|
|
|
226
226
|
[ ] R2 habilitado no Cloudflare Dashboard
|
|
227
227
|
[ ] Bucket cdp-edge-logs criado
|
|
228
228
|
[ ] wrangler.toml: [[r2_buckets]] descomentado
|
|
229
|
-
[ ]
|
|
229
|
+
[ ] index.ts: saveAuditLog() implementada
|
|
230
230
|
[ ] wrangler deploy executado sem erros
|
|
231
231
|
[ ] Evento de teste disparado
|
|
232
232
|
[ ] Objeto .json visível no R2 Dashboard
|
|
@@ -36,7 +36,7 @@ Buscar: "Reddit", "reddit pixel", "rdt", "Reddit Conversions API"
|
|
|
36
36
|
|
|
37
37
|
### PASSO 0 obrigatório — Ler Versões de API (api-versions.json)
|
|
38
38
|
|
|
39
|
-
```
|
|
39
|
+
```typescript
|
|
40
40
|
// Ler versões do arquivo centralizado
|
|
41
41
|
const apiVersions = await readJSON('contracts/api-versions.json');
|
|
42
42
|
const redditVersion = apiVersions.reddit;
|
|
@@ -86,7 +86,7 @@ if (isDeprecated) {
|
|
|
86
86
|
|
|
87
87
|
**Ler do template:** `models/reddit/pixel-template.js`
|
|
88
88
|
|
|
89
|
-
```
|
|
89
|
+
```typescript
|
|
90
90
|
import { REDDIT_PIXEL_TEMPLATE } from '../models/reddit/pixel-template.js';
|
|
91
91
|
|
|
92
92
|
// Substituir placeholders
|
|
@@ -152,7 +152,7 @@ function reinitRedditWithUserData(userData) {
|
|
|
152
152
|
|
|
153
153
|
**Ler do template:** `models/reddit/conversions-api-template.js`
|
|
154
154
|
|
|
155
|
-
```
|
|
155
|
+
```typescript
|
|
156
156
|
// Reutilizar funções do template
|
|
157
157
|
import {
|
|
158
158
|
trackRedditLead,
|
|
@@ -240,13 +240,13 @@ Seu código gerado (Reddit Pixel browser + Conversions API server) será incorpo
|
|
|
240
240
|
[rdt('init') + rdt('track', 'PageVisit') + funções de evento browser]
|
|
241
241
|
|
|
242
242
|
### REDDIT_CONVERSIONS_FUNCTION
|
|
243
|
-
[função sendRedditApi() para o
|
|
243
|
+
[função sendRedditApi() para o index.ts]
|
|
244
244
|
|
|
245
245
|
### REDDIT_HEAD_TAGS
|
|
246
246
|
[tag <script> para inserir no <head>]
|
|
247
247
|
```
|
|
248
248
|
|
|
249
|
-
O Master Orchestrator usará esses blocos para injetar no `tracking.js` e `
|
|
249
|
+
O Master Orchestrator usará esses blocos para injetar no `tracking.js` e `index.ts` via Write/Edit.
|
|
250
250
|
|
|
251
251
|
---
|
|
252
252
|
|
|
@@ -255,7 +255,7 @@ O Master Orchestrator usará esses blocos para injetar no `tracking.js` e `worke
|
|
|
255
255
|
Quando o Master Orchestrator solicitar código do Reddit Agent:
|
|
256
256
|
|
|
257
257
|
1. **Ler versões da API:**
|
|
258
|
-
```
|
|
258
|
+
```typescript
|
|
259
259
|
const apiVersions = await readJSON('contracts/api-versions.json');
|
|
260
260
|
const redditVersion = apiVersions.reddit.conversions_api.current; // "v2.0"
|
|
261
261
|
```
|
|
@@ -305,7 +305,7 @@ Quando o Master Orchestrator solicitar código do Reddit Agent:
|
|
|
305
305
|
{
|
|
306
306
|
"blocos_gerados": {
|
|
307
307
|
"REDDIT_BROWSER_SNIPPET": "rdt('init') + rdt('track', 'PageVisit') + eventos",
|
|
308
|
-
"REDDIT_CONVERSIONS_FUNCTION": "sendRedditApi() para
|
|
308
|
+
"REDDIT_CONVERSIONS_FUNCTION": "sendRedditApi() para index.ts",
|
|
309
309
|
"REDDIT_HEAD_TAGS": "<script> para <head>"
|
|
310
310
|
},
|
|
311
311
|
"versao_api": "v2.0",
|