@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.
- package/CHANGELOG.md +260 -4
- package/README.md +65 -118
- package/RELEASE_CANDIDATE.md +181 -36
- package/dist/{StorageFactory-BhpbB6Jj.d.mts → StorageFactory-CPghDPBj.d.mts} +2 -2
- package/dist/{StorageFactory-CAkJJqVD.d.ts → StorageFactory-tjfzk57c.d.ts} +2 -2
- package/dist/config/index.cjs.js +1 -1
- package/dist/config/index.cjs.js.map +1 -1
- package/dist/config/index.d.mts +4 -3
- package/dist/config/index.d.ts +4 -3
- package/dist/config/index.esm.js +1 -1
- package/dist/config/index.esm.js.map +1 -1
- package/dist/events/index.cjs.js +1 -1
- package/dist/events/index.cjs.js.map +1 -1
- package/dist/events/index.d.mts +2 -1
- package/dist/events/index.d.ts +2 -1
- package/dist/events/index.esm.js +1 -1
- package/dist/events/index.esm.js.map +1 -1
- package/dist/examples/html-script/README.md +24 -2
- package/dist/examples/html-script/RELEASE_CANDIDATE.md +20 -6
- package/dist/examples/html-script/add-payment-info/README.md +3 -3
- package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-autocomplete.html +66 -48
- package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-disabled.html +66 -48
- package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-fields.html +65 -47
- package/dist/examples/html-script/add-payment-info/example-add-payment-info-data-track.html +73 -47
- package/dist/examples/html-script/add-payment-info/example-add-payment-info-dedupe.html +65 -47
- package/dist/examples/html-script/add-payment-info/example-add-payment-info-manual.html +56 -47
- package/dist/examples/html-script/add-payment-info/example-add-payment-info-rules-card.html +65 -47
- package/dist/examples/html-script/add-payment-info/example-add-payment-info-security.html +65 -47
- package/dist/examples/html-script/add-to-cart/README.md +3 -3
- package/dist/examples/html-script/add-to-cart/example-add-to-cart-attribute.html +90 -70
- package/dist/examples/html-script/add-to-cart/example-add-to-cart-auto.html +103 -81
- package/dist/examples/html-script/add-to-cart/example-add-to-cart-click.html +101 -78
- package/dist/examples/html-script/add-to-cart/example-add-to-cart-dedupe.html +90 -70
- package/dist/examples/html-script/add-to-cart/example-add-to-cart-manual.html +81 -67
- package/dist/examples/html-script/add-to-cart/example-add-to-cart-order-bump.html +90 -70
- package/dist/examples/html-script/add-to-cart/example-add-to-cart-text.html +104 -81
- package/dist/examples/html-script/behavior/example-behavior-engagement.html +489 -0
- package/dist/examples/html-script/behavior/example-behavior-heartbeat.html +350 -0
- package/dist/examples/html-script/behavior/example-behavior-runtime-intelligence.html +433 -0
- package/dist/examples/html-script/behavior/example-behavior-viewport.html +397 -0
- package/dist/examples/html-script/{example-behavior.html → behavior/example-behavior.html} +23 -17
- package/dist/examples/html-script/example-checkout-commerce.html +825 -0
- package/dist/examples/html-script/example-integration.html +5 -5
- package/dist/examples/html-script/example-landing-commerce.html +380 -0
- package/dist/examples/html-script/example-runtime-diagnostics.html +108 -0
- package/dist/examples/html-script/example-transport.html +5 -5
- package/dist/examples/html-script/full-funnel/README.md +64 -0
- package/dist/examples/html-script/full-funnel/checkout.html +116 -0
- package/dist/examples/html-script/full-funnel/downsell.html +58 -0
- package/dist/examples/html-script/full-funnel/landing.html +99 -0
- package/dist/examples/html-script/full-funnel/thank-you.html +85 -0
- package/dist/examples/html-script/full-funnel/upsell.html +64 -0
- package/dist/examples/html-script/initiate-checkout/README.md +6 -6
- package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-attribute.html +94 -74
- package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-auto.html +102 -80
- package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-click.html +103 -80
- package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-manual.html +86 -72
- package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-snapshot.html +95 -75
- package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-submit.html +103 -83
- package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-text.html +105 -82
- package/dist/examples/html-script/lead/README.md +9 -7
- package/dist/examples/html-script/lead/example-lead-trigger-attribute.html +67 -47
- package/dist/examples/html-script/lead/example-lead-trigger-auto.html +78 -56
- package/dist/examples/html-script/lead/example-lead-trigger-click.html +78 -55
- package/dist/examples/html-script/release-candidate.html +187 -76
- package/dist/examples/html-script/remove-from-cart/README.md +1 -1
- package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-attribute.html +93 -73
- package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-css.html +93 -73
- package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-dedupe.html +93 -73
- package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-manual.html +84 -70
- package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-multi.html +94 -74
- package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-state.html +95 -75
- package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-text.html +98 -76
- package/dist/examples/html-script/search/README.md +1 -1
- package/dist/examples/html-script/search/example-search-attribute.html +66 -51
- package/dist/examples/html-script/search/example-search-button-sync.html +66 -51
- package/dist/examples/html-script/search/example-search-dedupe.html +66 -51
- package/dist/examples/html-script/search/example-search-input.html +67 -51
- package/dist/examples/html-script/search/example-search-manual.html +57 -48
- package/dist/examples/html-script/search/example-search-submit.html +66 -51
- package/dist/examples/html-script/search/example-search-text.html +71 -51
- package/dist/examples/html-script/url-context/example-url-context-allowed-domains.html +63 -0
- package/dist/examples/html-script/url-context/example-url-context-landing.html +70 -0
- package/dist/examples/html-script/url-context/example-url-context-upsell.html +67 -0
- package/dist/examples/html-script/url-context/example-url-context.html +171 -0
- package/dist/examples/html-script/view-content/README.md +1 -1
- package/dist/examples/html-script/view-content/example-view-content-attribute.html +85 -70
- package/dist/examples/html-script/view-content/example-view-content-css.html +85 -70
- package/dist/examples/html-script/view-content/example-view-content-dedupe.html +85 -70
- package/dist/examples/html-script/view-content/example-view-content-empty.html +85 -70
- package/dist/examples/html-script/view-content/example-view-content-manual.html +76 -67
- package/dist/examples/html-script/view-content/example-view-content-product-card.html +85 -70
- package/dist/examples/html-script/view-content/example-view-content-text.html +90 -73
- package/dist/examples/v2/README.md +4 -1
- package/dist/{index-DUfFzniE.d.ts → index-CQAyT5Od.d.ts} +170 -3
- package/dist/{index-DUfFzniE.d.mts → index-JlKPz4pp.d.mts} +170 -3
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +435 -12
- package/dist/index.d.ts +435 -12
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/{pixel-CbeF25mD.d.mts → pixel-BxZZx8l5.d.ts} +248 -72
- package/dist/{pixel-CbeF25mD.d.ts → pixel-CKc4OQUx.d.mts} +248 -72
- package/dist/{pixel-default-config-1VgLFOiL.d.mts → pixel-default-config-CJl-eypl.d.mts} +1 -1
- package/dist/{pixel-default-config-Bxb-Vdd8.d.ts → pixel-default-config-aAOujzwp.d.ts} +1 -1
- package/dist/runtime/index.cjs.js +1 -1
- package/dist/runtime/index.cjs.js.map +1 -1
- package/dist/runtime/index.d.mts +19 -26
- package/dist/runtime/index.d.ts +19 -26
- package/dist/runtime/index.esm.js +1 -1
- package/dist/runtime/index.esm.js.map +1 -1
- package/dist/services/index.cjs.js +1 -1
- package/dist/services/index.cjs.js.map +1 -1
- package/dist/services/index.d.mts +14 -6
- package/dist/services/index.d.ts +14 -6
- package/dist/services/index.esm.js +1 -1
- package/dist/services/index.esm.js.map +1 -1
- package/dist/types-BP8dz1gP.d.mts +19 -0
- package/dist/types-C75pQP31.d.ts +19 -0
- package/dist/types-DMhzHSVC.d.mts +293 -0
- package/dist/types-D_SsCur9.d.ts +293 -0
- package/dist/url-context-BjAsQoVl.d.mts +85 -0
- package/dist/url-context-BjAsQoVl.d.ts +85 -0
- package/dist/v2/global.global.js +1 -1
- package/dist/v2/global.global.js.map +1 -1
- package/dist/v2/index.cjs.js +1 -1
- package/dist/v2/index.cjs.js.map +1 -1
- package/dist/v2/index.d.mts +8 -6
- package/dist/v2/index.d.ts +8 -6
- package/dist/v2/index.esm.js +1 -1
- package/dist/v2/index.esm.js.map +1 -1
- package/docs/public/README.md +75 -0
- package/docs/public/api/exports.md +47 -0
- package/docs/public/api/pixel.md +65 -0
- package/docs/public/configuration/commerce.md +44 -0
- package/docs/public/configuration/modules.md +66 -0
- package/docs/public/configuration/overview.md +66 -0
- package/docs/public/events/catalog.md +65 -0
- package/docs/public/getting-started/installation.md +75 -0
- package/docs/public/getting-started/quick-start.md +77 -0
- package/docs/public/getting-started/react-nextjs.md +55 -0
- package/docs/public/getting-started/script-tag.md +57 -0
- package/docs/public/guides/funnel-checkout.md +52 -0
- package/docs/public/guides/funnel-downsell.md +53 -0
- package/docs/public/guides/funnel-full.md +64 -0
- package/docs/public/guides/funnel-landing.md +68 -0
- package/docs/public/guides/funnel-thank-you.md +48 -0
- package/docs/public/guides/funnel-upsell.md +72 -0
- package/docs/public/limitations.md +32 -0
- package/docs/public/privacy/limitations.md +33 -0
- package/docs/public/release-candidate/validation.md +37 -0
- package/docs/public/troubleshooting.md +55 -0
- package/package.json +13 -1
- package/dist/types-CTpRvFKZ.d.ts +0 -71
- package/dist/types-DGlBdsAy.d.mts +0 -71
|
@@ -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 — Behavior Heartbeat (Etapa 17)</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: system-ui, sans-serif;
|
|
10
|
+
margin: 0;
|
|
11
|
+
padding: 2rem;
|
|
12
|
+
max-width: 960px;
|
|
13
|
+
}
|
|
14
|
+
.hint {
|
|
15
|
+
background: #eff6ff;
|
|
16
|
+
border: 1px solid #bfdbfe;
|
|
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
|
+
.panels {
|
|
33
|
+
display: grid;
|
|
34
|
+
grid-template-columns: 1fr 1fr;
|
|
35
|
+
gap: 1rem;
|
|
36
|
+
margin: 1rem 0;
|
|
37
|
+
}
|
|
38
|
+
@media (max-width: 700px) {
|
|
39
|
+
.panels {
|
|
40
|
+
grid-template-columns: 1fr;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
.panel {
|
|
44
|
+
font-family: ui-monospace, monospace;
|
|
45
|
+
font-size: 12px;
|
|
46
|
+
border-radius: 8px;
|
|
47
|
+
padding: 1rem;
|
|
48
|
+
background: #f4f4f5;
|
|
49
|
+
border: 1px solid #e4e4e7;
|
|
50
|
+
}
|
|
51
|
+
.panel h3 {
|
|
52
|
+
margin: 0 0 0.75rem;
|
|
53
|
+
font-size: 13px;
|
|
54
|
+
font-family: system-ui, sans-serif;
|
|
55
|
+
}
|
|
56
|
+
.panel pre {
|
|
57
|
+
margin: 0;
|
|
58
|
+
white-space: pre-wrap;
|
|
59
|
+
}
|
|
60
|
+
#logs {
|
|
61
|
+
background: #18181b;
|
|
62
|
+
color: #fafafa;
|
|
63
|
+
min-height: 220px;
|
|
64
|
+
max-height: 360px;
|
|
65
|
+
overflow: auto;
|
|
66
|
+
margin-top: 1rem;
|
|
67
|
+
border-radius: 8px;
|
|
68
|
+
padding: 1rem;
|
|
69
|
+
font-family: ui-monospace, monospace;
|
|
70
|
+
font-size: 12px;
|
|
71
|
+
}
|
|
72
|
+
</style>
|
|
73
|
+
</head>
|
|
74
|
+
<body>
|
|
75
|
+
<h1>Behavior Heartbeat Runtime</h1>
|
|
76
|
+
<p class="hint">
|
|
77
|
+
Etapa 17 — dados fictícios. Heartbeat mede presença e emite
|
|
78
|
+
<code>BEHAVIOR_HEARTBEAT</code> via Dispatcher (não chama Transport
|
|
79
|
+
diretamente). Intervalo de demo: 3s · <code>fireImmediately: true</code>.
|
|
80
|
+
</p>
|
|
81
|
+
|
|
82
|
+
<div class="actions">
|
|
83
|
+
<button type="button" id="btn-init">Init</button>
|
|
84
|
+
<button type="button" id="btn-snapshot">Get Snapshot</button>
|
|
85
|
+
<button type="button" id="btn-activity">Simulate Activity</button>
|
|
86
|
+
<button type="button" id="btn-idle">Simulate Idle</button>
|
|
87
|
+
<button type="button" id="btn-hidden">Simulate Hidden</button>
|
|
88
|
+
<button type="button" id="btn-visible">Simulate Visible</button>
|
|
89
|
+
<button type="button" id="btn-destroy">Destroy</button>
|
|
90
|
+
<button type="button" id="btn-reinit">Reinit</button>
|
|
91
|
+
<button type="button" id="btn-clear">Clear log</button>
|
|
92
|
+
</div>
|
|
93
|
+
|
|
94
|
+
<div class="panels">
|
|
95
|
+
<div class="panel">
|
|
96
|
+
<h3>Heartbeat counters</h3>
|
|
97
|
+
<pre id="counters">—</pre>
|
|
98
|
+
</div>
|
|
99
|
+
<div class="panel">
|
|
100
|
+
<h3>Debug snapshot.behavior.heartbeat</h3>
|
|
101
|
+
<pre id="hb-snap">—</pre>
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<div id="logs"></div>
|
|
106
|
+
|
|
107
|
+
<script src="../../../dist/v2/global.global.js"></script>
|
|
108
|
+
<script>
|
|
109
|
+
(function () {
|
|
110
|
+
const { Pixel, DEFAULT_PIXEL_CONFIG } = window.PixelV2;
|
|
111
|
+
const logsEl = document.getElementById('logs');
|
|
112
|
+
const countersEl = document.getElementById('counters');
|
|
113
|
+
const hbSnapEl = document.getElementById('hb-snap');
|
|
114
|
+
|
|
115
|
+
let pixel = null;
|
|
116
|
+
let unsubscribe = null;
|
|
117
|
+
const counts = {
|
|
118
|
+
BEHAVIOR_HEARTBEAT: 0,
|
|
119
|
+
USER_IDLE: 0,
|
|
120
|
+
USER_ACTIVE: 0,
|
|
121
|
+
VISIBILITY_CHANGE: 0,
|
|
122
|
+
other: 0,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
function log(msg, data) {
|
|
126
|
+
const line = document.createElement('div');
|
|
127
|
+
const ts = new Date().toISOString().slice(11, 23);
|
|
128
|
+
line.textContent =
|
|
129
|
+
'[' +
|
|
130
|
+
ts +
|
|
131
|
+
'] ' +
|
|
132
|
+
msg +
|
|
133
|
+
(data !== undefined ? ' ' + JSON.stringify(data) : '');
|
|
134
|
+
logsEl.prepend(line);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function refreshCounters() {
|
|
138
|
+
countersEl.textContent = JSON.stringify(counts, null, 2);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function refreshHbSnap() {
|
|
142
|
+
if (!pixel) {
|
|
143
|
+
hbSnapEl.textContent = 'null (no pixel)';
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const snap = pixel.getDebugSnapshot();
|
|
147
|
+
hbSnapEl.textContent = JSON.stringify(
|
|
148
|
+
snap.behavior && snap.behavior.heartbeat,
|
|
149
|
+
null,
|
|
150
|
+
2
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function buildConfig() {
|
|
155
|
+
return {
|
|
156
|
+
...DEFAULT_PIXEL_CONFIG,
|
|
157
|
+
identity: {
|
|
158
|
+
...DEFAULT_PIXEL_CONFIG.identity,
|
|
159
|
+
pixelId: 'heartbeat-demo',
|
|
160
|
+
},
|
|
161
|
+
modules: {
|
|
162
|
+
...DEFAULT_PIXEL_CONFIG.modules,
|
|
163
|
+
core: {
|
|
164
|
+
...DEFAULT_PIXEL_CONFIG.modules.core,
|
|
165
|
+
enabled: true,
|
|
166
|
+
pageView: {
|
|
167
|
+
...DEFAULT_PIXEL_CONFIG.modules.core.pageView,
|
|
168
|
+
enabled: false,
|
|
169
|
+
trackInitialPageView: false,
|
|
170
|
+
spa: false,
|
|
171
|
+
},
|
|
172
|
+
session: {
|
|
173
|
+
...DEFAULT_PIXEL_CONFIG.modules.core.session,
|
|
174
|
+
enabled: false,
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
privacy: {
|
|
178
|
+
...DEFAULT_PIXEL_CONFIG.modules.privacy,
|
|
179
|
+
enabled: false,
|
|
180
|
+
},
|
|
181
|
+
conversion: {
|
|
182
|
+
...DEFAULT_PIXEL_CONFIG.modules.conversion,
|
|
183
|
+
enabled: false,
|
|
184
|
+
},
|
|
185
|
+
integrations: {
|
|
186
|
+
...DEFAULT_PIXEL_CONFIG.modules.integrations,
|
|
187
|
+
enabled: false,
|
|
188
|
+
},
|
|
189
|
+
transport: {
|
|
190
|
+
...DEFAULT_PIXEL_CONFIG.modules.transport,
|
|
191
|
+
enabled: false,
|
|
192
|
+
},
|
|
193
|
+
behavior: {
|
|
194
|
+
...DEFAULT_PIXEL_CONFIG.modules.behavior,
|
|
195
|
+
enabled: true,
|
|
196
|
+
heartbeat: {
|
|
197
|
+
enabled: true,
|
|
198
|
+
intervalMs: 15000,
|
|
199
|
+
hiddenIntervalMs: 60000,
|
|
200
|
+
emitWhenHidden: true,
|
|
201
|
+
emitWhenIdle: true,
|
|
202
|
+
includeSnapshot: true,
|
|
203
|
+
fireImmediately: true,
|
|
204
|
+
},
|
|
205
|
+
trackers: {
|
|
206
|
+
...DEFAULT_PIXEL_CONFIG.modules.behavior.trackers,
|
|
207
|
+
idle: {
|
|
208
|
+
enabled: true,
|
|
209
|
+
thresholdMs: 4000,
|
|
210
|
+
},
|
|
211
|
+
visibility: { enabled: true },
|
|
212
|
+
scroll: {
|
|
213
|
+
...DEFAULT_PIXEL_CONFIG.modules.behavior.trackers.scroll,
|
|
214
|
+
enabled: false,
|
|
215
|
+
},
|
|
216
|
+
click: {
|
|
217
|
+
...DEFAULT_PIXEL_CONFIG.modules.behavior.trackers.click,
|
|
218
|
+
enabled: false,
|
|
219
|
+
},
|
|
220
|
+
exitIntent: {
|
|
221
|
+
...DEFAULT_PIXEL_CONFIG.modules.behavior.trackers
|
|
222
|
+
.exitIntent,
|
|
223
|
+
enabled: false,
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function wireDispatcher() {
|
|
232
|
+
if (!pixel || unsubscribe) return;
|
|
233
|
+
const services = pixel.getDebugServices && pixel.getDebugServices();
|
|
234
|
+
if (!services || !services.dispatcher) {
|
|
235
|
+
log('dispatcher unavailable — use snapshot counters');
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
unsubscribe = services.dispatcher.subscribe(function (event) {
|
|
239
|
+
const t = event && event.type;
|
|
240
|
+
if (Object.prototype.hasOwnProperty.call(counts, t)) {
|
|
241
|
+
counts[t] += 1;
|
|
242
|
+
} else {
|
|
243
|
+
counts.other += 1;
|
|
244
|
+
}
|
|
245
|
+
log('event', {
|
|
246
|
+
type: t,
|
|
247
|
+
sequence: event.sequence,
|
|
248
|
+
active: event.active,
|
|
249
|
+
idle: event.idle,
|
|
250
|
+
visible: event.visible,
|
|
251
|
+
elapsedMs: event.elapsedMs,
|
|
252
|
+
});
|
|
253
|
+
refreshCounters();
|
|
254
|
+
refreshHbSnap();
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async function doInit() {
|
|
259
|
+
if (pixel && pixel.isInitialized()) {
|
|
260
|
+
log('already initialized');
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
pixel = new Pixel(buildConfig());
|
|
264
|
+
await pixel.init();
|
|
265
|
+
wireDispatcher();
|
|
266
|
+
log('init ok');
|
|
267
|
+
refreshHbSnap();
|
|
268
|
+
refreshCounters();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async function doDestroy() {
|
|
272
|
+
if (!pixel) return;
|
|
273
|
+
if (unsubscribe) {
|
|
274
|
+
unsubscribe();
|
|
275
|
+
unsubscribe = null;
|
|
276
|
+
}
|
|
277
|
+
await pixel.destroy();
|
|
278
|
+
log('destroy ok');
|
|
279
|
+
refreshHbSnap();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
document.getElementById('btn-init').onclick = function () {
|
|
283
|
+
doInit();
|
|
284
|
+
};
|
|
285
|
+
document.getElementById('btn-snapshot').onclick = function () {
|
|
286
|
+
if (!pixel) {
|
|
287
|
+
log('no pixel');
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const snap = pixel.getDebugSnapshot();
|
|
291
|
+
log('snapshot', snap.behavior);
|
|
292
|
+
refreshHbSnap();
|
|
293
|
+
};
|
|
294
|
+
document.getElementById('btn-activity').onclick = function () {
|
|
295
|
+
window.dispatchEvent(new Event('mousemove'));
|
|
296
|
+
log('simulate activity (mousemove)');
|
|
297
|
+
};
|
|
298
|
+
document.getElementById('btn-idle').onclick = function () {
|
|
299
|
+
log(
|
|
300
|
+
'simulate idle — aguarde thresholdMs do IdleTracker (4s sem atividade)'
|
|
301
|
+
);
|
|
302
|
+
};
|
|
303
|
+
document.getElementById('btn-hidden').onclick = function () {
|
|
304
|
+
try {
|
|
305
|
+
Object.defineProperty(document, 'visibilityState', {
|
|
306
|
+
configurable: true,
|
|
307
|
+
get: function () {
|
|
308
|
+
return 'hidden';
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
document.dispatchEvent(new Event('visibilitychange'));
|
|
312
|
+
log('simulate hidden');
|
|
313
|
+
} catch (err) {
|
|
314
|
+
log('simulate hidden failed', String(err));
|
|
315
|
+
}
|
|
316
|
+
refreshHbSnap();
|
|
317
|
+
};
|
|
318
|
+
document.getElementById('btn-visible').onclick = function () {
|
|
319
|
+
try {
|
|
320
|
+
Object.defineProperty(document, 'visibilityState', {
|
|
321
|
+
configurable: true,
|
|
322
|
+
get: function () {
|
|
323
|
+
return 'visible';
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
document.dispatchEvent(new Event('visibilitychange'));
|
|
327
|
+
log('simulate visible');
|
|
328
|
+
} catch (err) {
|
|
329
|
+
log('simulate visible failed', String(err));
|
|
330
|
+
}
|
|
331
|
+
refreshHbSnap();
|
|
332
|
+
};
|
|
333
|
+
document.getElementById('btn-destroy').onclick = function () {
|
|
334
|
+
doDestroy();
|
|
335
|
+
};
|
|
336
|
+
document.getElementById('btn-reinit').onclick = async function () {
|
|
337
|
+
await doDestroy();
|
|
338
|
+
await doInit();
|
|
339
|
+
log('reinit ok');
|
|
340
|
+
};
|
|
341
|
+
document.getElementById('btn-clear').onclick = function () {
|
|
342
|
+
logsEl.textContent = '';
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
refreshCounters();
|
|
346
|
+
log('ready — clique Init (requer dist/v2/global.global.js)');
|
|
347
|
+
})();
|
|
348
|
+
</script>
|
|
349
|
+
</body>
|
|
350
|
+
</html>
|