@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,350 @@
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 Playground</title>
7
+ <style>
8
+ body {
9
+ font-family: system-ui, sans-serif;
10
+ margin: 2rem;
11
+ max-width: 820px;
12
+ }
13
+
14
+ h2 {
15
+ font-size: 1rem;
16
+ margin: 1.5rem 0 0.5rem;
17
+ }
18
+
19
+ .actions {
20
+ display: flex;
21
+ flex-wrap: wrap;
22
+ gap: 0.5rem;
23
+ margin-bottom: 1rem;
24
+ }
25
+
26
+ button {
27
+ padding: 0.5rem 1rem;
28
+ cursor: pointer;
29
+ }
30
+
31
+ #state {
32
+ background: #f4f4f5;
33
+ border: 1px solid #e4e4e7;
34
+ border-radius: 8px;
35
+ padding: 1rem;
36
+ margin-bottom: 1rem;
37
+ white-space: pre-wrap;
38
+ font-family: ui-monospace, monospace;
39
+ font-size: 13px;
40
+ }
41
+
42
+ #logs {
43
+ background: #18181b;
44
+ color: #fafafa;
45
+ border-radius: 8px;
46
+ padding: 1rem;
47
+ min-height: 200px;
48
+ overflow: auto;
49
+ font-family: ui-monospace, monospace;
50
+ font-size: 12px;
51
+ }
52
+ </style>
53
+ </head>
54
+ <body>
55
+ <h1>Pixel v2 Playground</h1>
56
+
57
+ <h2>Lifecycle</h2>
58
+ <div class="actions">
59
+ <button id="reinit" type="button">Reinitialize Pixel</button>
60
+ <button id="destroy" type="button">Destroy Pixel</button>
61
+ </div>
62
+
63
+ <h2>SPA Navigation</h2>
64
+ <div class="actions">
65
+ <button id="pushState" type="button">PushState</button>
66
+ <button id="replaceState" type="button">ReplaceState</button>
67
+ <button id="back" type="button">Back</button>
68
+ <button id="forward" type="button">Forward</button>
69
+ <button id="hash" type="button">Hash Change</button>
70
+ </div>
71
+
72
+ <h2>Session</h2>
73
+ <div class="actions">
74
+ <button id="expireSession" type="button">Simulate Session Expiry</button>
75
+ <button id="trackPageView" type="button">Manual PageView</button>
76
+ </div>
77
+
78
+ <div id="state">Aguardando inicialização...</div>
79
+ <pre id="logs"></pre>
80
+
81
+ <script src="../../dist/v2/global.global.js"></script>
82
+ <script>
83
+ const { Pixel, DEFAULT_PIXEL_CONFIG, resolveStorageAdapterName } =
84
+ window.PixelV2;
85
+
86
+ const logsEl = document.getElementById('logs');
87
+ const stateEl = document.getElementById('state');
88
+
89
+ let pixel = null;
90
+ let pixelConfig = null;
91
+ let unsubscribe = null;
92
+ let lastEvent = '-';
93
+ let navCounter = 0;
94
+
95
+ function appendLog(message) {
96
+ const line = '[' + new Date().toISOString() + '] ' + message;
97
+ logsEl.textContent = line + '\n' + logsEl.textContent;
98
+ }
99
+
100
+ function formatTimestamp(value) {
101
+ if (!value) return '-';
102
+ return new Date(value).toISOString();
103
+ }
104
+
105
+ function renderState() {
106
+ const services = pixel ? pixel.getDebugServices() : null;
107
+ const initialized = pixel ? pixel.isInitialized() : false;
108
+ const metadata = services ? services.browserMetadata.getMetadata() : {};
109
+
110
+ if (!services || !pixelConfig) {
111
+ stateEl.textContent =
112
+ 'Runtime:\n' +
113
+ (initialized ? 'Initialized' : 'Not initialized') +
114
+ '\n\nCurrent URL:\n' +
115
+ (metadata.url || '-') +
116
+ '\n\nCurrent Path:\n' +
117
+ (metadata.path || '-');
118
+ return;
119
+ }
120
+
121
+ const persistence = pixelConfig.storage.persistence || {};
122
+ const listenerCount = services.dispatcher.getListenerCount();
123
+ const ttlMs = pixelConfig.modules.core.session.ttlMs;
124
+ const expired = services.session.isExpired(ttlMs);
125
+ const lastActivity = services.session.getLastActivityAt();
126
+
127
+ stateEl.textContent =
128
+ 'Runtime:\n' +
129
+ (initialized ? 'Initialized' : 'Not initialized') +
130
+ '\n\nCurrent URL:\n' +
131
+ (metadata.url || '-') +
132
+ '\n\nCurrent Path:\n' +
133
+ (metadata.path || '-') +
134
+ '\n\nHostname:\n' +
135
+ (metadata.hostname || '-') +
136
+ '\n\nLanguage:\n' +
137
+ (metadata.language || '-') +
138
+ '\n\nTimezone:\n' +
139
+ (metadata.timezone || '-') +
140
+ '\n\nStorage:\n' +
141
+ resolveStorageAdapterName(persistence.visitor) +
142
+ '\n\nVisitor Persistence:\n' +
143
+ (persistence.visitor || 'memory') +
144
+ '\n\nSession Persistence:\n' +
145
+ (persistence.session || 'memory') +
146
+ '\n\nFingerprint Persistence:\n' +
147
+ (persistence.attribution || 'memory') +
148
+ '\n\nVisitor:\n' +
149
+ (services.visitor.getVisitorId() || '-') +
150
+ '\n\nSession:\n' +
151
+ (services.session.getSessionId() || '-') +
152
+ '\n\nSession Status:\n' +
153
+ (expired ? 'Expired' : 'Active') +
154
+ '\n\nLast Activity:\n' +
155
+ formatTimestamp(lastActivity) +
156
+ '\n\nFingerprint:\n' +
157
+ (services.fingerprint.getFingerprint() || '-') +
158
+ '\n\nDispatcher:\n' +
159
+ listenerCount +
160
+ ' listener' +
161
+ (listenerCount === 1 ? '' : 's') +
162
+ '\n\nLast Event:\n' +
163
+ lastEvent;
164
+ }
165
+
166
+ function syncLastEvent(services) {
167
+ const dispatched = services.dispatcher.getLastEvent();
168
+ if (dispatched) {
169
+ lastEvent = JSON.stringify(dispatched, null, 2);
170
+ }
171
+ }
172
+
173
+ function subscribeDispatcher(services) {
174
+ if (unsubscribe) {
175
+ unsubscribe();
176
+ unsubscribe = null;
177
+ }
178
+
179
+ unsubscribe = services.dispatcher.subscribe(function (event) {
180
+ lastEvent = JSON.stringify(event, null, 2);
181
+ appendLog('Dispatcher: ' + event.type);
182
+ renderState();
183
+ });
184
+
185
+ syncLastEvent(services);
186
+ }
187
+
188
+ async function initPixel() {
189
+ if (pixel) {
190
+ await pixel.destroy();
191
+ pixel = null;
192
+ }
193
+
194
+ pixelConfig = {
195
+ ...DEFAULT_PIXEL_CONFIG,
196
+ app: {
197
+ ...DEFAULT_PIXEL_CONFIG.app,
198
+ debug: true,
199
+ },
200
+ identity: {
201
+ ...DEFAULT_PIXEL_CONFIG.identity,
202
+ pixelId: 'playground-pixel',
203
+ },
204
+ storage: {
205
+ ...DEFAULT_PIXEL_CONFIG.storage,
206
+ persistence: {
207
+ visitor: 'localStorage',
208
+ session: 'sessionStorage',
209
+ attribution: 'localStorage',
210
+ },
211
+ },
212
+ modules: {
213
+ ...DEFAULT_PIXEL_CONFIG.modules,
214
+ core: {
215
+ ...DEFAULT_PIXEL_CONFIG.modules.core,
216
+ enabled: true,
217
+ pageView: {
218
+ ...DEFAULT_PIXEL_CONFIG.modules.core.pageView,
219
+ enabled: true,
220
+ trackInitialPageView: true,
221
+ spa: true,
222
+ dedupeMs: 2000,
223
+ },
224
+ session: {
225
+ ...DEFAULT_PIXEL_CONFIG.modules.core.session,
226
+ enabled: true,
227
+ ttlMs: 10800000,
228
+ renewOnActivity: true,
229
+ },
230
+ },
231
+ },
232
+ };
233
+
234
+ pixel = new Pixel(pixelConfig);
235
+ await pixel.init();
236
+
237
+ const services = pixel.getDebugServices();
238
+ if (services) {
239
+ subscribeDispatcher(services);
240
+ }
241
+
242
+ appendLog('Pixel initialized');
243
+ renderState();
244
+ }
245
+
246
+ document.getElementById('reinit').addEventListener('click', function () {
247
+ initPixel().catch(function (error) {
248
+ appendLog('Init error: ' + String(error));
249
+ });
250
+ });
251
+
252
+ document
253
+ .getElementById('destroy')
254
+ .addEventListener('click', async function () {
255
+ if (!pixel) return;
256
+
257
+ await pixel.destroy();
258
+ pixel = null;
259
+
260
+ if (unsubscribe) {
261
+ unsubscribe();
262
+ unsubscribe = null;
263
+ }
264
+
265
+ lastEvent = '-';
266
+ appendLog('Pixel destroyed');
267
+ renderState();
268
+ });
269
+
270
+ document
271
+ .getElementById('pushState')
272
+ .addEventListener('click', function () {
273
+ navCounter += 1;
274
+ const path = '/checkout/step-' + navCounter;
275
+ history.pushState({}, '', path);
276
+ appendLog('Navigation: pushState -> ' + path);
277
+ renderState();
278
+ });
279
+
280
+ document
281
+ .getElementById('replaceState')
282
+ .addEventListener('click', function () {
283
+ const path = '/checkout/replaced-' + Date.now();
284
+ history.replaceState({}, '', path);
285
+ appendLog('Navigation: replaceState -> ' + path);
286
+ renderState();
287
+ });
288
+
289
+ document.getElementById('back').addEventListener('click', function () {
290
+ history.back();
291
+ appendLog('Navigation: back');
292
+ setTimeout(renderState, 50);
293
+ });
294
+
295
+ document.getElementById('forward').addEventListener('click', function () {
296
+ history.forward();
297
+ appendLog('Navigation: forward');
298
+ setTimeout(renderState, 50);
299
+ });
300
+
301
+ document.getElementById('hash').addEventListener('click', function () {
302
+ location.hash = 'section-' + Date.now();
303
+ appendLog('Navigation: hashchange');
304
+ renderState();
305
+ });
306
+
307
+ document
308
+ .getElementById('expireSession')
309
+ .addEventListener('click', function () {
310
+ const services = pixel ? pixel.getDebugServices() : null;
311
+ if (!services) return;
312
+
313
+ const data = services.session.getSessionData();
314
+ if (!data) {
315
+ appendLog('No session data to expire');
316
+ return;
317
+ }
318
+
319
+ const expiredData = {
320
+ ...data,
321
+ lastActivityAt:
322
+ Date.now() - pixelConfig.modules.core.session.ttlMs - 1000,
323
+ };
324
+
325
+ const sessionKey =
326
+ pixelConfig.storage.prefix +
327
+ ':' +
328
+ pixelConfig.storage.namespace +
329
+ ':session';
330
+
331
+ sessionStorage.setItem(sessionKey, JSON.stringify(expiredData));
332
+ appendLog('Session backdated beyond TTL');
333
+ renderState();
334
+ });
335
+
336
+ document
337
+ .getElementById('trackPageView')
338
+ .addEventListener('click', function () {
339
+ appendLog('Triggering PAGE_VIEW via navigation pushState');
340
+ navCounter += 1;
341
+ history.pushState({}, '', '/manual-' + navCounter);
342
+ renderState();
343
+ });
344
+
345
+ initPixel().catch(function (error) {
346
+ appendLog('Bootstrap error: ' + String(error));
347
+ });
348
+ </script>
349
+ </body>
350
+ </html>