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