@beworke/pixel 0.1.0-rc.1

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.
Files changed (123) hide show
  1. package/CHANGELOG.md +194 -0
  2. package/README.md +163 -0
  3. package/RELEASE_CANDIDATE.md +256 -0
  4. package/dist/PixelLogger-B21lEjep.d.mts +8 -0
  5. package/dist/PixelLogger-B21lEjep.d.ts +8 -0
  6. package/dist/StorageFactory-BhpbB6Jj.d.mts +8 -0
  7. package/dist/StorageFactory-CAkJJqVD.d.ts +8 -0
  8. package/dist/config/index.cjs.js +3 -0
  9. package/dist/config/index.cjs.js.map +1 -0
  10. package/dist/config/index.d.mts +19 -0
  11. package/dist/config/index.d.ts +19 -0
  12. package/dist/config/index.esm.js +3 -0
  13. package/dist/config/index.esm.js.map +1 -0
  14. package/dist/events/index.cjs.js +3 -0
  15. package/dist/events/index.cjs.js.map +1 -0
  16. package/dist/events/index.d.mts +1 -0
  17. package/dist/events/index.d.ts +1 -0
  18. package/dist/events/index.esm.js +3 -0
  19. package/dist/events/index.esm.js.map +1 -0
  20. package/dist/examples/html-script/README.md +71 -0
  21. package/dist/examples/html-script/RELEASE_CANDIDATE.md +121 -0
  22. package/dist/examples/html-script/add-payment-info/README.md +46 -0
  23. package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-autocomplete.html +494 -0
  24. package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-disabled.html +478 -0
  25. package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-fields.html +486 -0
  26. package/dist/examples/html-script/add-payment-info/example-add-payment-info-data-track.html +479 -0
  27. package/dist/examples/html-script/add-payment-info/example-add-payment-info-dedupe.html +492 -0
  28. package/dist/examples/html-script/add-payment-info/example-add-payment-info-manual.html +495 -0
  29. package/dist/examples/html-script/add-payment-info/example-add-payment-info-rules-card.html +469 -0
  30. package/dist/examples/html-script/add-payment-info/example-add-payment-info-security.html +489 -0
  31. package/dist/examples/html-script/add-to-cart/README.md +36 -0
  32. package/dist/examples/html-script/add-to-cart/example-add-to-cart-attribute.html +517 -0
  33. package/dist/examples/html-script/add-to-cart/example-add-to-cart-auto.html +512 -0
  34. package/dist/examples/html-script/add-to-cart/example-add-to-cart-click.html +519 -0
  35. package/dist/examples/html-script/add-to-cart/example-add-to-cart-dedupe.html +514 -0
  36. package/dist/examples/html-script/add-to-cart/example-add-to-cart-manual.html +517 -0
  37. package/dist/examples/html-script/add-to-cart/example-add-to-cart-order-bump.html +527 -0
  38. package/dist/examples/html-script/add-to-cart/example-add-to-cart-text.html +524 -0
  39. package/dist/examples/html-script/example-basic.html +350 -0
  40. package/dist/examples/html-script/example-behavior.html +435 -0
  41. package/dist/examples/html-script/example-conversion.html +479 -0
  42. package/dist/examples/html-script/example-integration.html +709 -0
  43. package/dist/examples/html-script/example-transport.html +748 -0
  44. package/dist/examples/html-script/initiate-checkout/README.md +38 -0
  45. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-attribute.html +485 -0
  46. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-auto.html +491 -0
  47. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-click.html +493 -0
  48. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-manual.html +494 -0
  49. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-snapshot.html +497 -0
  50. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-submit.html +502 -0
  51. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-text.html +496 -0
  52. package/dist/examples/html-script/lead/README.md +25 -0
  53. package/dist/examples/html-script/lead/example-lead-trigger-attribute.html +594 -0
  54. package/dist/examples/html-script/lead/example-lead-trigger-auto.html +431 -0
  55. package/dist/examples/html-script/lead/example-lead-trigger-click.html +587 -0
  56. package/dist/examples/html-script/release-candidate.html +726 -0
  57. package/dist/examples/html-script/remove-from-cart/README.md +36 -0
  58. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-attribute.html +532 -0
  59. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-css.html +524 -0
  60. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-dedupe.html +540 -0
  61. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-manual.html +533 -0
  62. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-multi.html +557 -0
  63. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-state.html +539 -0
  64. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-text.html +524 -0
  65. package/dist/examples/html-script/search/README.md +41 -0
  66. package/dist/examples/html-script/search/example-search-attribute.html +454 -0
  67. package/dist/examples/html-script/search/example-search-button-sync.html +455 -0
  68. package/dist/examples/html-script/search/example-search-dedupe.html +466 -0
  69. package/dist/examples/html-script/search/example-search-input.html +456 -0
  70. package/dist/examples/html-script/search/example-search-manual.html +473 -0
  71. package/dist/examples/html-script/search/example-search-submit.html +450 -0
  72. package/dist/examples/html-script/search/example-search-text.html +441 -0
  73. package/dist/examples/html-script/view-content/README.md +48 -0
  74. package/dist/examples/html-script/view-content/example-view-content-attribute.html +488 -0
  75. package/dist/examples/html-script/view-content/example-view-content-css.html +467 -0
  76. package/dist/examples/html-script/view-content/example-view-content-dedupe.html +485 -0
  77. package/dist/examples/html-script/view-content/example-view-content-empty.html +469 -0
  78. package/dist/examples/html-script/view-content/example-view-content-manual.html +496 -0
  79. package/dist/examples/html-script/view-content/example-view-content-product-card.html +478 -0
  80. package/dist/examples/html-script/view-content/example-view-content-text.html +473 -0
  81. package/dist/examples/release-candidate/README.md +14 -0
  82. package/dist/examples/v2/README.md +33 -0
  83. package/dist/index-DUfFzniE.d.mts +274 -0
  84. package/dist/index-DUfFzniE.d.ts +274 -0
  85. package/dist/index.cjs.js +3 -0
  86. package/dist/index.cjs.js.map +1 -0
  87. package/dist/index.d.mts +364 -0
  88. package/dist/index.d.ts +364 -0
  89. package/dist/index.esm.js +3 -0
  90. package/dist/index.esm.js.map +1 -0
  91. package/dist/logger/index.cjs.js +3 -0
  92. package/dist/logger/index.cjs.js.map +1 -0
  93. package/dist/logger/index.d.mts +12 -0
  94. package/dist/logger/index.d.ts +12 -0
  95. package/dist/logger/index.esm.js +3 -0
  96. package/dist/logger/index.esm.js.map +1 -0
  97. package/dist/pixel-CbeF25mD.d.mts +555 -0
  98. package/dist/pixel-CbeF25mD.d.ts +555 -0
  99. package/dist/pixel-default-config-1VgLFOiL.d.mts +5 -0
  100. package/dist/pixel-default-config-Bxb-Vdd8.d.ts +5 -0
  101. package/dist/runtime/index.cjs.js +3 -0
  102. package/dist/runtime/index.cjs.js.map +1 -0
  103. package/dist/runtime/index.d.mts +48 -0
  104. package/dist/runtime/index.d.ts +48 -0
  105. package/dist/runtime/index.esm.js +3 -0
  106. package/dist/runtime/index.esm.js.map +1 -0
  107. package/dist/services/index.cjs.js +3 -0
  108. package/dist/services/index.cjs.js.map +1 -0
  109. package/dist/services/index.d.mts +169 -0
  110. package/dist/services/index.d.ts +169 -0
  111. package/dist/services/index.esm.js +3 -0
  112. package/dist/services/index.esm.js.map +1 -0
  113. package/dist/types-CTpRvFKZ.d.ts +71 -0
  114. package/dist/types-DGlBdsAy.d.mts +71 -0
  115. package/dist/v2/global.global.js +3 -0
  116. package/dist/v2/global.global.js.map +1 -0
  117. package/dist/v2/index.cjs.js +3 -0
  118. package/dist/v2/index.cjs.js.map +1 -0
  119. package/dist/v2/index.d.mts +7 -0
  120. package/dist/v2/index.d.ts +7 -0
  121. package/dist/v2/index.esm.js +3 -0
  122. package/dist/v2/index.esm.js.map +1 -0
  123. package/package.json +101 -0
