cdp-edge 1.17.0 → 2.0.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 +308 -308
- package/bin/cdp-edge.js +61 -61
- package/dist/commands/analyze.js +52 -52
- package/dist/commands/infra.js +54 -54
- package/dist/commands/install.js +187 -0
- package/dist/commands/server.js +174 -174
- package/dist/commands/setup.js +19 -1
- package/dist/commands/validate.js +84 -84
- package/dist/index.js +12 -12
- package/extracted-skill/tracking-events-generator/advanced-matching.js +364 -364
- package/extracted-skill/tracking-events-generator/agents/bing-agent.md +8 -0
- package/extracted-skill/tracking-events-generator/agents/crm-integration-agent.md +8 -0
- package/extracted-skill/tracking-events-generator/agents/database-agent.md +8 -0
- package/extracted-skill/tracking-events-generator/agents/devops-agent.md +1 -0
- package/extracted-skill/tracking-events-generator/agents/domain-setup-agent.md +8 -0
- package/extracted-skill/tracking-events-generator/agents/google-agent.md +8 -0
- package/extracted-skill/tracking-events-generator/agents/linkedin-agent.md +8 -0
- package/extracted-skill/tracking-events-generator/agents/memory-agent.md +29 -2
- package/extracted-skill/tracking-events-generator/agents/meta-agent.md +8 -0
- package/extracted-skill/tracking-events-generator/agents/pinterest-agent.md +8 -0
- package/extracted-skill/tracking-events-generator/agents/r2-setup-agent.md +8 -0
- package/extracted-skill/tracking-events-generator/agents/reddit-agent.md +8 -0
- package/extracted-skill/tracking-events-generator/agents/server-tracking.md +1 -0
- package/extracted-skill/tracking-events-generator/agents/spotify-agent.md +8 -0
- package/extracted-skill/tracking-events-generator/agents/tiktok-agent.md +8 -0
- package/extracted-skill/tracking-events-generator/agents/validator-agent.md +4 -0
- package/extracted-skill/tracking-events-generator/agents/webhook-agent.md +8 -0
- package/extracted-skill/tracking-events-generator/agents/whatsapp-ctwa-setup-agent.md +8 -0
- package/extracted-skill/tracking-events-generator/anti-blocking.js +285 -285
- package/extracted-skill/tracking-events-generator/cdpTrack.js +641 -641
- package/extracted-skill/tracking-events-generator/engagement-scoring.js +226 -226
- package/extracted-skill/tracking-events-generator/evals/evals.json +235 -235
- package/extracted-skill/tracking-events-generator/integration-test.js +497 -497
- package/extracted-skill/tracking-events-generator/micro-events.js +992 -992
- package/extracted-skill/tracking-events-generator/models/pinterest/conversions-api-template.js +144 -144
- package/extracted-skill/tracking-events-generator/models/pinterest/event-mappings.json +48 -48
- package/extracted-skill/tracking-events-generator/models/pinterest/tag-template.js +28 -28
- package/extracted-skill/tracking-events-generator/models/reddit/conversions-api-template.js +205 -205
- package/extracted-skill/tracking-events-generator/models/reddit/event-mappings.json +56 -56
- package/extracted-skill/tracking-events-generator/models/reddit/pixel-template.js +19 -19
- package/extracted-skill/tracking-events-generator/models/scenarios/behavior-engine.js +425 -425
- package/package.json +76 -76
- package/server-edge-tracker/schema.sql +265 -265
- package/server-edge-tracker/worker.js +4160 -4160
- package/server-edge-tracker/wrangler.toml +103 -103
- package/templates/pinterest/conversions-api-template.js +144 -144
- package/templates/pinterest/event-mappings.json +48 -48
- package/templates/pinterest/tag-template.js +28 -28
- package/templates/reddit/conversions-api-template.js +205 -205
- package/templates/reddit/event-mappings.json +56 -56
- package/templates/reddit/pixel-template.js +19 -19
- package/templates/scenarios/behavior-engine.js +425 -425
|
@@ -1,205 +1,205 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reddit Conversions API Server Template — CDP Edge Quantum Tier
|
|
3
|
-
*
|
|
4
|
-
* Este template contém a função de envio para a Conversions API do Reddit
|
|
5
|
-
* Uso: Incluir no worker.js gerado pelo Server Tracking Agent
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Função principal de envio para Reddit Conversions API
|
|
10
|
-
* @param {Object} env - Variáveis de ambiente do Cloudflare Worker
|
|
11
|
-
* @param {Object} eventData - Dados do evento a ser enviado
|
|
12
|
-
* @returns {Promise<Object>} - Resposta da API
|
|
13
|
-
*/
|
|
14
|
-
export async function sendRedditApi(env, eventData) {
|
|
15
|
-
const { email, phone, userId, clientIp, userAgent, pageUrl,
|
|
16
|
-
eventId, value, currency, itemCount, transactionId } = eventData;
|
|
17
|
-
|
|
18
|
-
// Verificar se as credenciais estão configuradas
|
|
19
|
-
if (!env.REDDIT_ACCESS_TOKEN || !env.REDDIT_AD_ACCOUNT_ID) {
|
|
20
|
-
console.warn('Reddit Conversions API: Credenciais não configuradas');
|
|
21
|
-
return { success: false, error: 'MISSING_CREDENTIALS' };
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Função de hash SHA-256
|
|
25
|
-
async function sha256(str) {
|
|
26
|
-
if (!str) return undefined;
|
|
27
|
-
const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(str.toLowerCase().trim()));
|
|
28
|
-
return Array.from(new Uint8Array(buf)).map(b => b.toString(16).padStart(2,'0')).join('');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Mapeamento de eventos CDP Edge → Reddit
|
|
32
|
-
const redditEventMap = {
|
|
33
|
-
'PageView': 'PageVisit',
|
|
34
|
-
'ViewContent': 'ViewContent',
|
|
35
|
-
'Lead': 'Lead',
|
|
36
|
-
'Purchase': 'Purchase',
|
|
37
|
-
'AddToCart': 'AddToCart',
|
|
38
|
-
'CompleteRegistration': 'SignUp',
|
|
39
|
-
'Search': 'Search',
|
|
40
|
-
'InitiateCheckout': 'Purchase', // com conversionType BEGIN_CHECKOUT
|
|
41
|
-
};
|
|
42
|
-
const redditEvent = redditEventMap[eventName] || 'Custom';
|
|
43
|
-
|
|
44
|
-
// user object com SHA256
|
|
45
|
-
const user = {};
|
|
46
|
-
if (email) user.email = { value: await sha256(email) };
|
|
47
|
-
if (phone) user.phoneNumber = { value: await sha256(phone.replace(/\D/g,'')) };
|
|
48
|
-
if (userId) user.externalId = { value: await sha256(userId) };
|
|
49
|
-
if (clientIp) user.ipAddress = { value: clientIp }; // sem hash
|
|
50
|
-
if (userAgent) user.userAgent = { value: userAgent }; // sem hash
|
|
51
|
-
|
|
52
|
-
const event = {
|
|
53
|
-
event_at: new Date().toISOString(),
|
|
54
|
-
event_type: { tracking_type: redditEvent },
|
|
55
|
-
click_id: '', // Reddit click ID (rdt_cid) — se disponível da URL
|
|
56
|
-
event_metadata: {
|
|
57
|
-
currency: currency || 'BRL',
|
|
58
|
-
value_decimal: String(value || 0), // string com decimal
|
|
59
|
-
item_count: String(itemCount || 1),
|
|
60
|
-
transaction_id: transactionId || eventId,
|
|
61
|
-
conversion_id: eventId, // deduplicação
|
|
62
|
-
},
|
|
63
|
-
user,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// Adicionar conversionType para InitiateCheckout
|
|
67
|
-
if (eventName === 'InitiateCheckout') {
|
|
68
|
-
event.event_type.conversion_type = 'BEGIN_CHECKOUT';
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const payload = { events: [event] };
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
const resp = await fetch(
|
|
75
|
-
`https://ads-api.reddit.com/api/v2.0/conversions/events/${env.REDDIT_AD_ACCOUNT_ID}`,
|
|
76
|
-
{
|
|
77
|
-
method: 'POST',
|
|
78
|
-
headers: {
|
|
79
|
-
'Content-Type': 'application/json',
|
|
80
|
-
'Authorization': `Bearer ${env.REDDIT_ACCESS_TOKEN}`,
|
|
81
|
-
},
|
|
82
|
-
body: JSON.stringify(payload),
|
|
83
|
-
}
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
// Resposta de sucesso: { status: 200, message: "Success" }
|
|
87
|
-
if (resp.ok) {
|
|
88
|
-
const result = await resp.json();
|
|
89
|
-
return { success: true, result };
|
|
90
|
-
} else {
|
|
91
|
-
return { success: false, error: `HTTP ${resp.status}` };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
} catch (error) {
|
|
95
|
-
console.error('Reddit Conversions API Error:', error);
|
|
96
|
-
return { success: false, error: error.message };
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Função de Advanced Matching — re-inicializa o pixel com dados hasheados
|
|
102
|
-
* @param {Object} userData - Dados do usuário (email, phone, externalId)
|
|
103
|
-
*/
|
|
104
|
-
export function reinitRedditWithUserData(userData) {
|
|
105
|
-
const matchData = {};
|
|
106
|
-
if (userData.email) matchData.email = userData.email; // pixel faz hash
|
|
107
|
-
if (userData.phone) matchData.phoneNumber = userData.phone; // pixel faz hash
|
|
108
|
-
if (userData.externalId) matchData.externalId = userData.externalId;
|
|
109
|
-
|
|
110
|
-
rdt('init', '{REDDIT_PIXEL_ID}', matchData);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Funções de tracking de eventos (browser + server)
|
|
115
|
-
* Uso: Chamadas do tracking.js para eventos Reddit
|
|
116
|
-
*/
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Track de Lead
|
|
120
|
-
* @param {Object} data - Dados do formulário
|
|
121
|
-
*/
|
|
122
|
-
export async function trackRedditLead(data = {}) {
|
|
123
|
-
const eventId = generateEventId(); // reutilizar a função do tracking.js
|
|
124
|
-
|
|
125
|
-
// Browser: Reddit Pixel
|
|
126
|
-
if (typeof rdt !== 'undefined') {
|
|
127
|
-
if (data.email || data.phone) reinitRedditWithUserData(data);
|
|
128
|
-
rdt('track', 'Lead', { transactionId: eventId });
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Servidor: Conversions API
|
|
132
|
-
await sendToServer('Lead', { ...data, eventId, redditEventId: eventId });
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Track de Purchase
|
|
137
|
-
* @param {Object} data - Dados da compra
|
|
138
|
-
*/
|
|
139
|
-
export async function trackRedditPurchase(data = {}) {
|
|
140
|
-
const eventId = generateEventId();
|
|
141
|
-
|
|
142
|
-
if (typeof rdt !== 'undefined')
|
|
143
|
-
rdt('track', 'Purchase', {
|
|
144
|
-
value: data.value || 0,
|
|
145
|
-
currency: data.currency || 'BRL',
|
|
146
|
-
itemCount: data.itemCount ||1,
|
|
147
|
-
transactionId: data.transactionId || eventId,
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
await sendToServer('Purchase', { ...data, eventId, redditEventId: eventId });
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Track de InitiateCheckout
|
|
155
|
-
* @param {Object} data - Dados do checkout iniciado
|
|
156
|
-
*/
|
|
157
|
-
export async function trackRedditInitiateCheckout(data = {}) {
|
|
158
|
-
const eventId = generateEventId();
|
|
159
|
-
|
|
160
|
-
if (typeof rdt !== 'undefined')
|
|
161
|
-
rdt('track', 'Purchase', {
|
|
162
|
-
conversionType: 'BEGIN_CHECKOUT',
|
|
163
|
-
value: data.value || 0,
|
|
164
|
-
currency: data.currency || 'BRL',
|
|
165
|
-
transactionId: eventId,
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
await sendToServer('InitiateCheckout', { ...data, eventId });
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Gerador de Event ID único
|
|
173
|
-
* Reutiliza a função do tracking.js ou gera novo
|
|
174
|
-
*/
|
|
175
|
-
function generateEventId() {
|
|
176
|
-
return crypto.randomUUID ? crypto.randomUUID() :
|
|
177
|
-
Date.now().toString(36) + Math.random().toString(36).slice(2);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Enviar dados para servidor via fetch
|
|
182
|
-
* @param {string} eventName - Nome do evento
|
|
183
|
-
* @param {Object} data - Dados completos do evento
|
|
184
|
-
*/
|
|
185
|
-
async function sendToServer(eventName, data) {
|
|
186
|
-
const serverUrl = '/api/track'; // ou URL configurada
|
|
187
|
-
|
|
188
|
-
await fetch(serverUrl, {
|
|
189
|
-
method: 'POST',
|
|
190
|
-
headers: { 'Content-Type': 'application/json' },
|
|
191
|
-
body: JSON.stringify({
|
|
192
|
-
event_name: eventName,
|
|
193
|
-
platform: 'reddit',
|
|
194
|
-
...data
|
|
195
|
-
})
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
export default {
|
|
200
|
-
sendRedditApi,
|
|
201
|
-
reinitRedditWithUserData,
|
|
202
|
-
trackRedditLead,
|
|
203
|
-
trackRedditPurchase,
|
|
204
|
-
trackRedditInitiateCheckout
|
|
205
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Reddit Conversions API Server Template — CDP Edge Quantum Tier
|
|
3
|
+
*
|
|
4
|
+
* Este template contém a função de envio para a Conversions API do Reddit
|
|
5
|
+
* Uso: Incluir no worker.js gerado pelo Server Tracking Agent
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Função principal de envio para Reddit Conversions API
|
|
10
|
+
* @param {Object} env - Variáveis de ambiente do Cloudflare Worker
|
|
11
|
+
* @param {Object} eventData - Dados do evento a ser enviado
|
|
12
|
+
* @returns {Promise<Object>} - Resposta da API
|
|
13
|
+
*/
|
|
14
|
+
export async function sendRedditApi(env, eventData) {
|
|
15
|
+
const { email, phone, userId, clientIp, userAgent, pageUrl,
|
|
16
|
+
eventId, value, currency, itemCount, transactionId } = eventData;
|
|
17
|
+
|
|
18
|
+
// Verificar se as credenciais estão configuradas
|
|
19
|
+
if (!env.REDDIT_ACCESS_TOKEN || !env.REDDIT_AD_ACCOUNT_ID) {
|
|
20
|
+
console.warn('Reddit Conversions API: Credenciais não configuradas');
|
|
21
|
+
return { success: false, error: 'MISSING_CREDENTIALS' };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Função de hash SHA-256
|
|
25
|
+
async function sha256(str) {
|
|
26
|
+
if (!str) return undefined;
|
|
27
|
+
const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(str.toLowerCase().trim()));
|
|
28
|
+
return Array.from(new Uint8Array(buf)).map(b => b.toString(16).padStart(2,'0')).join('');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Mapeamento de eventos CDP Edge → Reddit
|
|
32
|
+
const redditEventMap = {
|
|
33
|
+
'PageView': 'PageVisit',
|
|
34
|
+
'ViewContent': 'ViewContent',
|
|
35
|
+
'Lead': 'Lead',
|
|
36
|
+
'Purchase': 'Purchase',
|
|
37
|
+
'AddToCart': 'AddToCart',
|
|
38
|
+
'CompleteRegistration': 'SignUp',
|
|
39
|
+
'Search': 'Search',
|
|
40
|
+
'InitiateCheckout': 'Purchase', // com conversionType BEGIN_CHECKOUT
|
|
41
|
+
};
|
|
42
|
+
const redditEvent = redditEventMap[eventName] || 'Custom';
|
|
43
|
+
|
|
44
|
+
// user object com SHA256
|
|
45
|
+
const user = {};
|
|
46
|
+
if (email) user.email = { value: await sha256(email) };
|
|
47
|
+
if (phone) user.phoneNumber = { value: await sha256(phone.replace(/\D/g,'')) };
|
|
48
|
+
if (userId) user.externalId = { value: await sha256(userId) };
|
|
49
|
+
if (clientIp) user.ipAddress = { value: clientIp }; // sem hash
|
|
50
|
+
if (userAgent) user.userAgent = { value: userAgent }; // sem hash
|
|
51
|
+
|
|
52
|
+
const event = {
|
|
53
|
+
event_at: new Date().toISOString(),
|
|
54
|
+
event_type: { tracking_type: redditEvent },
|
|
55
|
+
click_id: '', // Reddit click ID (rdt_cid) — se disponível da URL
|
|
56
|
+
event_metadata: {
|
|
57
|
+
currency: currency || 'BRL',
|
|
58
|
+
value_decimal: String(value || 0), // string com decimal
|
|
59
|
+
item_count: String(itemCount || 1),
|
|
60
|
+
transaction_id: transactionId || eventId,
|
|
61
|
+
conversion_id: eventId, // deduplicação
|
|
62
|
+
},
|
|
63
|
+
user,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// Adicionar conversionType para InitiateCheckout
|
|
67
|
+
if (eventName === 'InitiateCheckout') {
|
|
68
|
+
event.event_type.conversion_type = 'BEGIN_CHECKOUT';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const payload = { events: [event] };
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
const resp = await fetch(
|
|
75
|
+
`https://ads-api.reddit.com/api/v2.0/conversions/events/${env.REDDIT_AD_ACCOUNT_ID}`,
|
|
76
|
+
{
|
|
77
|
+
method: 'POST',
|
|
78
|
+
headers: {
|
|
79
|
+
'Content-Type': 'application/json',
|
|
80
|
+
'Authorization': `Bearer ${env.REDDIT_ACCESS_TOKEN}`,
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify(payload),
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
// Resposta de sucesso: { status: 200, message: "Success" }
|
|
87
|
+
if (resp.ok) {
|
|
88
|
+
const result = await resp.json();
|
|
89
|
+
return { success: true, result };
|
|
90
|
+
} else {
|
|
91
|
+
return { success: false, error: `HTTP ${resp.status}` };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error('Reddit Conversions API Error:', error);
|
|
96
|
+
return { success: false, error: error.message };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Função de Advanced Matching — re-inicializa o pixel com dados hasheados
|
|
102
|
+
* @param {Object} userData - Dados do usuário (email, phone, externalId)
|
|
103
|
+
*/
|
|
104
|
+
export function reinitRedditWithUserData(userData) {
|
|
105
|
+
const matchData = {};
|
|
106
|
+
if (userData.email) matchData.email = userData.email; // pixel faz hash
|
|
107
|
+
if (userData.phone) matchData.phoneNumber = userData.phone; // pixel faz hash
|
|
108
|
+
if (userData.externalId) matchData.externalId = userData.externalId;
|
|
109
|
+
|
|
110
|
+
rdt('init', '{REDDIT_PIXEL_ID}', matchData);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Funções de tracking de eventos (browser + server)
|
|
115
|
+
* Uso: Chamadas do tracking.js para eventos Reddit
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Track de Lead
|
|
120
|
+
* @param {Object} data - Dados do formulário
|
|
121
|
+
*/
|
|
122
|
+
export async function trackRedditLead(data = {}) {
|
|
123
|
+
const eventId = generateEventId(); // reutilizar a função do tracking.js
|
|
124
|
+
|
|
125
|
+
// Browser: Reddit Pixel
|
|
126
|
+
if (typeof rdt !== 'undefined') {
|
|
127
|
+
if (data.email || data.phone) reinitRedditWithUserData(data);
|
|
128
|
+
rdt('track', 'Lead', { transactionId: eventId });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Servidor: Conversions API
|
|
132
|
+
await sendToServer('Lead', { ...data, eventId, redditEventId: eventId });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Track de Purchase
|
|
137
|
+
* @param {Object} data - Dados da compra
|
|
138
|
+
*/
|
|
139
|
+
export async function trackRedditPurchase(data = {}) {
|
|
140
|
+
const eventId = generateEventId();
|
|
141
|
+
|
|
142
|
+
if (typeof rdt !== 'undefined')
|
|
143
|
+
rdt('track', 'Purchase', {
|
|
144
|
+
value: data.value || 0,
|
|
145
|
+
currency: data.currency || 'BRL',
|
|
146
|
+
itemCount: data.itemCount ||1,
|
|
147
|
+
transactionId: data.transactionId || eventId,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
await sendToServer('Purchase', { ...data, eventId, redditEventId: eventId });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Track de InitiateCheckout
|
|
155
|
+
* @param {Object} data - Dados do checkout iniciado
|
|
156
|
+
*/
|
|
157
|
+
export async function trackRedditInitiateCheckout(data = {}) {
|
|
158
|
+
const eventId = generateEventId();
|
|
159
|
+
|
|
160
|
+
if (typeof rdt !== 'undefined')
|
|
161
|
+
rdt('track', 'Purchase', {
|
|
162
|
+
conversionType: 'BEGIN_CHECKOUT',
|
|
163
|
+
value: data.value || 0,
|
|
164
|
+
currency: data.currency || 'BRL',
|
|
165
|
+
transactionId: eventId,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
await sendToServer('InitiateCheckout', { ...data, eventId });
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Gerador de Event ID único
|
|
173
|
+
* Reutiliza a função do tracking.js ou gera novo
|
|
174
|
+
*/
|
|
175
|
+
function generateEventId() {
|
|
176
|
+
return crypto.randomUUID ? crypto.randomUUID() :
|
|
177
|
+
Date.now().toString(36) + Math.random().toString(36).slice(2);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Enviar dados para servidor via fetch
|
|
182
|
+
* @param {string} eventName - Nome do evento
|
|
183
|
+
* @param {Object} data - Dados completos do evento
|
|
184
|
+
*/
|
|
185
|
+
async function sendToServer(eventName, data) {
|
|
186
|
+
const serverUrl = '/api/track'; // ou URL configurada
|
|
187
|
+
|
|
188
|
+
await fetch(serverUrl, {
|
|
189
|
+
method: 'POST',
|
|
190
|
+
headers: { 'Content-Type': 'application/json' },
|
|
191
|
+
body: JSON.stringify({
|
|
192
|
+
event_name: eventName,
|
|
193
|
+
platform: 'reddit',
|
|
194
|
+
...data
|
|
195
|
+
})
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export default {
|
|
200
|
+
sendRedditApi,
|
|
201
|
+
reinitRedditWithUserData,
|
|
202
|
+
trackRedditLead,
|
|
203
|
+
trackRedditPurchase,
|
|
204
|
+
trackRedditInitiateCheckout
|
|
205
|
+
};
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
{
|
|
2
|
-
"platform": "reddit",
|
|
3
|
-
"version": "v2.0",
|
|
4
|
-
"event_mappings": {
|
|
5
|
-
"pixel_to_native": {
|
|
6
|
-
"PageView": "PageVisit",
|
|
7
|
-
"ViewContent": "ViewContent",
|
|
8
|
-
"Lead": "Lead",
|
|
9
|
-
"Purchase": "Purchase",
|
|
10
|
-
"AddToCart": "AddToCart",
|
|
11
|
-
"AddToWishlist": "AddToWishlist",
|
|
12
|
-
"InitiateCheckout": "Purchase", // com conversionType: BEGIN_CHECKOUT
|
|
13
|
-
"CompleteRegistration": "SignUp",
|
|
14
|
-
"Search": "Search"
|
|
15
|
-
},
|
|
16
|
-
"native_names": {
|
|
17
|
-
"PageVisit": "Visualização de página",
|
|
18
|
-
"ViewContent": "Visualizar produto/conteúdo",
|
|
19
|
-
"Lead": "Formulário de lead",
|
|
20
|
-
"Purchase": "Compra confirmada",
|
|
21
|
-
"AddToCart": "Adicionar ao carrinho",
|
|
22
|
-
"AddToWishlist": "Adicionar à lista de desejos",
|
|
23
|
-
"SignUp": "Cadastro",
|
|
24
|
-
"Search": "Busca"
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
"required_parameters": {
|
|
28
|
-
"PageVisit": [],
|
|
29
|
-
"ViewContent": ["value", "currency", "itemCount"],
|
|
30
|
-
"Lead": [],
|
|
31
|
-
"Purchase": ["value", "currency", "itemCount", "transactionId"],
|
|
32
|
-
"AddToCart": ["value", "currency", "itemCount"],
|
|
33
|
-
"AddToWishlist": ["value", "currency", "itemCount"],
|
|
34
|
-
"InitiateCheckout": ["value", "currency"],
|
|
35
|
-
"SignUp": [],
|
|
36
|
-
"Search": []
|
|
37
|
-
},
|
|
38
|
-
"optional_parameters": {
|
|
39
|
-
"PageVisit": [],
|
|
40
|
-
"ViewContent": ["customData"],
|
|
41
|
-
"Lead": ["customData"],
|
|
42
|
-
"Purchase": ["customData"],
|
|
43
|
-
"AddToCart": ["customData"],
|
|
44
|
-
"AddToWishlist": ["customData"],
|
|
45
|
-
"InitiateCheckout": ["customData"],
|
|
46
|
-
"SignUp": ["customData"],
|
|
47
|
-
"Search": ["customData"]
|
|
48
|
-
},
|
|
49
|
-
"advanced_matching_fields": {
|
|
50
|
-
"email": "email",
|
|
51
|
-
"phoneNumber": "phoneNumber",
|
|
52
|
-
"externalId": "externalId",
|
|
53
|
-
"ipAddress": "ipAddress",
|
|
54
|
-
"userAgent": "userAgent"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"platform": "reddit",
|
|
3
|
+
"version": "v2.0",
|
|
4
|
+
"event_mappings": {
|
|
5
|
+
"pixel_to_native": {
|
|
6
|
+
"PageView": "PageVisit",
|
|
7
|
+
"ViewContent": "ViewContent",
|
|
8
|
+
"Lead": "Lead",
|
|
9
|
+
"Purchase": "Purchase",
|
|
10
|
+
"AddToCart": "AddToCart",
|
|
11
|
+
"AddToWishlist": "AddToWishlist",
|
|
12
|
+
"InitiateCheckout": "Purchase", // com conversionType: BEGIN_CHECKOUT
|
|
13
|
+
"CompleteRegistration": "SignUp",
|
|
14
|
+
"Search": "Search"
|
|
15
|
+
},
|
|
16
|
+
"native_names": {
|
|
17
|
+
"PageVisit": "Visualização de página",
|
|
18
|
+
"ViewContent": "Visualizar produto/conteúdo",
|
|
19
|
+
"Lead": "Formulário de lead",
|
|
20
|
+
"Purchase": "Compra confirmada",
|
|
21
|
+
"AddToCart": "Adicionar ao carrinho",
|
|
22
|
+
"AddToWishlist": "Adicionar à lista de desejos",
|
|
23
|
+
"SignUp": "Cadastro",
|
|
24
|
+
"Search": "Busca"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"required_parameters": {
|
|
28
|
+
"PageVisit": [],
|
|
29
|
+
"ViewContent": ["value", "currency", "itemCount"],
|
|
30
|
+
"Lead": [],
|
|
31
|
+
"Purchase": ["value", "currency", "itemCount", "transactionId"],
|
|
32
|
+
"AddToCart": ["value", "currency", "itemCount"],
|
|
33
|
+
"AddToWishlist": ["value", "currency", "itemCount"],
|
|
34
|
+
"InitiateCheckout": ["value", "currency"],
|
|
35
|
+
"SignUp": [],
|
|
36
|
+
"Search": []
|
|
37
|
+
},
|
|
38
|
+
"optional_parameters": {
|
|
39
|
+
"PageVisit": [],
|
|
40
|
+
"ViewContent": ["customData"],
|
|
41
|
+
"Lead": ["customData"],
|
|
42
|
+
"Purchase": ["customData"],
|
|
43
|
+
"AddToCart": ["customData"],
|
|
44
|
+
"AddToWishlist": ["customData"],
|
|
45
|
+
"InitiateCheckout": ["customData"],
|
|
46
|
+
"SignUp": ["customData"],
|
|
47
|
+
"Search": ["customData"]
|
|
48
|
+
},
|
|
49
|
+
"advanced_matching_fields": {
|
|
50
|
+
"email": "email",
|
|
51
|
+
"phoneNumber": "phoneNumber",
|
|
52
|
+
"externalId": "externalId",
|
|
53
|
+
"ipAddress": "ipAddress",
|
|
54
|
+
"userAgent": "userAgent"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reddit Pixel Browser Template — CDP Edge Quantum Tier
|
|
3
|
-
*
|
|
4
|
-
* Este template contém o código de inicialização do Reddit Pixel
|
|
5
|
-
* Uso: Incluir no tracking.js gerado pelo Browser Tracking Agent
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export const REDDIT_PIXEL_TEMPLATE = `
|
|
9
|
-
<!-- Reddit Pixel Base Code -->
|
|
10
|
-
<script>
|
|
11
|
-
!function(w,d){if(!w.rdt){var p=w.rdt=function(){p.sendEvent?p.sendEvent.apply(p,arguments):p.callQueue.push(arguments);p.callQueue=[];var t=d.createElement('script');t.src='https://www.redditstatic.com/ads/v2.js',t.async=!0;var s=d.getElementsByTagName('script')[0];s.parentNode.insertBefore(t,s)}}(window,document);
|
|
12
|
-
rdt('init', '{REDDIT_PIXEL_ID}', {
|
|
13
|
-
optOut: false,
|
|
14
|
-
useDecimalCurrencyValues: true,
|
|
15
|
-
email: '', // preencher após captura (hashed automaticamente pelo pixel)
|
|
16
|
-
});
|
|
17
|
-
rdt('track', 'PageVisit');
|
|
18
|
-
</script>
|
|
19
|
-
`;
|
|
1
|
+
/**
|
|
2
|
+
* Reddit Pixel Browser Template — CDP Edge Quantum Tier
|
|
3
|
+
*
|
|
4
|
+
* Este template contém o código de inicialização do Reddit Pixel
|
|
5
|
+
* Uso: Incluir no tracking.js gerado pelo Browser Tracking Agent
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const REDDIT_PIXEL_TEMPLATE = `
|
|
9
|
+
<!-- Reddit Pixel Base Code -->
|
|
10
|
+
<script>
|
|
11
|
+
!function(w,d){if(!w.rdt){var p=w.rdt=function(){p.sendEvent?p.sendEvent.apply(p,arguments):p.callQueue.push(arguments);p.callQueue=[];var t=d.createElement('script');t.src='https://www.redditstatic.com/ads/v2.js',t.async=!0;var s=d.getElementsByTagName('script')[0];s.parentNode.insertBefore(t,s)}}(window,document);
|
|
12
|
+
rdt('init', '{REDDIT_PIXEL_ID}', {
|
|
13
|
+
optOut: false,
|
|
14
|
+
useDecimalCurrencyValues: true,
|
|
15
|
+
email: '', // preencher após captura (hashed automaticamente pelo pixel)
|
|
16
|
+
});
|
|
17
|
+
rdt('track', 'PageVisit');
|
|
18
|
+
</script>
|
|
19
|
+
`;
|