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