@beworke/pixel 0.1.0-rc.1 → 0.1.0-rc.6

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 (156) hide show
  1. package/CHANGELOG.md +260 -4
  2. package/README.md +65 -118
  3. package/RELEASE_CANDIDATE.md +181 -36
  4. package/dist/{StorageFactory-BhpbB6Jj.d.mts → StorageFactory-CPghDPBj.d.mts} +2 -2
  5. package/dist/{StorageFactory-CAkJJqVD.d.ts → StorageFactory-tjfzk57c.d.ts} +2 -2
  6. package/dist/config/index.cjs.js +1 -1
  7. package/dist/config/index.cjs.js.map +1 -1
  8. package/dist/config/index.d.mts +4 -3
  9. package/dist/config/index.d.ts +4 -3
  10. package/dist/config/index.esm.js +1 -1
  11. package/dist/config/index.esm.js.map +1 -1
  12. package/dist/events/index.cjs.js +1 -1
  13. package/dist/events/index.cjs.js.map +1 -1
  14. package/dist/events/index.d.mts +2 -1
  15. package/dist/events/index.d.ts +2 -1
  16. package/dist/events/index.esm.js +1 -1
  17. package/dist/events/index.esm.js.map +1 -1
  18. package/dist/examples/html-script/README.md +24 -2
  19. package/dist/examples/html-script/RELEASE_CANDIDATE.md +20 -6
  20. package/dist/examples/html-script/add-payment-info/README.md +3 -3
  21. package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-autocomplete.html +66 -48
  22. package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-disabled.html +66 -48
  23. package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-fields.html +65 -47
  24. package/dist/examples/html-script/add-payment-info/example-add-payment-info-data-track.html +73 -47
  25. package/dist/examples/html-script/add-payment-info/example-add-payment-info-dedupe.html +65 -47
  26. package/dist/examples/html-script/add-payment-info/example-add-payment-info-manual.html +56 -47
  27. package/dist/examples/html-script/add-payment-info/example-add-payment-info-rules-card.html +65 -47
  28. package/dist/examples/html-script/add-payment-info/example-add-payment-info-security.html +65 -47
  29. package/dist/examples/html-script/add-to-cart/README.md +3 -3
  30. package/dist/examples/html-script/add-to-cart/example-add-to-cart-attribute.html +90 -70
  31. package/dist/examples/html-script/add-to-cart/example-add-to-cart-auto.html +103 -81
  32. package/dist/examples/html-script/add-to-cart/example-add-to-cart-click.html +101 -78
  33. package/dist/examples/html-script/add-to-cart/example-add-to-cart-dedupe.html +90 -70
  34. package/dist/examples/html-script/add-to-cart/example-add-to-cart-manual.html +81 -67
  35. package/dist/examples/html-script/add-to-cart/example-add-to-cart-order-bump.html +90 -70
  36. package/dist/examples/html-script/add-to-cart/example-add-to-cart-text.html +104 -81
  37. package/dist/examples/html-script/behavior/example-behavior-engagement.html +489 -0
  38. package/dist/examples/html-script/behavior/example-behavior-heartbeat.html +350 -0
  39. package/dist/examples/html-script/behavior/example-behavior-runtime-intelligence.html +433 -0
  40. package/dist/examples/html-script/behavior/example-behavior-viewport.html +397 -0
  41. package/dist/examples/html-script/{example-behavior.html → behavior/example-behavior.html} +23 -17
  42. package/dist/examples/html-script/example-checkout-commerce.html +825 -0
  43. package/dist/examples/html-script/example-integration.html +5 -5
  44. package/dist/examples/html-script/example-landing-commerce.html +380 -0
  45. package/dist/examples/html-script/example-runtime-diagnostics.html +108 -0
  46. package/dist/examples/html-script/example-transport.html +5 -5
  47. package/dist/examples/html-script/full-funnel/README.md +64 -0
  48. package/dist/examples/html-script/full-funnel/checkout.html +116 -0
  49. package/dist/examples/html-script/full-funnel/downsell.html +58 -0
  50. package/dist/examples/html-script/full-funnel/landing.html +99 -0
  51. package/dist/examples/html-script/full-funnel/thank-you.html +85 -0
  52. package/dist/examples/html-script/full-funnel/upsell.html +64 -0
  53. package/dist/examples/html-script/initiate-checkout/README.md +6 -6
  54. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-attribute.html +94 -74
  55. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-auto.html +102 -80
  56. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-click.html +103 -80
  57. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-manual.html +86 -72
  58. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-snapshot.html +95 -75
  59. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-submit.html +103 -83
  60. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-text.html +105 -82
  61. package/dist/examples/html-script/lead/README.md +9 -7
  62. package/dist/examples/html-script/lead/example-lead-trigger-attribute.html +67 -47
  63. package/dist/examples/html-script/lead/example-lead-trigger-auto.html +78 -56
  64. package/dist/examples/html-script/lead/example-lead-trigger-click.html +78 -55
  65. package/dist/examples/html-script/release-candidate.html +187 -76
  66. package/dist/examples/html-script/remove-from-cart/README.md +1 -1
  67. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-attribute.html +93 -73
  68. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-css.html +93 -73
  69. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-dedupe.html +93 -73
  70. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-manual.html +84 -70
  71. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-multi.html +94 -74
  72. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-state.html +95 -75
  73. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-text.html +98 -76
  74. package/dist/examples/html-script/search/README.md +1 -1
  75. package/dist/examples/html-script/search/example-search-attribute.html +66 -51
  76. package/dist/examples/html-script/search/example-search-button-sync.html +66 -51
  77. package/dist/examples/html-script/search/example-search-dedupe.html +66 -51
  78. package/dist/examples/html-script/search/example-search-input.html +67 -51
  79. package/dist/examples/html-script/search/example-search-manual.html +57 -48
  80. package/dist/examples/html-script/search/example-search-submit.html +66 -51
  81. package/dist/examples/html-script/search/example-search-text.html +71 -51
  82. package/dist/examples/html-script/url-context/example-url-context-allowed-domains.html +63 -0
  83. package/dist/examples/html-script/url-context/example-url-context-landing.html +70 -0
  84. package/dist/examples/html-script/url-context/example-url-context-upsell.html +67 -0
  85. package/dist/examples/html-script/url-context/example-url-context.html +171 -0
  86. package/dist/examples/html-script/view-content/README.md +1 -1
  87. package/dist/examples/html-script/view-content/example-view-content-attribute.html +85 -70
  88. package/dist/examples/html-script/view-content/example-view-content-css.html +85 -70
  89. package/dist/examples/html-script/view-content/example-view-content-dedupe.html +85 -70
  90. package/dist/examples/html-script/view-content/example-view-content-empty.html +85 -70
  91. package/dist/examples/html-script/view-content/example-view-content-manual.html +76 -67
  92. package/dist/examples/html-script/view-content/example-view-content-product-card.html +85 -70
  93. package/dist/examples/html-script/view-content/example-view-content-text.html +90 -73
  94. package/dist/examples/v2/README.md +4 -1
  95. package/dist/{index-DUfFzniE.d.ts → index-CQAyT5Od.d.ts} +170 -3
  96. package/dist/{index-DUfFzniE.d.mts → index-JlKPz4pp.d.mts} +170 -3
  97. package/dist/index.cjs.js +1 -1
  98. package/dist/index.cjs.js.map +1 -1
  99. package/dist/index.d.mts +435 -12
  100. package/dist/index.d.ts +435 -12
  101. package/dist/index.esm.js +1 -1
  102. package/dist/index.esm.js.map +1 -1
  103. package/dist/{pixel-CbeF25mD.d.mts → pixel-BxZZx8l5.d.ts} +248 -72
  104. package/dist/{pixel-CbeF25mD.d.ts → pixel-CKc4OQUx.d.mts} +248 -72
  105. package/dist/{pixel-default-config-1VgLFOiL.d.mts → pixel-default-config-CJl-eypl.d.mts} +1 -1
  106. package/dist/{pixel-default-config-Bxb-Vdd8.d.ts → pixel-default-config-aAOujzwp.d.ts} +1 -1
  107. package/dist/runtime/index.cjs.js +1 -1
  108. package/dist/runtime/index.cjs.js.map +1 -1
  109. package/dist/runtime/index.d.mts +19 -26
  110. package/dist/runtime/index.d.ts +19 -26
  111. package/dist/runtime/index.esm.js +1 -1
  112. package/dist/runtime/index.esm.js.map +1 -1
  113. package/dist/services/index.cjs.js +1 -1
  114. package/dist/services/index.cjs.js.map +1 -1
  115. package/dist/services/index.d.mts +14 -6
  116. package/dist/services/index.d.ts +14 -6
  117. package/dist/services/index.esm.js +1 -1
  118. package/dist/services/index.esm.js.map +1 -1
  119. package/dist/types-BP8dz1gP.d.mts +19 -0
  120. package/dist/types-C75pQP31.d.ts +19 -0
  121. package/dist/types-DMhzHSVC.d.mts +293 -0
  122. package/dist/types-D_SsCur9.d.ts +293 -0
  123. package/dist/url-context-BjAsQoVl.d.mts +85 -0
  124. package/dist/url-context-BjAsQoVl.d.ts +85 -0
  125. package/dist/v2/global.global.js +1 -1
  126. package/dist/v2/global.global.js.map +1 -1
  127. package/dist/v2/index.cjs.js +1 -1
  128. package/dist/v2/index.cjs.js.map +1 -1
  129. package/dist/v2/index.d.mts +8 -6
  130. package/dist/v2/index.d.ts +8 -6
  131. package/dist/v2/index.esm.js +1 -1
  132. package/dist/v2/index.esm.js.map +1 -1
  133. package/docs/public/README.md +75 -0
  134. package/docs/public/api/exports.md +47 -0
  135. package/docs/public/api/pixel.md +65 -0
  136. package/docs/public/configuration/commerce.md +44 -0
  137. package/docs/public/configuration/modules.md +66 -0
  138. package/docs/public/configuration/overview.md +66 -0
  139. package/docs/public/events/catalog.md +65 -0
  140. package/docs/public/getting-started/installation.md +75 -0
  141. package/docs/public/getting-started/quick-start.md +77 -0
  142. package/docs/public/getting-started/react-nextjs.md +55 -0
  143. package/docs/public/getting-started/script-tag.md +57 -0
  144. package/docs/public/guides/funnel-checkout.md +52 -0
  145. package/docs/public/guides/funnel-downsell.md +53 -0
  146. package/docs/public/guides/funnel-full.md +64 -0
  147. package/docs/public/guides/funnel-landing.md +68 -0
  148. package/docs/public/guides/funnel-thank-you.md +48 -0
  149. package/docs/public/guides/funnel-upsell.md +72 -0
  150. package/docs/public/limitations.md +32 -0
  151. package/docs/public/privacy/limitations.md +33 -0
  152. package/docs/public/release-candidate/validation.md +37 -0
  153. package/docs/public/troubleshooting.md +55 -0
  154. package/package.json +13 -1
  155. package/dist/types-CTpRvFKZ.d.ts +0 -71
  156. package/dist/types-DGlBdsAy.d.mts +0 -71
