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