cdp-edge 2.2.5 → 2.3.0
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 +34 -2
- package/contracts/types.ts +81 -0
- package/docs/whatsapp-ctwa.md +3 -2
- package/package.json +7 -4
- package/server-edge-tracker/{index.js → index.ts} +91 -82
- package/server-edge-tracker/modules/{db.js → db.ts} +116 -76
- package/server-edge-tracker/modules/dispatch/{ga4.js → ga4.ts} +12 -10
- package/server-edge-tracker/modules/dispatch/{meta.js → meta.ts} +35 -28
- package/server-edge-tracker/modules/dispatch/{platforms.js → platforms.ts} +58 -56
- package/server-edge-tracker/modules/dispatch/{tiktok.js → tiktok.ts} +22 -20
- package/server-edge-tracker/modules/dispatch/{whatsapp.js → whatsapp.ts} +59 -25
- package/server-edge-tracker/modules/{intelligence.js → intelligence.ts} +175 -60
- package/server-edge-tracker/modules/ml/{bidding.js → bidding.ts} +37 -35
- package/server-edge-tracker/modules/ml/{fraud.js → fraud.ts} +48 -40
- package/server-edge-tracker/modules/ml/{logistic.js → logistic.ts} +44 -19
- package/server-edge-tracker/modules/ml/{ltv.js → ltv.ts} +135 -90
- package/server-edge-tracker/modules/ml/{matchquality.js → matchquality.ts} +70 -26
- package/server-edge-tracker/modules/ml/{segmentation.js → segmentation.ts} +109 -48
- package/server-edge-tracker/modules/{utils.js → utils.ts} +41 -22
- package/server-edge-tracker/types.ts +251 -0
- package/server-edge-tracker/wrangler.toml +8 -8
- package/docs/PixelBuilder-Documentacao-Completa (2).docx +0 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CDP Edge — Server Types
|
|
3
|
+
* Tipos para o Cloudflare Worker e bindings
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { D1Database, KVNamespace, R2Bucket } from '@cloudflare/workers-types';
|
|
7
|
+
|
|
8
|
+
// ── Environment Bindings ─────────────────────────────────────────────────────
|
|
9
|
+
export interface Env {
|
|
10
|
+
// D1 Database
|
|
11
|
+
DB?: D1Database;
|
|
12
|
+
|
|
13
|
+
// KV Namespace
|
|
14
|
+
GEO_CACHE?: KVNamespace;
|
|
15
|
+
|
|
16
|
+
// R2 Bucket
|
|
17
|
+
AUDIT_LOGS?: R2Bucket;
|
|
18
|
+
|
|
19
|
+
// Workers AI
|
|
20
|
+
AI?: any;
|
|
21
|
+
|
|
22
|
+
// Rate Limiter
|
|
23
|
+
RATE_LIMITER?: any;
|
|
24
|
+
|
|
25
|
+
// Public Variables
|
|
26
|
+
META_PIXEL_ID?: string;
|
|
27
|
+
GA4_MEASUREMENT_ID?: string;
|
|
28
|
+
TIKTOK_PIXEL_ID?: string;
|
|
29
|
+
SITE_DOMAIN?: string;
|
|
30
|
+
|
|
31
|
+
// Secrets
|
|
32
|
+
META_ACCESS_TOKEN?: string;
|
|
33
|
+
GA4_API_SECRET?: string;
|
|
34
|
+
TIKTOK_ACCESS_TOKEN?: string;
|
|
35
|
+
WA_WEBHOOK_VERIFY_TOKEN?: string;
|
|
36
|
+
WHATSAPP_ACCESS_TOKEN?: string;
|
|
37
|
+
WHATSAPP_PHONE_NUMBER_ID?: string;
|
|
38
|
+
WA_NOTIFY_NUMBER?: string;
|
|
39
|
+
CALLMEBOT_PHONE?: string;
|
|
40
|
+
WEBHOOK_SECRET_TICTO?: string;
|
|
41
|
+
WEBHOOK_SECRET_HOTMART?: string;
|
|
42
|
+
WEBHOOK_SECRET_KIWIFY?: string;
|
|
43
|
+
META_TEST_CODE?: string;
|
|
44
|
+
META_AD_ACCOUNT_ID?: string;
|
|
45
|
+
META_AUDIENCE_ID?: string;
|
|
46
|
+
PINTEREST_ACCESS_TOKEN?: string;
|
|
47
|
+
PINTEREST_AD_ACCOUNT_ID?: string;
|
|
48
|
+
REDDIT_ACCESS_TOKEN?: string;
|
|
49
|
+
REDDIT_AD_ACCOUNT_ID?: string;
|
|
50
|
+
LINKEDIN_ACCESS_TOKEN?: string;
|
|
51
|
+
LINKEDIN_CONVERSION_ID?: string;
|
|
52
|
+
LINKEDIN_AD_ACCOUNT_ID?: string;
|
|
53
|
+
SPOTIFY_ACCESS_TOKEN?: string;
|
|
54
|
+
SPOTIFY_AD_ACCOUNT_ID?: string;
|
|
55
|
+
|
|
56
|
+
// Email and Notification
|
|
57
|
+
RESEND_API_KEY?: string;
|
|
58
|
+
RESEND_FROM_EMAIL?: string;
|
|
59
|
+
CALLMEBOT_APIKEY?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ── Event Payload Types ───────────────────────────────────────────────────────
|
|
63
|
+
export interface TrackPayload {
|
|
64
|
+
eventName?: string;
|
|
65
|
+
eventId?: string;
|
|
66
|
+
event_id?: string;
|
|
67
|
+
userId?: string;
|
|
68
|
+
email?: string | null;
|
|
69
|
+
phone?: string | null;
|
|
70
|
+
firstName?: string | null;
|
|
71
|
+
lastName?: string | null;
|
|
72
|
+
city?: string | null;
|
|
73
|
+
state?: string | null;
|
|
74
|
+
zip?: string | null;
|
|
75
|
+
country?: string | null;
|
|
76
|
+
dob?: string | null;
|
|
77
|
+
|
|
78
|
+
// Identifiers
|
|
79
|
+
fbp?: string | null;
|
|
80
|
+
fbc?: string | null;
|
|
81
|
+
ttp?: string | null;
|
|
82
|
+
gaClientId?: string | null;
|
|
83
|
+
|
|
84
|
+
// Parameters
|
|
85
|
+
value?: number | null;
|
|
86
|
+
currency?: string | null;
|
|
87
|
+
contentIds?: string[] | null;
|
|
88
|
+
contentName?: string | null;
|
|
89
|
+
contentType?: string | null;
|
|
90
|
+
pageUrl?: string | null;
|
|
91
|
+
orderId?: string | null;
|
|
92
|
+
productName?: string | null;
|
|
93
|
+
|
|
94
|
+
// Quantum Tracking Details
|
|
95
|
+
intent_score?: string | number | null;
|
|
96
|
+
intentScoreNum?: number | null;
|
|
97
|
+
intent_bucket?: string | null;
|
|
98
|
+
intent_penalized?: boolean;
|
|
99
|
+
metaSignal?: number | null;
|
|
100
|
+
metaSignalBucket?: string | null;
|
|
101
|
+
distanceBucket?: string | null;
|
|
102
|
+
distanceKm?: number | null;
|
|
103
|
+
funnel_stage?: string | null;
|
|
104
|
+
funnelDepth?: string | null;
|
|
105
|
+
funnelLevel?: string | null;
|
|
106
|
+
internalEvent?: string | null;
|
|
107
|
+
botScore?: number | null;
|
|
108
|
+
|
|
109
|
+
// Real Estate
|
|
110
|
+
property_lat?: string | number | null;
|
|
111
|
+
propertyLat?: string | number | null;
|
|
112
|
+
property_lng?: string | number | null;
|
|
113
|
+
propertyLng?: string | number | null;
|
|
114
|
+
|
|
115
|
+
// Engagement
|
|
116
|
+
engagementScore?: number | null;
|
|
117
|
+
intentionLevel?: string | null;
|
|
118
|
+
userScore?: number | null;
|
|
119
|
+
scrollScore?: number | null;
|
|
120
|
+
timeLevel?: string | null;
|
|
121
|
+
|
|
122
|
+
// UTM
|
|
123
|
+
utmSource?: string | null;
|
|
124
|
+
utmMedium?: string | null;
|
|
125
|
+
utmCampaign?: string | null;
|
|
126
|
+
utmContent?: string | null;
|
|
127
|
+
utmTerm?: string | null;
|
|
128
|
+
utmRestored?: boolean;
|
|
129
|
+
|
|
130
|
+
// LTV
|
|
131
|
+
ltvClass?: string | null;
|
|
132
|
+
ltvScore?: number | null;
|
|
133
|
+
|
|
134
|
+
// Additional fields
|
|
135
|
+
[key: string]: any;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface BehavioralData {
|
|
139
|
+
engagement_score?: number;
|
|
140
|
+
totalScore?: number;
|
|
141
|
+
intention_level?: string;
|
|
142
|
+
user_score?: number;
|
|
143
|
+
scroll_score?: number;
|
|
144
|
+
time_level?: string;
|
|
145
|
+
email?: string | null;
|
|
146
|
+
phone?: string | null;
|
|
147
|
+
first_name?: string | null;
|
|
148
|
+
firstName?: string | null;
|
|
149
|
+
last_name?: string | null;
|
|
150
|
+
lastName?: string | null;
|
|
151
|
+
city?: string | null;
|
|
152
|
+
state?: string | null;
|
|
153
|
+
zip?: string | null;
|
|
154
|
+
dob?: string | null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ── Webhook Types ─────────────────────────────────────────────────────────────
|
|
158
|
+
export interface HotmartWebhook {
|
|
159
|
+
data?: {
|
|
160
|
+
buyer?: {
|
|
161
|
+
email?: string;
|
|
162
|
+
phone?: string;
|
|
163
|
+
name?: string;
|
|
164
|
+
};
|
|
165
|
+
purchase?: {
|
|
166
|
+
status?: string;
|
|
167
|
+
transaction?: string;
|
|
168
|
+
price?: {
|
|
169
|
+
value?: number;
|
|
170
|
+
currency_value?: string;
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
product?: {
|
|
174
|
+
id?: string;
|
|
175
|
+
ucode?: string;
|
|
176
|
+
name?: string;
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
[key: string]: any;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface KiwifyWebhook {
|
|
183
|
+
order_status?: string;
|
|
184
|
+
order_id?: string;
|
|
185
|
+
order_value?: string;
|
|
186
|
+
Customer?: {
|
|
187
|
+
email?: string;
|
|
188
|
+
mobile?: string;
|
|
189
|
+
full_name?: string;
|
|
190
|
+
};
|
|
191
|
+
Product?: {
|
|
192
|
+
product_id?: string;
|
|
193
|
+
product_name?: string;
|
|
194
|
+
};
|
|
195
|
+
[key: string]: any;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface TictoWebhook {
|
|
199
|
+
status?: string;
|
|
200
|
+
customer?: {
|
|
201
|
+
email?: string;
|
|
202
|
+
phone?: string;
|
|
203
|
+
name?: string;
|
|
204
|
+
};
|
|
205
|
+
order?: {
|
|
206
|
+
hash?: string;
|
|
207
|
+
transaction_hash?: string;
|
|
208
|
+
id?: string;
|
|
209
|
+
paid_amount?: number;
|
|
210
|
+
total?: number;
|
|
211
|
+
amount?: number;
|
|
212
|
+
};
|
|
213
|
+
item?: {
|
|
214
|
+
product_id?: string;
|
|
215
|
+
product_name?: string;
|
|
216
|
+
};
|
|
217
|
+
tracking?: {
|
|
218
|
+
user_id?: string;
|
|
219
|
+
fbclid?: string;
|
|
220
|
+
utm_source?: string;
|
|
221
|
+
src?: string;
|
|
222
|
+
utm_medium?: string;
|
|
223
|
+
utm_campaign?: string;
|
|
224
|
+
utm_content?: string;
|
|
225
|
+
};
|
|
226
|
+
url_params?: {
|
|
227
|
+
user_id?: string;
|
|
228
|
+
fbclid?: string;
|
|
229
|
+
utm_source?: string;
|
|
230
|
+
src?: string;
|
|
231
|
+
utm_medium?: string;
|
|
232
|
+
utm_campaign?: string;
|
|
233
|
+
utm_content?: string;
|
|
234
|
+
};
|
|
235
|
+
[key: string]: any;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ── Queue Message Types ───────────────────────────────────────────────────────
|
|
239
|
+
export interface QueueMessage {
|
|
240
|
+
eventType: string;
|
|
241
|
+
payload: TrackPayload;
|
|
242
|
+
platform: string;
|
|
243
|
+
attempt?: number;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// ── Promise Settled Result Helpers ─────────────────────────────────────────────
|
|
247
|
+
export interface PromiseResult<T> {
|
|
248
|
+
status: 'fulfilled' | 'rejected';
|
|
249
|
+
value?: T;
|
|
250
|
+
reason?: Error | string;
|
|
251
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
name = "server-edge-tracker"
|
|
2
2
|
# Entry point: worker.js (monólito original, 100% compatível)
|
|
3
|
-
# Para usar a versão modular ES Modules: altere para main = "index.
|
|
4
|
-
main = "index.
|
|
3
|
+
# Para usar a versão modular ES Modules: altere para main = "index.ts"
|
|
4
|
+
main = "index.ts"
|
|
5
5
|
compatibility_date = "2025-01-01"
|
|
6
6
|
compatibility_flags = ["nodejs_compat"]
|
|
7
7
|
workers_dev = true
|
|
@@ -17,19 +17,19 @@ workers_dev = true
|
|
|
17
17
|
# zone_name = "SEU_DOMINIO"
|
|
18
18
|
|
|
19
19
|
[[routes]]
|
|
20
|
-
pattern = "
|
|
21
|
-
zone_name = "
|
|
20
|
+
pattern = "lancamentosabc.com.br/track*"
|
|
21
|
+
zone_name = "lancamentosabc.com.br"
|
|
22
22
|
|
|
23
23
|
[[routes]]
|
|
24
|
-
pattern = "*.
|
|
25
|
-
zone_name = "
|
|
24
|
+
pattern = "*.lancamentosabc.com.br/track*"
|
|
25
|
+
zone_name = "lancamentosabc.com.br"
|
|
26
26
|
|
|
27
27
|
# ── Variáveis públicas (não são segredos) ─────────────────────────────────────
|
|
28
28
|
[vars]
|
|
29
29
|
META_PIXEL_ID = ""
|
|
30
30
|
GA4_MEASUREMENT_ID = ""
|
|
31
31
|
TIKTOK_PIXEL_ID = ""
|
|
32
|
-
SITE_DOMAIN = "
|
|
32
|
+
SITE_DOMAIN = "lancamentosabc.com.br"
|
|
33
33
|
|
|
34
34
|
# ── Banco D1 ──────────────────────────────────────────────────────────────────
|
|
35
35
|
# Após criar o banco com "wrangler d1 create cdp-edge-db",
|
|
@@ -37,7 +37,7 @@ SITE_DOMAIN = "SEU_DOMINIO"
|
|
|
37
37
|
[[d1_databases]]
|
|
38
38
|
binding = "DB"
|
|
39
39
|
database_name = "cdp-edge-db"
|
|
40
|
-
database_id = "
|
|
40
|
+
database_id = "7867d38f-5fa8-4c17-b465-386211422c09"
|
|
41
41
|
|
|
42
42
|
# ── Queues — Retry + Dead Letter Queue ───────────────────────────────────────
|
|
43
43
|
# Produtor: worker envia eventos com falha para cdp-edge-retry
|
|
Binary file
|