@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,454 @@
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 — SEARCH data-query estático</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
+ label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; }
51
+ input {
52
+ width: 100%; border: 1px solid var(--border); border-radius: 8px;
53
+ padding: 0.55rem 0.7rem; font: inherit; background: #fff;
54
+ }
55
+ .search-bar { display: flex; gap: 0.5rem; align-items: stretch; }
56
+ .search-bar input { flex: 1; }
57
+ .status, pre {
58
+ background: #0f172a; color: #e2e8f0; border-radius: 8px; padding: 0.75rem;
59
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
60
+ font-size: 0.78rem; white-space: pre-wrap; word-break: break-word;
61
+ max-height: 260px; overflow: auto;
62
+ }
63
+ .pill {
64
+ display: inline-block; border-radius: 999px; padding: 0.15rem 0.55rem;
65
+ font-size: 0.72rem; background: #e2e8f0; color: #334155; margin-left: 0.35rem;
66
+ }
67
+ .pill.ok { background: #bbf7d0; color: #166534; }
68
+ .checklist { margin: 0; padding-left: 1.1rem; font-size: 0.88rem; color: var(--muted); }
69
+ .checklist li { margin: 0.35rem 0; }
70
+ .ctx {
71
+ border-left: 3px solid var(--accent); padding-left: 0.75rem; margin-bottom: 0.85rem;
72
+ color: var(--muted); font-size: 0.88rem;
73
+ }
74
+ code { font-size: 0.85em; }
75
+ </style>
76
+ </head>
77
+ <body>
78
+ <div class="wrap">
79
+ <h1>SEARCH — data-track + data-query</h1>
80
+ <p class="sub">
81
+ Cenário isolado para validação do Pixel v2.
82
+ <span class="pill" id="init-pill">offline</span>
83
+ </p>
84
+ <div class="nav"><a href="example-search-attribute.html" class="active">1. data-query</a>
85
+ <a href="example-search-button-sync.html" class="">2. Botão + sync</a>
86
+ <a href="example-search-input.html" class="">3. Input value</a>
87
+ <a href="example-search-submit.html" class="">4. Form submit</a>
88
+ <a href="example-search-text.html" class="">5. Text</a>
89
+ <a href="example-search-manual.html" class="">6. Manual API</a>
90
+ <a href="example-search-dedupe.html" class="">7. Dedupe</a></div>
91
+ <div class="hint"><strong>Contexto:</strong> botão com <code>data-track="search"</code> e
92
+ <code>data-query</code> fixo. <code>ConfiguredSelectorDetector</code> lê a query
93
+ do elemento matched. Sem query → não dispara. Sem <code>selectorForm</code>
94
+ (search não tem form condition).</div>
95
+
96
+ <div class="card">
97
+ <h2>Lifecycle</h2>
98
+ <div class="actions">
99
+ <button id="btn-reinit" class="primary" type="button">Reinitialize</button>
100
+ <button id="btn-destroy" class="danger" type="button">Destroy</button>
101
+ <button id="btn-clear" type="button">Clear logs</button>
102
+ </div>
103
+ <div class="status" id="runtime-status">Aguardando init...</div>
104
+ </div>
105
+
106
+ <div class="grid">
107
+ <div>
108
+ <div class="card">
109
+ <h2>Busca por atributo <span class="pill">ConfiguredSelector</span></h2>
110
+ <div class="ctx">Query vem só do data-query do botão.</div>
111
+ <div class="actions">
112
+ <button
113
+ type="button"
114
+ class="primary"
115
+ data-track="search"
116
+ data-query="tenis corrida"
117
+ >
118
+ Buscar “tenis corrida”
119
+ </button>
120
+ <button type="button" data-track="search">
121
+ Buscar sem data-query
122
+ </button>
123
+ <button type="button" id="btn-no-track" data-query=" Ignorado ">
124
+ Sem data-track
125
+ </button>
126
+ </div>
127
+ <p class="sub">Sem data-query → skip. Sem data-track → não casa o selector.</p>
128
+ </div>
129
+ <div class="card">
130
+ <h2>Checklist</h2>
131
+ <ul class="checklist">
132
+ <li>[ ] Com data-query → <code>SEARCH { query: "tenis corrida" }</code></li>
133
+ <li>[ ] Sem data-query → não dispara</li>
134
+ <li>[ ] Sem data-track → não dispara</li>
135
+ <li>[ ] Detector: <code>ConfiguredSelector(SEARCH)</code></li>
136
+ </ul>
137
+ </div>
138
+ </div>
139
+ <div>
140
+ <div class="card">
141
+ <h2>Event counts</h2>
142
+ <div class="status" id="event-counts">Nenhum evento ainda</div>
143
+ </div>
144
+ <div class="card">
145
+ <h2>Search payload (último)</h2>
146
+ <div class="status" id="search-payload">null</div>
147
+ </div>
148
+ <div class="card">
149
+ <h2>Active detectors</h2>
150
+ <div class="status" id="detectors">—</div>
151
+ </div>
152
+
153
+ <div class="card">
154
+ <h2>Last event JSON</h2>
155
+ <pre id="last-event">null</pre>
156
+ </div>
157
+ <div class="card">
158
+ <h2>Event log</h2>
159
+ <pre id="logs">Aguardando eventos...</pre>
160
+ </div>
161
+ </div>
162
+ </div>
163
+ </div>
164
+
165
+ <script src="../../../dist/v2/global.global.js"></script>
166
+ <script>
167
+ const { Pixel, DEFAULT_PIXEL_CONFIG } = window.PixelV2;
168
+ const API_ENDPOINT =
169
+ 'https://micro-service-pixel-production-4826.up.railway.app';
170
+ const PIXEL_ID = 'pix_7315610';
171
+
172
+ const els = {
173
+ logs: document.getElementById('logs'),
174
+ last: document.getElementById('last-event'),
175
+ counts: document.getElementById('event-counts'),
176
+ payload: document.getElementById('search-payload'),
177
+ detectors: document.getElementById('detectors'),
178
+ dedupe: document.getElementById('dedupe-keys'),
179
+ runtime: document.getElementById('runtime-status'),
180
+ pill: document.getElementById('init-pill'),
181
+ };
182
+
183
+ let pixel = null;
184
+ let unsubscribe = null;
185
+ let initCount = 0;
186
+ let destroyCount = 0;
187
+ const counts = {};
188
+
189
+ function searchDetectorConfig() {
190
+ return {
191
+ enabled: true,
192
+ selector: ['[data-track="search"]'],
193
+ selectorType: 'css',
194
+ };
195
+ }
196
+
197
+ function buildConfig() {
198
+ const base = DEFAULT_PIXEL_CONFIG;
199
+ return {
200
+ ...base,
201
+ app: {
202
+ ...base.app,
203
+ source: 'custom',
204
+ environment: 'development',
205
+ debug: true,
206
+ },
207
+ transport: {
208
+ ...DEFAULT_PIXEL_CONFIG.transport,
209
+ apiEndpoint: API_ENDPOINT,
210
+ timeoutMs: 10000,
211
+ },
212
+ identity: { ...base.identity, pixelId: PIXEL_ID },
213
+ modules: {
214
+ ...base.modules,
215
+ core: {
216
+ ...base.modules.core,
217
+ enabled: false,
218
+ pageView: {
219
+ ...base.modules.core.pageView,
220
+ enabled: false,
221
+ trackInitialPageView: false,
222
+ spa: false,
223
+ },
224
+ },
225
+ behavior: { ...base.modules.behavior, enabled: false },
226
+ privacy: { ...base.modules.privacy, enabled: false },
227
+ transport: {
228
+ enabled: true,
229
+ mockSender: { enabled: false },
230
+ sender: { mode: 'http' },
231
+ persistence: { enabled: true },
232
+ replay: { enabled: true },
233
+ ordering: { enabled: true },
234
+ coordination: { enabled: true },
235
+ circuitBreaker: {
236
+ enabled: true,
237
+ failureThreshold: 5,
238
+ resetTimeoutMs: 30000,
239
+ halfOpenMaxAttempts: 2,
240
+ },
241
+ backpressure: {
242
+ enabled: true,
243
+ maxQueueSize: 500,
244
+ policy: 'drop_oldest',
245
+ sampleRate: 0.5,
246
+ },
247
+ deadLetter: { enabled: true, maxEntries: 200 },
248
+ compression: { enabled: true, strategy: 'identity' },
249
+ retry: {
250
+ enabled: true,
251
+ maxAttempts: 4,
252
+ baseDelayMs: 500,
253
+ maxDelayMs: 4000,
254
+ multiplier: 2,
255
+ },
256
+ batch: {
257
+ enabled: true,
258
+ batchSize: 10,
259
+ flushIntervalMs: 2000,
260
+ maxWaitMs: 5000,
261
+ },
262
+ timeout: { enabled: true, timeoutMs: 10000 },
263
+ offline: { enabled: true },
264
+ flush: {
265
+ enabled: true,
266
+ flushIntervalMs: 2000,
267
+ flushOnDestroy: true,
268
+ prepareUnloadHooks: true,
269
+ },
270
+ },
271
+ integrations: { ...base.modules.integrations, enabled: false },
272
+ conversion: {
273
+ enabled: true,
274
+ commerce: {
275
+ currency: 'BRL',
276
+ catalog: { products: [] },
277
+ checkout: {
278
+ mode: 'single_product',
279
+ selectedItems: [],
280
+ calculateValueFrom: 'selected_items',
281
+ allowDynamicItems: true,
282
+ },
283
+ mappings: {
284
+ attributes: {
285
+ productId: ['data-product-id'],
286
+ productName: ['data-product-name'],
287
+ price: ['data-product-price'],
288
+ quantity: ['data-quantity'],
289
+ currency: ['data-currency'],
290
+ },
291
+ fields: {
292
+ email: ['email'],
293
+ phone: ['phone'],
294
+ productId: ['productId'],
295
+ productName: ['productName'],
296
+ price: ['price'],
297
+ quantity: ['quantity'],
298
+ currency: ['currency'],
299
+ },
300
+ },
301
+ },
302
+ manual: {
303
+ pageView: { enabled: false },
304
+ purchase: { enabled: false },
305
+ lead: { enabled: false },
306
+ addToCart: { enabled: false },
307
+ removeFromCart: { enabled: false },
308
+ initiateCheckout: { enabled: false },
309
+ addPaymentInfo: { enabled: false },
310
+ search: { enabled: true },
311
+ viewContent: { enabled: false },
312
+ },
313
+ auto: {
314
+ enabled: true,
315
+ detectors: {
316
+ lead: { enabled: false },
317
+ purchase: { enabled: false },
318
+ addToCart: { enabled: false },
319
+ removeFromCart: { enabled: false },
320
+ initiateCheckout: { enabled: false },
321
+ addPaymentInfo: {
322
+ enabled: false,
323
+ paymentMethod: 'CREDIT_CARD',
324
+ cardDetection: false,
325
+ autoDispatch: false,
326
+ },
327
+ search: searchDetectorConfig(),
328
+ viewContent: { enabled: false },
329
+ },
330
+ },
331
+ rules: {
332
+ enabled: false,
333
+ selectors: [],
334
+ texts: [],
335
+ urlPatterns: [],
336
+ checkout: { enabled: false },
337
+ card: { enabled: false },
338
+ },
339
+ },
340
+ },
341
+ };
342
+ }
343
+
344
+ function appendLog(message) {
345
+ const line = '[' + new Date().toISOString() + '] ' + message;
346
+ const prev = els.logs.textContent;
347
+ els.logs.textContent =
348
+ prev === 'Aguardando eventos...' ? line : line + '\n' + prev;
349
+ }
350
+
351
+ function renderCounts() {
352
+ const lines = Object.keys(counts)
353
+ .sort()
354
+ .map(function (type) { return type + ': ' + counts[type]; });
355
+ els.counts.textContent =
356
+ lines.length > 0 ? lines.join('\n') : 'Nenhum evento ainda';
357
+ }
358
+
359
+ function renderPayload(event) {
360
+ if (!els.payload) return;
361
+ if (!event || event.type !== 'SEARCH') {
362
+ els.payload.textContent = 'null';
363
+ return;
364
+ }
365
+ els.payload.textContent = JSON.stringify(event.data || {}, null, 2);
366
+ }
367
+
368
+ function renderDebug() {
369
+ const detectors =
370
+ pixel && pixel.getDebugActiveDetectors
371
+ ? pixel.getDebugActiveDetectors()
372
+ : [];
373
+ els.detectors.textContent =
374
+ detectors.length > 0 ? detectors.join('\n') : 'Nenhum detector ativo';
375
+ if (els.dedupe) {
376
+ const keys =
377
+ pixel && pixel.getDebugDedupeKeys ? pixel.getDebugDedupeKeys() : [];
378
+ els.dedupe.textContent =
379
+ keys.length > 0 ? keys.join('\n') : 'Nenhuma chave';
380
+ }
381
+ els.runtime.textContent =
382
+ 'initialized: ' +
383
+ (pixel ? pixel.isInitialized() : false) +
384
+ '\ninit count: ' +
385
+ initCount +
386
+ '\ndestroy count: ' +
387
+ destroyCount +
388
+ '\npixelId: ' +
389
+ PIXEL_ID +
390
+ '\nscenario: data-track + data-query';
391
+ els.pill.textContent =
392
+ pixel && pixel.isInitialized() ? 'ready' : 'offline';
393
+ els.pill.className =
394
+ 'pill' + (pixel && pixel.isInitialized() ? ' ok' : '');
395
+ }
396
+
397
+ function onEvent(event) {
398
+ counts[event.type] = (counts[event.type] || 0) + 1;
399
+ renderCounts();
400
+ renderPayload(event);
401
+ els.last.textContent = JSON.stringify(event, null, 2);
402
+ appendLog(event.type + ' ' + JSON.stringify(event.data || {}));
403
+ renderDebug();
404
+ }
405
+
406
+ async function boot() {
407
+ if (unsubscribe) { unsubscribe(); unsubscribe = null; }
408
+ if (pixel) {
409
+ await pixel.destroy();
410
+ destroyCount += 1;
411
+ pixel = null;
412
+ }
413
+ pixel = new Pixel(buildConfig());
414
+ await pixel.init();
415
+ initCount += 1;
416
+ const services = pixel.getDebugServices();
417
+ if (services && services.dispatcher) {
418
+ unsubscribe = services.dispatcher.subscribe(onEvent);
419
+ }
420
+ appendLog('Pixel initialized — data-track + data-query');
421
+ renderDebug();
422
+ }
423
+
424
+ async function destroyPixel() {
425
+ if (unsubscribe) { unsubscribe(); unsubscribe = null; }
426
+ if (pixel) {
427
+ await pixel.destroy();
428
+ destroyCount += 1;
429
+ pixel = null;
430
+ }
431
+ appendLog('Pixel destroyed');
432
+ renderDebug();
433
+ }
434
+
435
+ document.getElementById('btn-reinit').onclick = function () { boot(); };
436
+ document.getElementById('btn-destroy').onclick = function () { destroyPixel(); };
437
+ document.getElementById('btn-clear').onclick = function () {
438
+ els.logs.textContent = 'Aguardando eventos...';
439
+ els.last.textContent = 'null';
440
+ if (els.payload) els.payload.textContent = 'null';
441
+ Object.keys(counts).forEach(function (k) { delete counts[k]; });
442
+ renderCounts();
443
+ };
444
+
445
+
446
+ document.getElementById('btn-no-track').onclick = function () {
447
+ appendLog('(playground) sem data-track — esperado: nenhum SEARCH');
448
+ };
449
+
450
+
451
+ boot();
452
+ </script>
453
+ </body>
454
+ </html>