@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,512 @@
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 auto + selectorForm</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 — trigger: auto · selectorForm</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="active">3. Auto+Form</a>
92
+ <a href="example-add-to-cart-text.html" class="">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> ao completar contato no checkout, dispara
97
+ <code>ADD_TO_CART</code> automaticamente (input/change) com produto de
98
+ <code>selectedItems</code> / catálogo. <code>fireOnce: true</code>.</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>Contato → add automático <span class="pill">selectorForm · auto</span></h2>
114
+ <div class="ctx">
115
+ selectedItems já tem <code>main_offer</code>. Completar email+phone
116
+ dispara o add sem clicar.
117
+ </div>
118
+ <form id="checkout-contact-form">
119
+ <div class="row">
120
+ <div>
121
+ <label for="auto-email">Email</label>
122
+ <input id="auto-email" name="email" type="email" placeholder="auto@test.com" />
123
+ </div>
124
+ <div>
125
+ <label for="auto-phone">Phone</label>
126
+ <input id="auto-phone" name="phone" type="tel" placeholder="11977776666" />
127
+ </div>
128
+ </div>
129
+ <div class="actions">
130
+ <button type="button" disabled>Continuar (demo)</button>
131
+ </div>
132
+ </form>
133
+ <p class="sub">
134
+ Preencha o 2º campo → <code>ADD_TO_CART</code> sozinho.
135
+ Continuar digitando → não duplica (<code>fireOnce</code>).
136
+ </p>
137
+ </div>
138
+ <div class="card">
139
+ <h2>Checklist</h2>
140
+ <ul class="checklist">
141
+ <li>[ ] Só email → não dispara</li>
142
+ <li>[ ] Só phone → não dispara</li>
143
+ <li>[ ] Ambos via input → <code>ADD_TO_CART</code> automático</li>
144
+ <li>[ ] Payload enriquecido (catalog / selectedItems)</li>
145
+ <li>[ ] fireOnce impede duplicata</li>
146
+ </ul>
147
+ </div>
148
+ </div>
149
+ <div>
150
+ <div class="card">
151
+ <h2>Event counts</h2>
152
+ <div class="status" id="event-counts">Nenhum evento ainda</div>
153
+ </div>
154
+ <div class="card">
155
+ <h2>Cart mirror (via eventos)</h2>
156
+ <div class="status" id="cart-mirror">{}</div>
157
+ </div>
158
+ <div class="card">
159
+ <h2>Active detectors</h2>
160
+ <div class="status" id="detectors">—</div>
161
+ </div>
162
+
163
+ <div class="card">
164
+ <h2>Last event JSON</h2>
165
+ <pre id="last-event">null</pre>
166
+ </div>
167
+ <div class="card">
168
+ <h2>Event log</h2>
169
+ <pre id="logs">Aguardando eventos...</pre>
170
+ </div>
171
+ </div>
172
+ </div>
173
+ </div>
174
+
175
+ <script src="../../../dist/v2/global.global.js"></script>
176
+ <script>
177
+ const { Pixel, DEFAULT_PIXEL_CONFIG } = window.PixelV2;
178
+ const API_ENDPOINT =
179
+ 'https://micro-service-pixel-production-4826.up.railway.app';
180
+ const PIXEL_ID = 'pix_7315610';
181
+
182
+ const els = {
183
+ logs: document.getElementById('logs'),
184
+ last: document.getElementById('last-event'),
185
+ counts: document.getElementById('event-counts'),
186
+ cart: document.getElementById('cart-mirror'),
187
+ detectors: document.getElementById('detectors'),
188
+ dedupe: document.getElementById('dedupe-keys'),
189
+ runtime: document.getElementById('runtime-status'),
190
+ pill: document.getElementById('init-pill'),
191
+ };
192
+
193
+ let pixel = null;
194
+ let unsubscribe = null;
195
+ let initCount = 0;
196
+ let destroyCount = 0;
197
+ const counts = {};
198
+ const cartMirror = {};
199
+
200
+ function addToCartDetectorConfig() {
201
+ return {
202
+ enabled: true,
203
+ selector: ['#checkout-contact-form'],
204
+ selectorType: 'css',
205
+ selectorForm: {
206
+ fields: ['email', 'phone'],
207
+ mode: 'all',
208
+ formSelector: '#checkout-contact-form',
209
+ trigger: 'auto',
210
+ debounceMs: 300,
211
+ fireOnce: true,
212
+ },
213
+ };
214
+ }
215
+
216
+ function buildConfig() {
217
+ const base = DEFAULT_PIXEL_CONFIG;
218
+ return {
219
+ ...base,
220
+ app: {
221
+ ...base.app,
222
+ source: 'custom',
223
+ environment: 'development',
224
+ debug: true,
225
+ },
226
+ transport: {
227
+ ...DEFAULT_PIXEL_CONFIG.transport,
228
+ apiEndpoint: API_ENDPOINT,
229
+ timeoutMs: 10000,
230
+ },
231
+ identity: { ...base.identity, pixelId: PIXEL_ID },
232
+ modules: {
233
+ ...base.modules,
234
+ core: {
235
+ ...base.modules.core,
236
+ enabled: false,
237
+ pageView: {
238
+ ...base.modules.core.pageView,
239
+ enabled: false,
240
+ trackInitialPageView: false,
241
+ spa: false,
242
+ },
243
+ },
244
+ behavior: { ...base.modules.behavior, enabled: false },
245
+ privacy: { ...base.modules.privacy, enabled: false },
246
+ transport: {
247
+ enabled: true,
248
+ mockSender: { enabled: false },
249
+ sender: { mode: 'http' },
250
+ persistence: { enabled: true },
251
+ replay: { enabled: true },
252
+ ordering: { enabled: true },
253
+ coordination: { enabled: true },
254
+ circuitBreaker: {
255
+ enabled: true,
256
+ failureThreshold: 5,
257
+ resetTimeoutMs: 30000,
258
+ halfOpenMaxAttempts: 2,
259
+ },
260
+ backpressure: {
261
+ enabled: true,
262
+ maxQueueSize: 500,
263
+ policy: 'drop_oldest',
264
+ sampleRate: 0.5,
265
+ },
266
+ deadLetter: { enabled: true, maxEntries: 200 },
267
+ compression: { enabled: true, strategy: 'identity' },
268
+ retry: {
269
+ enabled: true,
270
+ maxAttempts: 4,
271
+ baseDelayMs: 500,
272
+ maxDelayMs: 4000,
273
+ multiplier: 2,
274
+ },
275
+ batch: {
276
+ enabled: true,
277
+ batchSize: 10,
278
+ flushIntervalMs: 2000,
279
+ maxWaitMs: 5000,
280
+ },
281
+ timeout: { enabled: true, timeoutMs: 10000 },
282
+ offline: { enabled: true },
283
+ flush: {
284
+ enabled: true,
285
+ flushIntervalMs: 2000,
286
+ flushOnDestroy: true,
287
+ prepareUnloadHooks: true,
288
+ },
289
+ },
290
+ integrations: { ...base.modules.integrations, enabled: false },
291
+ conversion: {
292
+ enabled: true,
293
+ commerce: {
294
+ currency: 'BRL',
295
+ catalog: { products: [
296
+ {
297
+ id: 'main_offer',
298
+ name: 'Oferta Principal',
299
+ type: 'main',
300
+ price: 197,
301
+ currency: 'BRL',
302
+ quantity: 1,
303
+ },
304
+ {
305
+ id: 'order_bump_01',
306
+ name: 'Order Bump Especial',
307
+ type: 'order_bump',
308
+ price: 47,
309
+ currency: 'BRL',
310
+ quantity: 1,
311
+ },
312
+ {
313
+ id: 'upsell_01',
314
+ name: 'Upsell 01',
315
+ type: 'upsell',
316
+ price: 97,
317
+ currency: 'BRL',
318
+ quantity: 1,
319
+ },
320
+ ] },
321
+ checkout: {
322
+ mode: 'single_product',
323
+ selectedItems: [{ productId: "main_offer", quantity: 1 }],
324
+ calculateValueFrom: 'selected_items',
325
+ allowDynamicItems: true,
326
+ },
327
+ mappings: {
328
+ attributes: {
329
+ productId: ['data-product-id', 'data-sku', 'data-offer-id'],
330
+ productName: ['data-product-name', 'data-name'],
331
+ price: ['data-product-price', 'data-price'],
332
+ quantity: ['data-quantity', 'data-qty'],
333
+ currency: ['data-currency'],
334
+ },
335
+ fields: {
336
+ productId: ['productId', 'product_id', 'offerId', 'sku'],
337
+ productName: ['productName', 'product_name'],
338
+ price: ['price', 'amount'],
339
+ quantity: ['quantity', 'qty'],
340
+ currency: ['currency'],
341
+ email: ['email', 'customerEmail'],
342
+ phone: ['phone', 'telefone', 'customerPhone'],
343
+ },
344
+ },
345
+ },
346
+ manual: {
347
+ pageView: { enabled: false },
348
+ purchase: { enabled: false },
349
+ lead: { enabled: false },
350
+ addToCart: { enabled: true },
351
+ removeFromCart: { enabled: true },
352
+ initiateCheckout: { enabled: false },
353
+ addPaymentInfo: { enabled: false },
354
+ search: { enabled: false },
355
+ viewContent: { enabled: false },
356
+ },
357
+ auto: {
358
+ enabled: true,
359
+ detectors: {
360
+ lead: { enabled: false },
361
+ purchase: { enabled: false },
362
+ addToCart: addToCartDetectorConfig(),
363
+ removeFromCart: { enabled: false },
364
+ initiateCheckout: { enabled: false },
365
+ addPaymentInfo: { enabled: false },
366
+ search: { enabled: false },
367
+ viewContent: { enabled: false },
368
+ },
369
+ },
370
+ rules: {
371
+ enabled: false,
372
+ selectors: [],
373
+ texts: [],
374
+ urlPatterns: [],
375
+ checkout: { enabled: false },
376
+ card: { enabled: false },
377
+ },
378
+ },
379
+ },
380
+ };
381
+ }
382
+
383
+ function appendLog(message) {
384
+ const line = '[' + new Date().toISOString() + '] ' + message;
385
+ const prev = els.logs.textContent;
386
+ els.logs.textContent =
387
+ prev === 'Aguardando eventos...' ? line : line + '\n' + prev;
388
+ }
389
+
390
+ function renderCounts() {
391
+ const lines = Object.keys(counts)
392
+ .sort()
393
+ .map(function (type) { return type + ': ' + counts[type]; });
394
+ els.counts.textContent =
395
+ lines.length > 0 ? lines.join('\n') : 'Nenhum evento ainda';
396
+ }
397
+
398
+ function renderCart() {
399
+ if (!els.cart) return;
400
+ els.cart.textContent = JSON.stringify(cartMirror, null, 2);
401
+ }
402
+
403
+ function renderDebug() {
404
+ const detectors =
405
+ pixel && pixel.getDebugActiveDetectors
406
+ ? pixel.getDebugActiveDetectors()
407
+ : [];
408
+ els.detectors.textContent =
409
+ detectors.length > 0 ? detectors.join('\n') : 'Nenhum detector ativo';
410
+ if (els.dedupe) {
411
+ const keys =
412
+ pixel && pixel.getDebugDedupeKeys ? pixel.getDebugDedupeKeys() : [];
413
+ els.dedupe.textContent =
414
+ keys.length > 0 ? keys.join('\n') : 'Nenhuma chave';
415
+ }
416
+ els.runtime.textContent =
417
+ 'initialized: ' +
418
+ (pixel ? pixel.isInitialized() : false) +
419
+ '\ninit count: ' +
420
+ initCount +
421
+ '\ndestroy count: ' +
422
+ destroyCount +
423
+ '\npixelId: ' +
424
+ PIXEL_ID +
425
+ '\nscenario: trigger: auto · selectorForm';
426
+ els.pill.textContent =
427
+ pixel && pixel.isInitialized() ? 'ready' : 'offline';
428
+ els.pill.className =
429
+ 'pill' + (pixel && pixel.isInitialized() ? ' ok' : '');
430
+ }
431
+
432
+ function updateCartFromEvent(event) {
433
+ if (
434
+ event.type === 'ADD_TO_CART' &&
435
+ event.data &&
436
+ event.data.productId
437
+ ) {
438
+ cartMirror[event.data.productId] = {
439
+ productId: event.data.productId,
440
+ productName: event.data.productName,
441
+ price: event.data.price,
442
+ currency: event.data.currency,
443
+ quantity: event.data.quantity != null ? event.data.quantity : 1,
444
+ };
445
+ }
446
+ if (
447
+ event.type === 'REMOVE_FROM_CART' &&
448
+ event.data &&
449
+ event.data.productId
450
+ ) {
451
+ delete cartMirror[event.data.productId];
452
+ }
453
+ renderCart();
454
+ }
455
+
456
+ function onEvent(event) {
457
+ counts[event.type] = (counts[event.type] || 0) + 1;
458
+ renderCounts();
459
+ updateCartFromEvent(event);
460
+ els.last.textContent = JSON.stringify(event, null, 2);
461
+ appendLog(event.type + ' ' + JSON.stringify(event.data || {}));
462
+ renderDebug();
463
+ }
464
+
465
+ async function boot() {
466
+ if (unsubscribe) { unsubscribe(); unsubscribe = null; }
467
+ if (pixel) {
468
+ await pixel.destroy();
469
+ destroyCount += 1;
470
+ pixel = null;
471
+ }
472
+ Object.keys(cartMirror).forEach(function (k) { delete cartMirror[k]; });
473
+ renderCart();
474
+ pixel = new Pixel(buildConfig());
475
+ await pixel.init();
476
+ initCount += 1;
477
+ const services = pixel.getDebugServices();
478
+ if (services && services.dispatcher) {
479
+ unsubscribe = services.dispatcher.subscribe(onEvent);
480
+ }
481
+ appendLog('Pixel initialized — trigger: auto · selectorForm');
482
+ renderDebug();
483
+ }
484
+
485
+ async function destroyPixel() {
486
+ if (unsubscribe) { unsubscribe(); unsubscribe = null; }
487
+ if (pixel) {
488
+ await pixel.destroy();
489
+ destroyCount += 1;
490
+ pixel = null;
491
+ }
492
+ appendLog('Pixel destroyed');
493
+ renderDebug();
494
+ }
495
+
496
+ document.getElementById('btn-reinit').onclick = function () { boot(); };
497
+ document.getElementById('btn-destroy').onclick = function () { destroyPixel(); };
498
+ document.getElementById('btn-clear').onclick = function () {
499
+ els.logs.textContent = 'Aguardando eventos...';
500
+ els.last.textContent = 'null';
501
+ Object.keys(counts).forEach(function (k) { delete counts[k]; });
502
+ Object.keys(cartMirror).forEach(function (k) { delete cartMirror[k]; });
503
+ renderCounts();
504
+ renderCart();
505
+ };
506
+
507
+
508
+
509
+ boot();
510
+ </script>
511
+ </body>
512
+ </html>