@@ -0,0 +1,524 @@
1
+ <!doctype html>
2
+ <html lang="pt-BR">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Pixel v2 — ADD_TO_CART text selector</title>
7
+ <style>
8
+ :root {
9
+ --bg: #f8fafc; --card: #fff; --border: #e2e8f0; --text: #0f172a;
10
+ --muted: #64748b; --accent: #0f766e; --accent-soft: #ccfbf1;
11
+ --warn: #9a3412; --warn-soft: #ffedd5;
12
+ }
13
+ * { box-sizing: border-box; }
14
+ body {
15
+ margin: 0;
16
+ font-family: "Segoe UI", system-ui, sans-serif;
17
+ background:
18
+ radial-gradient(circle at top left, #ecfeff 0%, transparent 40%),
19
+ linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
20
+ color: var(--text); line-height: 1.45;
21
+ }
22
+ .wrap { max-width: 980px; margin: 0 auto; padding: 1.5rem; }
23
+ h1 { font-size: 1.5rem; margin: 0 0 0.35rem; letter-spacing: -0.02em; }
24
+ h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
25
+ .sub { color: var(--muted); margin: 0 0 1rem; font-size: 0.92rem; }
26
+ .nav { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
27
+ .nav a {
28
+ text-decoration: none; border: 1px solid var(--border); background: #fff;
29
+ color: var(--text); border-radius: 999px; padding: 0.3rem 0.7rem; font-size: 0.78rem;
30
+ }
31
+ .nav a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
32
+ .grid { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 1rem; }
33
+ @media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }
34
+ .card {
35
+ background: var(--card); border: 1px solid var(--border); border-radius: 12px;
36
+ padding: 1rem; margin-bottom: 1rem; box-shadow: 0 1px 0 rgba(15,23,42,.03);
37
+ }
38
+ .hint {
39
+ background: var(--accent-soft); border: 1px solid #99f6e4; border-radius: 10px;
40
+ padding: 0.85rem 1rem; font-size: 0.9rem; margin-bottom: 1rem;
41
+ }
42
+ .hint.warn { background: var(--warn-soft); border-color: #fdba74; color: var(--warn); }
43
+ .actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
44
+ button {
45
+ appearance: none; border: 1px solid var(--border); background: #fff; color: var(--text);
46
+ border-radius: 8px; padding: 0.5rem 0.85rem; cursor: pointer; font: inherit;
47
+ }
48
+ button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
49
+ button.danger { background: #7f1d1d; border-color: #7f1d1d; color: #fff; }
50
+ button:disabled { opacity: 0.55; cursor: not-allowed; }
51
+ label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; }
52
+ input {
53
+ width: 100%; border: 1px solid var(--border); border-radius: 8px;
54
+ padding: 0.55rem 0.7rem; font: inherit; background: #fff;
55
+ }
56
+ .row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
57
+ @media (max-width: 560px) { .row { grid-template-columns: 1fr; } }
58
+ .status, pre {
59
+ background: #0f172a; color: #e2e8f0; border-radius: 8px; padding: 0.75rem;
60
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
61
+ font-size: 0.78rem; white-space: pre-wrap; word-break: break-word;
62
+ max-height: 260px; overflow: auto;
63
+ }
64
+ .pill {
65
+ display: inline-block; border-radius: 999px; padding: 0.15rem 0.55rem;
66
+ font-size: 0.72rem; background: #e2e8f0; color: #334155; margin-left: 0.35rem;
67
+ }
68
+ .pill.ok { background: #bbf7d0; color: #166534; }
69
+ .checklist { margin: 0; padding-left: 1.1rem; font-size: 0.88rem; color: var(--muted); }
70
+ .checklist li { margin: 0.35rem 0; }
71
+ .ctx {
72
+ border-left: 3px solid var(--accent); padding-left: 0.75rem; margin-bottom: 0.85rem;
73
+ color: var(--muted); font-size: 0.88rem;
74
+ }
75
+ .product {
76
+ border: 1px dashed var(--border); border-radius: 10px; padding: 0.75rem; margin: 0.5rem 0;
77
+ }
78
+ .product strong { display: block; margin-bottom: 0.2rem; }
79
+ code { font-size: 0.85em; }
80
+ </style>
81
+ </head>
82
+ <body>
83
+ <div class="wrap">
84
+ <h1>ADD_TO_CART — text:Comprar agora</h1>
85
+ <p class="sub">
86
+ Cenário isolado para validação do Pixel v2.
87
+ <span class="pill" id="init-pill">offline</span>
88
+ </p>
89
+ <div class="nav"><a href="example-add-to-cart-attribute.html" class="">1. Atributo</a>
90
+ <a href="example-add-to-cart-click.html" class="">2. Click+Form</a>
91
+ <a href="example-add-to-cart-auto.html" class="">3. Auto+Form</a>
92
+ <a href="example-add-to-cart-text.html" class="active">4. Text</a>
93
+ <a href="example-add-to-cart-manual.html" class="">5. Manual API</a>
94
+ <a href="example-add-to-cart-dedupe.html" class="">6. Dedupe</a>
95
+ <a href="example-add-to-cart-order-bump.html" class="">7. Order bump</a></div>
96
+ <div class="hint"><strong>Contexto:</strong> CTA sem <code>data-track</code>, só texto visível.
97
+ Selector <code>text:Comprar agora</code>. Produto via <code>data-product-id</code>
98
+ no botão + catálogo. Com <code>selectorForm</code> exigindo contato.</div>
99
+
100
+ <div class="card">
101
+ <h2>Lifecycle</h2>
102
+ <div class="actions">
103
+ <button id="btn-reinit" class="primary" type="button">Reinitialize</button>
104
+ <button id="btn-destroy" class="danger" type="button">Destroy</button>
105
+ <button id="btn-clear" type="button">Clear logs</button>
106
+ </div>
107
+ <div class="status" id="runtime-status">Aguardando init...</div>
108
+ </div>
109
+
110
+ <div class="grid">
111
+ <div>
112
+ <div class="card">
113
+ <h2>CTA por texto <span class="pill">text: + selectorForm</span></h2>
114
+ <div class="ctx">Botão sem data-track — match por texto do label.</div>
115
+ <form id="buy-now-form">
116
+ <div class="row">
117
+ <div>
118
+ <label for="bn-email">Email</label>
119
+ <input id="bn-email" name="email" type="email" placeholder="buy@test.com" />
120
+ </div>
121
+ <div>
122
+ <label for="bn-phone">Phone</label>
123
+ <input id="bn-phone" name="phone" type="tel" placeholder="11966665555" />
124
+ </div>
125
+ </div>
126
+ <div class="product">
127
+ <strong>Order Bump Especial — R$ 47</strong>
128
+ <div class="actions">
129
+ <button
130
+ type="button"
131
+ class="primary"
132
+ data-product-id="order_bump_01"
133
+ >
134
+ Comprar agora
135
+ </button>
136
+ <button type="button" id="btn-other-text">Outro texto</button>
137
+ </div>
138
+ </div>
139
+ </form>
140
+ <p class="sub">
141
+ Sem form ok → não dispara. Texto diferente → não dispara.
142
+ </p>
143
+ </div>
144
+ <div class="card">
145
+ <h2>Checklist</h2>
146
+ <ul class="checklist">
147
+ <li>[ ] Form incompleto + Comprar agora → não dispara</li>
148
+ <li>[ ] Form ok + Comprar agora → <code>ADD_TO_CART</code> bump</li>
149
+ <li>[ ] Botão “Outro texto” → não dispara</li>
150
+ <li>[ ] productId do atributo + enrich catalog</li>
151
+ </ul>
152
+ </div>
153
+ </div>
154
+ <div>
155
+ <div class="card">
156
+ <h2>Event counts</h2>
157
+ <div class="status" id="event-counts">Nenhum evento ainda</div>
158
+ </div>
159
+ <div class="card">
160
+ <h2>Cart mirror (via eventos)</h2>
161
+ <div class="status" id="cart-mirror">{}</div>
162
+ </div>
163
+ <div class="card">
164
+ <h2>Active detectors</h2>
165
+ <div class="status" id="detectors">—</div>
166
+ </div>
167
+
168
+ <div class="card">
169
+ <h2>Last event JSON</h2>
170
+ <pre id="last-event">null</pre>
171
+ </div>
172
+ <div class="card">
173
+ <h2>Event log</h2>
174
+ <pre id="logs">Aguardando eventos...</pre>
175
+ </div>
176
+ </div>
177
+ </div>
178
+ </div>
179
+
180
+ <script src="../../../dist/v2/global.global.js"></script>
181
+ <script>
182
+ const { Pixel, DEFAULT_PIXEL_CONFIG } = window.PixelV2;
183
+ const API_ENDPOINT =
184
+ 'https://micro-service-pixel-production-4826.up.railway.app';
185
+ const PIXEL_ID = 'pix_7315610';
186
+
187
+ const els = {
188
+ logs: document.getElementById('logs'),
189
+ last: document.getElementById('last-event'),
190
+ counts: document.getElementById('event-counts'),
191
+ cart: document.getElementById('cart-mirror'),
192
+ detectors: document.getElementById('detectors'),
193
+ dedupe: document.getElementById('dedupe-keys'),
194
+ runtime: document.getElementById('runtime-status'),
195
+ pill: document.getElementById('init-pill'),
196
+ };
197
+
198
+ let pixel = null;
199
+ let unsubscribe = null;
200
+ let initCount = 0;
201
+ let destroyCount = 0;
202
+ const counts = {};
203
+ const cartMirror = {};
204
+
205
+ function addToCartDetectorConfig() {
206
+ return {
207
+ enabled: true,
208
+ selector: [
209
+ 'text:Comprar agora',
210
+ { type: 'text', value: 'Comprar agora' },
211
+ ],
212
+ selectorType: 'css',
213
+ selectorForm: {
214
+ fields: ['email', 'phone'],
215
+ mode: 'all',
216
+ formSelector: '#buy-now-form',
217
+ trigger: 'click',
218
+ debounceMs: 0,
219
+ fireOnce: false,
220
+ },
221
+ };
222
+ }
223
+
224
+ function buildConfig() {
225
+ const base = DEFAULT_PIXEL_CONFIG;
226
+ return {
227
+ ...base,
228
+ app: {
229
+ ...base.app,
230
+ source: 'custom',
231
+ environment: 'development',
232
+ debug: true,
233
+ },
234
+ transport: {
235
+ ...DEFAULT_PIXEL_CONFIG.transport,
236
+ apiEndpoint: API_ENDPOINT,
237
+ timeoutMs: 10000,
238
+ },
239
+ identity: { ...base.identity, pixelId: PIXEL_ID },
240
+ modules: {
241
+ ...base.modules,
242
+ core: {
243
+ ...base.modules.core,
244
+ enabled: false,
245
+ pageView: {
246
+ ...base.modules.core.pageView,
247
+ enabled: false,
248
+ trackInitialPageView: false,
249
+ spa: false,
250
+ },
251
+ },
252
+ behavior: { ...base.modules.behavior, enabled: false },
253
+ privacy: { ...base.modules.privacy, enabled: false },
254
+ transport: {
255
+ enabled: true,
256
+ mockSender: { enabled: false },
257
+ sender: { mode: 'http' },
258
+ persistence: { enabled: true },
259
+ replay: { enabled: true },
260
+ ordering: { enabled: true },
261
+ coordination: { enabled: true },
262
+ circuitBreaker: {
263
+ enabled: true,
264
+ failureThreshold: 5,
265
+ resetTimeoutMs: 30000,
266
+ halfOpenMaxAttempts: 2,
267
+ },
268
+ backpressure: {
269
+ enabled: true,
270
+ maxQueueSize: 500,
271
+ policy: 'drop_oldest',
272
+ sampleRate: 0.5,
273
+ },
274
+ deadLetter: { enabled: true, maxEntries: 200 },
275
+ compression: { enabled: true, strategy: 'identity' },
276
+ retry: {
277
+ enabled: true,
278
+ maxAttempts: 4,
279
+ baseDelayMs: 500,
280
+ maxDelayMs: 4000,
281
+ multiplier: 2,
282
+ },
283
+ batch: {
284
+ enabled: true,
285
+ batchSize: 10,
286
+ flushIntervalMs: 2000,
287
+ maxWaitMs: 5000,
288
+ },
289
+ timeout: { enabled: true, timeoutMs: 10000 },
290
+ offline: { enabled: true },
291
+ flush: {
292
+ enabled: true,
293
+ flushIntervalMs: 2000,
294
+ flushOnDestroy: true,
295
+ prepareUnloadHooks: true,
296
+ },
297
+ },
298
+ integrations: { ...base.modules.integrations, enabled: false },
299
+ conversion: {
300
+ enabled: true,
301
+ commerce: {
302
+ currency: 'BRL',
303
+ catalog: { products: [
304
+ {
305
+ id: 'main_offer',
306
+ name: 'Oferta Principal',
307
+ type: 'main',
308
+ price: 197,
309
+ currency: 'BRL',
310
+ quantity: 1,
311
+ },
312
+ {
313
+ id: 'order_bump_01',
314
+ name: 'Order Bump Especial',
315
+ type: 'order_bump',
316
+ price: 47,
317
+ currency: 'BRL',
318
+ quantity: 1,
319
+ },
320
+ {
321
+ id: 'upsell_01',
322
+ name: 'Upsell 01',
323
+ type: 'upsell',
324
+ price: 97,
325
+ currency: 'BRL',
326
+ quantity: 1,
327
+ },
328
+ ] },
329
+ checkout: {
330
+ mode: 'single_product',
331
+ selectedItems: [],
332
+ calculateValueFrom: 'selected_items',
333
+ allowDynamicItems: true,
334
+ },
335
+ mappings: {
336
+ attributes: {
337
+ productId: ['data-product-id', 'data-sku', 'data-offer-id'],
338
+ productName: ['data-product-name', 'data-name'],
339
+ price: ['data-product-price', 'data-price'],
340
+ quantity: ['data-quantity', 'data-qty'],
341
+ currency: ['data-currency'],
342
+ },
343
+ fields: {
344
+ productId: ['productId', 'product_id', 'offerId', 'sku'],
345
+ productName: ['productName', 'product_name'],
346
+ price: ['price', 'amount'],
347
+ quantity: ['quantity', 'qty'],
348
+ currency: ['currency'],
349
+ email: ['email', 'customerEmail'],
350
+ phone: ['phone', 'telefone', 'customerPhone'],
351
+ },
352
+ },
353
+ },
354
+ manual: {
355
+ pageView: { enabled: false },
356
+ purchase: { enabled: false },
357
+ lead: { enabled: false },
358
+ addToCart: { enabled: true },
359
+ removeFromCart: { enabled: true },
360
+ initiateCheckout: { enabled: false },
361
+ addPaymentInfo: { enabled: false },
362
+ search: { enabled: false },
363
+ viewContent: { enabled: false },
364
+ },
365
+ auto: {
366
+ enabled: true,
367
+ detectors: {
368
+ lead: { enabled: false },
369
+ purchase: { enabled: false },
370
+ addToCart: addToCartDetectorConfig(),
371
+ removeFromCart: { enabled: false },
372
+ initiateCheckout: { enabled: false },
373
+ addPaymentInfo: { enabled: false },
374
+ search: { enabled: false },
375
+ viewContent: { enabled: false },
376
+ },
377
+ },
378
+ rules: {
379
+ enabled: false,
380
+ selectors: [],
381
+ texts: [],
382
+ urlPatterns: [],
383
+ checkout: { enabled: false },
384
+ card: { enabled: false },
385
+ },
386
+ },
387
+ },
388
+ };
389
+ }
390
+
391
+ function appendLog(message) {
392
+ const line = '[' + new Date().toISOString() + '] ' + message;
393
+ const prev = els.logs.textContent;
394
+ els.logs.textContent =
395
+ prev === 'Aguardando eventos...' ? line : line + '\n' + prev;
396
+ }
397
+
398
+ function renderCounts() {
399
+ const lines = Object.keys(counts)
400
+ .sort()
401
+ .map(function (type) { return type + ': ' + counts[type]; });
402
+ els.counts.textContent =
403
+ lines.length > 0 ? lines.join('\n') : 'Nenhum evento ainda';
404
+ }
405
+
406
+ function renderCart() {
407
+ if (!els.cart) return;
408
+ els.cart.textContent = JSON.stringify(cartMirror, null, 2);
409
+ }
410
+
411
+ function renderDebug() {
412
+ const detectors =
413
+ pixel && pixel.getDebugActiveDetectors
414
+ ? pixel.getDebugActiveDetectors()
415
+ : [];
416
+ els.detectors.textContent =
417
+ detectors.length > 0 ? detectors.join('\n') : 'Nenhum detector ativo';
418
+ if (els.dedupe) {
419
+ const keys =
420
+ pixel && pixel.getDebugDedupeKeys ? pixel.getDebugDedupeKeys() : [];
421
+ els.dedupe.textContent =
422
+ keys.length > 0 ? keys.join('\n') : 'Nenhuma chave';
423
+ }
424
+ els.runtime.textContent =
425
+ 'initialized: ' +
426
+ (pixel ? pixel.isInitialized() : false) +
427
+ '\ninit count: ' +
428
+ initCount +
429
+ '\ndestroy count: ' +
430
+ destroyCount +
431
+ '\npixelId: ' +
432
+ PIXEL_ID +
433
+ '\nscenario: text:Comprar agora';
434
+ els.pill.textContent =
435
+ pixel && pixel.isInitialized() ? 'ready' : 'offline';
436
+ els.pill.className =
437
+ 'pill' + (pixel && pixel.isInitialized() ? ' ok' : '');
438
+ }
439
+
440
+ function updateCartFromEvent(event) {
441
+ if (
442
+ event.type === 'ADD_TO_CART' &&
443
+ event.data &&
444
+ event.data.productId
445
+ ) {
446
+ cartMirror[event.data.productId] = {
447
+ productId: event.data.productId,
448
+ productName: event.data.productName,
449
+ price: event.data.price,
450
+ currency: event.data.currency,
451
+ quantity: event.data.quantity != null ? event.data.quantity : 1,
452
+ };
453
+ }
454
+ if (
455
+ event.type === 'REMOVE_FROM_CART' &&
456
+ event.data &&
457
+ event.data.productId
458
+ ) {
459
+ delete cartMirror[event.data.productId];
460
+ }
461
+ renderCart();
462
+ }
463
+
464
+ function onEvent(event) {
465
+ counts[event.type] = (counts[event.type] || 0) + 1;
466
+ renderCounts();
467
+ updateCartFromEvent(event);
468
+ els.last.textContent = JSON.stringify(event, null, 2);
469
+ appendLog(event.type + ' ' + JSON.stringify(event.data || {}));
470
+ renderDebug();
471
+ }
472
+
473
+ async function boot() {
474
+ if (unsubscribe) { unsubscribe(); unsubscribe = null; }
475
+ if (pixel) {
476
+ await pixel.destroy();
477
+ destroyCount += 1;
478
+ pixel = null;
479
+ }
480
+ Object.keys(cartMirror).forEach(function (k) { delete cartMirror[k]; });
481
+ renderCart();
482
+ pixel = new Pixel(buildConfig());
483
+ await pixel.init();
484
+ initCount += 1;
485
+ const services = pixel.getDebugServices();
486
+ if (services && services.dispatcher) {
487
+ unsubscribe = services.dispatcher.subscribe(onEvent);
488
+ }
489
+ appendLog('Pixel initialized — text:Comprar agora');
490
+ renderDebug();
491
+ }
492
+
493
+ async function destroyPixel() {
494
+ if (unsubscribe) { unsubscribe(); unsubscribe = null; }
495
+ if (pixel) {
496
+ await pixel.destroy();
497
+ destroyCount += 1;
498
+ pixel = null;
499
+ }
500
+ appendLog('Pixel destroyed');
501
+ renderDebug();
502
+ }
503
+
504
+ document.getElementById('btn-reinit').onclick = function () { boot(); };
505
+ document.getElementById('btn-destroy').onclick = function () { destroyPixel(); };
506
+ document.getElementById('btn-clear').onclick = function () {
507
+ els.logs.textContent = 'Aguardando eventos...';
508
+ els.last.textContent = 'null';
509
+ Object.keys(counts).forEach(function (k) { delete counts[k]; });
510
+ Object.keys(cartMirror).forEach(function (k) { delete cartMirror[k]; });
511
+ renderCounts();
512
+ renderCart();
513
+ };
514
+
515
+
516
+ document.getElementById('btn-other-text').onclick = function () {
517
+ appendLog('(playground) texto diferente — esperado: nenhum ADD_TO_CART');
518
+ };
519
+
520
+
521
+ boot();
522
+ </script>
523
+ </body>
524
+ </html>