@@ -0,0 +1,433 @@
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 — Runtime Intelligence (Etapa 20)</title>
7
+ <style>
8
+ body {
9
+ font-family: system-ui, sans-serif;
10
+ margin: 0;
11
+ padding: 2rem;
12
+ max-width: 1100px;
13
+ }
14
+ .hint {
15
+ background: #ecfdf5;
16
+ border: 1px solid #a7f3d0;
17
+ border-radius: 8px;
18
+ padding: 1rem;
19
+ margin-bottom: 1rem;
20
+ font-size: 14px;
21
+ }
22
+ .actions {
23
+ display: flex;
24
+ flex-wrap: wrap;
25
+ gap: 0.5rem;
26
+ margin: 1rem 0;
27
+ }
28
+ button {
29
+ padding: 0.5rem 1rem;
30
+ cursor: pointer;
31
+ }
32
+ .state-badge {
33
+ display: inline-block;
34
+ padding: 0.35rem 0.85rem;
35
+ border-radius: 999px;
36
+ font-weight: 600;
37
+ font-size: 0.9rem;
38
+ background: #dbeafe;
39
+ color: #1e40af;
40
+ margin-bottom: 1rem;
41
+ }
42
+ .panels {
43
+ display: grid;
44
+ grid-template-columns: 1fr 1fr;
45
+ gap: 1rem;
46
+ }
47
+ @media (max-width: 820px) {
48
+ .panels {
49
+ grid-template-columns: 1fr;
50
+ }
51
+ }
52
+ .panel {
53
+ font-family: ui-monospace, monospace;
54
+ font-size: 12px;
55
+ border-radius: 8px;
56
+ padding: 1rem;
57
+ background: #f4f4f5;
58
+ border: 1px solid #e4e4e7;
59
+ }
60
+ .panel h3 {
61
+ margin: 0 0 0.75rem;
62
+ font-size: 13px;
63
+ font-family: system-ui, sans-serif;
64
+ }
65
+ .panel pre {
66
+ margin: 0;
67
+ white-space: pre-wrap;
68
+ word-break: break-word;
69
+ }
70
+ #logs {
71
+ background: #18181b;
72
+ color: #fafafa;
73
+ min-height: 180px;
74
+ max-height: 320px;
75
+ overflow: auto;
76
+ margin-top: 1rem;
77
+ border-radius: 8px;
78
+ padding: 1rem;
79
+ font-family: ui-monospace, monospace;
80
+ font-size: 12px;
81
+ }
82
+ </style>
83
+ </head>
84
+ <body>
85
+ <h1>Behavior Runtime Intelligence</h1>
86
+ <p class="hint">
87
+ Etapa 20 — RateLimit, Buffer, StateMachine e Session Summary. Emite
88
+ <code>BEHAVIOR_SESSION_SUMMARY</code> via Dispatcher. Dados fictícios.
89
+ <br /><br />
90
+ <strong>Roteiro:</strong> Init → Burst → Idle/Active/Hidden/Visible →
91
+ Flush → Summary → Destroy (captura summary) → Reinit.
92
+ </p>
93
+
94
+ <div id="state-badge" class="state-badge">state: —</div>
95
+
96
+ <div class="actions">
97
+ <button type="button" id="btn-init">Init</button>
98
+ <button type="button" id="btn-burst">Burst signals</button>
99
+ <button type="button" id="btn-idle">Idle</button>
100
+ <button type="button" id="btn-active">Active</button>
101
+ <button type="button" id="btn-hidden">Hidden</button>
102
+ <button type="button" id="btn-visible">Visible</button>
103
+ <button type="button" id="btn-flush">Flush</button>
104
+ <button type="button" id="btn-summary">Summary</button>
105
+ <button type="button" id="btn-destroy">Destroy</button>
106
+ <button type="button" id="btn-reinit">Reinit</button>
107
+ <button type="button" id="btn-clear">Clear log</button>
108
+ </div>
109
+
110
+ <div class="panels">
111
+ <div class="panel">
112
+ <h3>Rate limit</h3>
113
+ <pre id="rate-limit">—</pre>
114
+ </div>
115
+ <div class="panel">
116
+ <h3>Buffer</h3>
117
+ <pre id="buffer">—</pre>
118
+ </div>
119
+ <div class="panel">
120
+ <h3>Session summary</h3>
121
+ <pre id="summary">—</pre>
122
+ </div>
123
+ <div class="panel">
124
+ <h3>Engagement</h3>
125
+ <pre id="engagement">—</pre>
126
+ </div>
127
+ <div class="panel" style="grid-column: 1 / -1">
128
+ <h3>Diagnostics (behavior.*)</h3>
129
+ <pre id="diag">—</pre>
130
+ </div>
131
+ </div>
132
+
133
+ <div id="logs"></div>
134
+
135
+ <script src="../../../dist/v2/global.global.js"></script>
136
+ <script>
137
+ (function () {
138
+ const { Pixel, DEFAULT_PIXEL_CONFIG } = window.PixelV2;
139
+ const logsEl = document.getElementById('logs');
140
+ const stateBadge = document.getElementById('state-badge');
141
+ const rateLimitEl = document.getElementById('rate-limit');
142
+ const bufferEl = document.getElementById('buffer');
143
+ const summaryEl = document.getElementById('summary');
144
+ const engagementEl = document.getElementById('engagement');
145
+ const diagEl = document.getElementById('diag');
146
+
147
+ let pixel = null;
148
+ let unsubscribe = null;
149
+ let lastSnapshot = null;
150
+ const eventCounts = {
151
+ BEHAVIOR_SESSION_SUMMARY: 0,
152
+ ENGAGEMENT_UPDATE: 0,
153
+ ENGAGEMENT_SUMMARY: 0,
154
+ };
155
+
156
+ function log(msg, data) {
157
+ const line = document.createElement('div');
158
+ line.textContent =
159
+ '[' +
160
+ new Date().toISOString().slice(11, 23) +
161
+ '] ' +
162
+ msg +
163
+ (data !== undefined ? ' ' + JSON.stringify(data) : '');
164
+ logsEl.prepend(line);
165
+ }
166
+
167
+ function buildConfig() {
168
+ return {
169
+ ...DEFAULT_PIXEL_CONFIG,
170
+ identity: {
171
+ ...DEFAULT_PIXEL_CONFIG.identity,
172
+ pixelId: 'runtime-intelligence-demo',
173
+ },
174
+ modules: {
175
+ ...DEFAULT_PIXEL_CONFIG.modules,
176
+ core: {
177
+ ...DEFAULT_PIXEL_CONFIG.modules.core,
178
+ enabled: true,
179
+ pageView: {
180
+ ...DEFAULT_PIXEL_CONFIG.modules.core.pageView,
181
+ enabled: false,
182
+ trackInitialPageView: false,
183
+ spa: false,
184
+ },
185
+ session: {
186
+ ...DEFAULT_PIXEL_CONFIG.modules.core.session,
187
+ enabled: false,
188
+ },
189
+ },
190
+ privacy: {
191
+ ...DEFAULT_PIXEL_CONFIG.modules.privacy,
192
+ enabled: false,
193
+ },
194
+ conversion: {
195
+ ...DEFAULT_PIXEL_CONFIG.modules.conversion,
196
+ enabled: false,
197
+ },
198
+ integrations: {
199
+ ...DEFAULT_PIXEL_CONFIG.modules.integrations,
200
+ enabled: false,
201
+ },
202
+ transport: {
203
+ ...DEFAULT_PIXEL_CONFIG.modules.transport,
204
+ enabled: false,
205
+ },
206
+ behavior: {
207
+ ...DEFAULT_PIXEL_CONFIG.modules.behavior,
208
+ enabled: true,
209
+ heartbeat: {
210
+ ...DEFAULT_PIXEL_CONFIG.modules.behavior.heartbeat,
211
+ enabled: false,
212
+ },
213
+ engagement: {
214
+ ...DEFAULT_PIXEL_CONFIG.modules.behavior.engagement,
215
+ enabled: true,
216
+ evaluationIntervalMs: 3000,
217
+ minScoreDelta: 3,
218
+ emitSummaryOnDestroy: false,
219
+ },
220
+ rateLimit: {
221
+ enabled: true,
222
+ windowMs: 1000,
223
+ maxSignalsPerWindow: 20,
224
+ criticalBypass: true,
225
+ },
226
+ buffer: {
227
+ enabled: true,
228
+ maxSize: 50,
229
+ maxAgeMs: 5000,
230
+ flushSize: 15,
231
+ dropStrategy: 'compress_similar',
232
+ flushOnHidden: true,
233
+ },
234
+ stateMachine: {
235
+ enabled: true,
236
+ historyLimit: 30,
237
+ },
238
+ sessionSummary: {
239
+ enabled: true,
240
+ emitOnHidden: true,
241
+ emitOnDestroy: true,
242
+ minimumSessionMs: 0,
243
+ },
244
+ trackers: {
245
+ ...DEFAULT_PIXEL_CONFIG.modules.behavior.trackers,
246
+ scroll: { enabled: false, thresholds: [], debounceMs: 0 },
247
+ click: { enabled: false, rageClick: { enabled: false, threshold: 3, windowMs: 500 } },
248
+ visibility: { enabled: false },
249
+ idle: { enabled: false, thresholdMs: 60000 },
250
+ exitIntent: { enabled: false },
251
+ viewport: {
252
+ enabled: false,
253
+ targets: [],
254
+ rootMargin: '0px',
255
+ observeMutations: false,
256
+ mutationDebounceMs: 0,
257
+ maxObservedElements: 0,
258
+ },
259
+ },
260
+ },
261
+ },
262
+ };
263
+ }
264
+
265
+ function captureLive() {
266
+ if (!pixel || !pixel.isInitialized || !pixel.isInitialized()) return null;
267
+ try {
268
+ const snap = pixel.getDebugSnapshot();
269
+ lastSnapshot = snap;
270
+ return snap;
271
+ } catch (err) {
272
+ return lastSnapshot;
273
+ }
274
+ }
275
+
276
+ function refresh(destroyed) {
277
+ const snap = captureLive();
278
+ if (!snap) {
279
+ if (destroyed && lastSnapshot) {
280
+ renderPanels(lastSnapshot, true);
281
+ }
282
+ return;
283
+ }
284
+ renderPanels(snap, destroyed);
285
+ }
286
+
287
+ function renderPanels(snap, destroyed) {
288
+ const b = snap.behavior || {};
289
+ const sm = b.stateMachine;
290
+ stateBadge.textContent =
291
+ 'state: ' +
292
+ (sm ? sm.state : '—') +
293
+ ' · gen ' +
294
+ (sm ? sm.generation : '—') +
295
+ (destroyed ? ' (destroyed)' : '');
296
+
297
+ rateLimitEl.textContent = JSON.stringify(b.rateLimit, null, 2);
298
+ bufferEl.textContent = JSON.stringify(b.buffer, null, 2);
299
+ summaryEl.textContent = JSON.stringify(
300
+ { eventCounts: eventCounts, sessionSummary: b.sessionSummary },
301
+ null,
302
+ 2
303
+ );
304
+ engagementEl.textContent = JSON.stringify(b.engagement, null, 2);
305
+ diagEl.textContent = JSON.stringify(
306
+ {
307
+ runtime: destroyed ? 'destroyed' : 'active',
308
+ health: snap.health,
309
+ configuredEngines: b.configuredEngines,
310
+ rateLimit: b.rateLimit,
311
+ buffer: b.buffer,
312
+ stateMachine: b.stateMachine,
313
+ sessionSummary: b.sessionSummary,
314
+ },
315
+ null,
316
+ 2
317
+ );
318
+ }
319
+
320
+ function wire() {
321
+ if (!pixel || unsubscribe) return;
322
+ const services = pixel.getDebugServices && pixel.getDebugServices();
323
+ if (!services || !services.dispatcher) return;
324
+ unsubscribe = services.dispatcher.subscribe(function (event) {
325
+ if (event.type === 'BEHAVIOR_SESSION_SUMMARY') {
326
+ eventCounts.BEHAVIOR_SESSION_SUMMARY += 1;
327
+ log('BEHAVIOR_SESSION_SUMMARY', {
328
+ reason: event.reason,
329
+ clickCount: event.clickCount,
330
+ generation: event.generation,
331
+ finalState: event.finalState,
332
+ });
333
+ captureLive();
334
+ refresh(false);
335
+ } else if (event.type === 'ENGAGEMENT_UPDATE') {
336
+ eventCounts.ENGAGEMENT_UPDATE += 1;
337
+ log('ENGAGEMENT_UPDATE', { score: event.score, level: event.level });
338
+ refresh(false);
339
+ } else if (event.type === 'ENGAGEMENT_SUMMARY') {
340
+ eventCounts.ENGAGEMENT_SUMMARY += 1;
341
+ log('ENGAGEMENT_SUMMARY', { score: event.score, peakScore: event.peakScore });
342
+ }
343
+ });
344
+ }
345
+
346
+ async function doInit() {
347
+ if (pixel && pixel.isInitialized()) {
348
+ log('already initialized');
349
+ return;
350
+ }
351
+ pixel = new Pixel(buildConfig());
352
+ await pixel.init();
353
+ wire();
354
+ log('init ok');
355
+ refresh(false);
356
+ }
357
+
358
+ async function doDestroy() {
359
+ if (!pixel) return;
360
+ captureLive();
361
+ await pixel.destroy();
362
+ if (unsubscribe) {
363
+ unsubscribe();
364
+ unsubscribe = null;
365
+ }
366
+ pixel = null;
367
+ log('destroy ok');
368
+ refresh(true);
369
+ }
370
+
371
+ document.getElementById('btn-init').onclick = doInit;
372
+ document.getElementById('btn-destroy').onclick = doDestroy;
373
+ document.getElementById('btn-reinit').onclick = async function () {
374
+ await doDestroy();
375
+ await doInit();
376
+ };
377
+ document.getElementById('btn-burst').onclick = function () {
378
+ if (!pixel) return;
379
+ for (let i = 0; i < 30; i += 1) {
380
+ pixel.debugPublishBehaviorSignal('SCROLL', { maxScrollPercent: i * 3 });
381
+ pixel.debugPublishBehaviorSignal('CLICK');
382
+ }
383
+ log('burst: 60 signals');
384
+ refresh(false);
385
+ };
386
+ document.getElementById('btn-idle').onclick = function () {
387
+ if (!pixel) return;
388
+ pixel.debugPublishBehaviorSignal('IDLE', { idleSince: Date.now() });
389
+ log('signal: IDLE');
390
+ refresh(false);
391
+ };
392
+ document.getElementById('btn-active').onclick = function () {
393
+ if (!pixel) return;
394
+ pixel.debugPublishBehaviorSignal('ACTIVITY', { at: Date.now() });
395
+ log('signal: ACTIVITY');
396
+ refresh(false);
397
+ };
398
+ document.getElementById('btn-hidden').onclick = function () {
399
+ if (!pixel) return;
400
+ pixel.debugPublishBehaviorSignal('HIDDEN', { hiddenAt: Date.now() });
401
+ log('signal: HIDDEN');
402
+ refresh(false);
403
+ };
404
+ document.getElementById('btn-visible').onclick = function () {
405
+ if (!pixel) return;
406
+ pixel.debugPublishBehaviorSignal('VISIBLE', { visibleSince: Date.now() });
407
+ log('signal: VISIBLE');
408
+ refresh(false);
409
+ };
410
+ document.getElementById('btn-flush').onclick = function () {
411
+ if (!pixel) return;
412
+ pixel.flushBehaviorBuffer();
413
+ log('manual buffer flush');
414
+ refresh(false);
415
+ };
416
+ document.getElementById('btn-summary').onclick = function () {
417
+ if (!pixel) return;
418
+ const ok = pixel.emitBehaviorSessionSummary('hidden');
419
+ log('manual summary', { emitted: ok });
420
+ refresh(false);
421
+ };
422
+ document.getElementById('btn-clear').onclick = function () {
423
+ logsEl.textContent = '';
424
+ eventCounts.BEHAVIOR_SESSION_SUMMARY = 0;
425
+ eventCounts.ENGAGEMENT_UPDATE = 0;
426
+ eventCounts.ENGAGEMENT_SUMMARY = 0;
427
+ };
428
+
429
+ log('ready — clique Init (requer dist/v2/global.global.js)');
430
+ })();
431
+ </script>
432
+ </body>
433
+ </html>