@absmartly/sdk-plugins 1.2.2 → 1.3.0
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/dist/absmartly-cookie.min.js +1 -1
- package/dist/absmartly-dom-changes-core.min.js +1 -1
- package/dist/absmartly-dom-changes-lite.min.js +1 -1
- package/dist/absmartly-overrides-full.min.js +1 -1
- package/dist/absmartly-overrides-lite.min.js +1 -1
- package/dist/absmartly-sdk-plugins.min.js +1 -1
- package/dist/absmartly-vitals.min.js +1 -1
- package/es/analytics/AnalyticsPlugin.js +96 -0
- package/es/analytics/AnalyticsPlugin.js.map +1 -0
- package/es/analytics/index.js +2 -0
- package/es/analytics/index.js.map +1 -0
- package/es/analytics/types.js +2 -0
- package/es/analytics/types.js.map +1 -0
- package/es/cookies/CookiePlugin.js +59 -18
- package/es/cookies/CookiePlugin.js.map +1 -1
- package/es/core/DOMChangesPluginLite.js +203 -100
- package/es/core/DOMChangesPluginLite.js.map +1 -1
- package/es/core/DOMManipulatorLite.js +187 -131
- package/es/core/DOMManipulatorLite.js.map +1 -1
- package/es/core/ExposureTracker.js +310 -108
- package/es/core/ExposureTracker.js.map +1 -1
- package/es/core/HTMLInjector.js +11 -1
- package/es/core/HTMLInjector.js.map +1 -1
- package/es/core/PendingChangeManager.js +114 -54
- package/es/core/PendingChangeManager.js.map +1 -1
- package/es/generated/buildInfo.js +1 -1
- package/es/index.js +1 -0
- package/es/index.js.map +1 -1
- package/es/overrides/BrowserCookieAdapter.js +3 -31
- package/es/overrides/BrowserCookieAdapter.js.map +1 -1
- package/es/overrides/OverridesPlugin.js +39 -107
- package/es/overrides/OverridesPlugin.js.map +1 -1
- package/es/overrides/OverridesPluginLite.js +5 -136
- package/es/overrides/OverridesPluginLite.js.map +1 -1
- package/es/parsers/VariantExtractor.js +21 -18
- package/es/parsers/VariantExtractor.js.map +1 -1
- package/es/url-redirect/URLRedirectExtractor.js +8 -2
- package/es/url-redirect/URLRedirectExtractor.js.map +1 -1
- package/es/url-redirect/URLRedirectMatcher.js +130 -0
- package/es/url-redirect/URLRedirectMatcher.js.map +1 -1
- package/es/url-redirect/URLRedirectPlugin.js +14 -5
- package/es/url-redirect/URLRedirectPlugin.js.map +1 -1
- package/es/utils/URLMatcher.js.map +1 -1
- package/es/utils/debug.js +11 -0
- package/es/utils/debug.js.map +1 -1
- package/es/utils/persistence.js +143 -75
- package/es/utils/persistence.js.map +1 -1
- package/es/utils/plugin-registry.js.map +1 -1
- package/es/vitals/WebVitalsPlugin.js +9 -4
- package/es/vitals/WebVitalsPlugin.js.map +1 -1
- package/lib/analytics/AnalyticsPlugin.d.ts +8 -0
- package/lib/analytics/AnalyticsPlugin.js +99 -0
- package/lib/analytics/AnalyticsPlugin.js.map +1 -0
- package/lib/analytics/index.d.ts +2 -0
- package/lib/analytics/index.js +6 -0
- package/lib/analytics/index.js.map +1 -0
- package/lib/analytics/types.d.ts +5 -0
- package/lib/analytics/types.js +3 -0
- package/lib/analytics/types.js.map +1 -0
- package/lib/cookies/CookiePlugin.js +59 -18
- package/lib/cookies/CookiePlugin.js.map +1 -1
- package/lib/core/DOMChangesPluginLite.d.ts +3 -0
- package/lib/core/DOMChangesPluginLite.js +203 -100
- package/lib/core/DOMChangesPluginLite.js.map +1 -1
- package/lib/core/DOMManipulatorLite.js +187 -131
- package/lib/core/DOMManipulatorLite.js.map +1 -1
- package/lib/core/ExposureTracker.js +310 -108
- package/lib/core/ExposureTracker.js.map +1 -1
- package/lib/core/HTMLInjector.d.ts +1 -0
- package/lib/core/HTMLInjector.js +11 -1
- package/lib/core/HTMLInjector.js.map +1 -1
- package/lib/core/PendingChangeManager.js +114 -54
- package/lib/core/PendingChangeManager.js.map +1 -1
- package/lib/generated/buildInfo.d.ts +1 -1
- package/lib/generated/buildInfo.js +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/overrides/BrowserCookieAdapter.js +3 -31
- package/lib/overrides/BrowserCookieAdapter.js.map +1 -1
- package/lib/overrides/OverridesPlugin.js +39 -107
- package/lib/overrides/OverridesPlugin.js.map +1 -1
- package/lib/overrides/OverridesPluginLite.d.ts +5 -1
- package/lib/overrides/OverridesPluginLite.js +5 -136
- package/lib/overrides/OverridesPluginLite.js.map +1 -1
- package/lib/parsers/VariantExtractor.js +21 -18
- package/lib/parsers/VariantExtractor.js.map +1 -1
- package/lib/types/index.d.ts +5 -0
- package/lib/url-redirect/URLRedirectExtractor.js +8 -2
- package/lib/url-redirect/URLRedirectExtractor.js.map +1 -1
- package/lib/url-redirect/URLRedirectMatcher.d.ts +3 -0
- package/lib/url-redirect/URLRedirectMatcher.js +130 -0
- package/lib/url-redirect/URLRedirectMatcher.js.map +1 -1
- package/lib/url-redirect/URLRedirectPlugin.js +13 -4
- package/lib/url-redirect/URLRedirectPlugin.js.map +1 -1
- package/lib/url-redirect/types.d.ts +1 -1
- package/lib/utils/URLMatcher.d.ts +1 -7
- package/lib/utils/URLMatcher.js.map +1 -1
- package/lib/utils/debug.d.ts +5 -0
- package/lib/utils/debug.js +12 -0
- package/lib/utils/debug.js.map +1 -1
- package/lib/utils/persistence.js +143 -75
- package/lib/utils/persistence.js.map +1 -1
- package/lib/utils/plugin-registry.d.ts +1 -0
- package/lib/utils/plugin-registry.js.map +1 -1
- package/lib/vitals/WebVitalsPlugin.js +9 -4
- package/lib/vitals/WebVitalsPlugin.js.map +1 -1
- package/package.json +9 -3
- package/types/analytics/AnalyticsPlugin.d.ts +8 -0
- package/types/analytics/index.d.ts +2 -0
- package/types/analytics/types.d.ts +5 -0
- package/types/core/DOMChangesPluginLite.d.ts +3 -0
- package/types/core/HTMLInjector.d.ts +1 -0
- package/types/generated/buildInfo.d.ts +1 -1
- package/types/index.d.ts +2 -0
- package/types/overrides/OverridesPluginLite.d.ts +5 -1
- package/types/types/index.d.ts +5 -0
- package/types/url-redirect/URLRedirectMatcher.d.ts +3 -0
- package/types/url-redirect/types.d.ts +1 -1
- package/types/utils/URLMatcher.d.ts +1 -7
- package/types/utils/debug.d.ts +5 -0
- package/types/utils/plugin-registry.d.ts +1 -0
|
@@ -97,6 +97,9 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
97
97
|
this.persistenceManager = null;
|
|
98
98
|
this.antiFlickerTimeout = null;
|
|
99
99
|
this.antiFlickerStyleId = 'absmartly-antiflicker';
|
|
100
|
+
this.originalPushState = null;
|
|
101
|
+
this.originalReplaceState = null;
|
|
102
|
+
this.popstateHandler = null;
|
|
100
103
|
this.config = {
|
|
101
104
|
context: config.context,
|
|
102
105
|
autoApply: (_a = config.autoApply) !== null && _a !== void 0 ? _a : true,
|
|
@@ -203,6 +206,10 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
203
206
|
case 4:
|
|
204
207
|
error_1 = _a.sent();
|
|
205
208
|
(0, debug_1.logDebug)('[ABsmartly] Failed to initialize plugin:', error_1);
|
|
209
|
+
this.emit('error', {
|
|
210
|
+
type: 'initialization_error',
|
|
211
|
+
error: (error_1 === null || error_1 === void 0 ? void 0 : error_1.message) || String(error_1),
|
|
212
|
+
});
|
|
206
213
|
throw error_1;
|
|
207
214
|
case 5: return [2 /*return*/];
|
|
208
215
|
}
|
|
@@ -212,45 +219,96 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
212
219
|
DOMChangesPluginLite.prototype.setupMutationObserver = function () {
|
|
213
220
|
var _this = this;
|
|
214
221
|
var observer = new MutationObserver(function (mutations) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
// Check
|
|
224
|
-
var
|
|
225
|
-
|
|
226
|
-
|
|
222
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
|
|
223
|
+
var _f;
|
|
224
|
+
try {
|
|
225
|
+
// Re-apply ALL changes to elements that were replaced by React (hydration mismatch)
|
|
226
|
+
for (var mutations_1 = __values(mutations), mutations_1_1 = mutations_1.next(); !mutations_1_1.done; mutations_1_1 = mutations_1.next()) {
|
|
227
|
+
var mutation = mutations_1_1.value;
|
|
228
|
+
if (mutation.type === 'childList') {
|
|
229
|
+
try {
|
|
230
|
+
// Check if any added nodes match our applied change selectors
|
|
231
|
+
for (var _g = (e_2 = void 0, __values(mutation.addedNodes)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
232
|
+
var node = _h.value;
|
|
233
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
234
|
+
var element = node;
|
|
235
|
+
// Check all experiments with applied changes (not just style changes)
|
|
236
|
+
var appliedChanges = ((_f = _this.persistenceManager) === null || _f === void 0 ? void 0 : _f.getAppliedChanges()) || new Map();
|
|
227
237
|
try {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
for (var appliedChanges_1 = (e_3 = void 0, __values(appliedChanges)), appliedChanges_1_1 = appliedChanges_1.next(); !appliedChanges_1_1.done; appliedChanges_1_1 = appliedChanges_1.next()) {
|
|
239
|
+
var _j = __read(appliedChanges_1_1.value, 2), experimentName = _j[0], changes = _j[1];
|
|
240
|
+
try {
|
|
241
|
+
for (var changes_1 = (e_4 = void 0, __values(changes)), changes_1_1 = changes_1.next(); !changes_1_1.done; changes_1_1 = changes_1.next()) {
|
|
242
|
+
var change = changes_1_1.value;
|
|
243
|
+
try {
|
|
244
|
+
// Check if this new element or any of its descendants match the selector
|
|
245
|
+
var matchingElements = element.matches(change.selector)
|
|
246
|
+
? [element]
|
|
247
|
+
: Array.from(element.querySelectorAll(change.selector));
|
|
248
|
+
try {
|
|
249
|
+
for (var matchingElements_1 = (e_5 = void 0, __values(matchingElements)), matchingElements_1_1 = matchingElements_1.next(); !matchingElements_1_1.done; matchingElements_1_1 = matchingElements_1.next()) {
|
|
250
|
+
var matchingEl = matchingElements_1_1.value;
|
|
251
|
+
if (_this.config.debug) {
|
|
252
|
+
(0, debug_1.logDebug)('[SPA-REAPPLY] Re-applying change to newly added element (React hydration recovery)', {
|
|
253
|
+
experimentName: experimentName,
|
|
254
|
+
selector: change.selector,
|
|
255
|
+
element: matchingEl.tagName,
|
|
256
|
+
changeType: change.type,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
// Re-apply the change to the new element (ALL types: style, class, attribute, html, text, etc.)
|
|
260
|
+
_this.domManipulator.applyChange(change, experimentName);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
264
|
+
finally {
|
|
265
|
+
try {
|
|
266
|
+
if (matchingElements_1_1 && !matchingElements_1_1.done && (_e = matchingElements_1.return)) _e.call(matchingElements_1);
|
|
267
|
+
}
|
|
268
|
+
finally { if (e_5) throw e_5.error; }
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
catch (e) {
|
|
272
|
+
// Invalid selector, skip
|
|
273
|
+
}
|
|
274
|
+
}
|
|
240
275
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
276
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
277
|
+
finally {
|
|
278
|
+
try {
|
|
279
|
+
if (changes_1_1 && !changes_1_1.done && (_d = changes_1.return)) _d.call(changes_1);
|
|
280
|
+
}
|
|
281
|
+
finally { if (e_4) throw e_4.error; }
|
|
282
|
+
}
|
|
283
|
+
}
|
|
244
284
|
}
|
|
245
|
-
catch (
|
|
246
|
-
|
|
285
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
286
|
+
finally {
|
|
287
|
+
try {
|
|
288
|
+
if (appliedChanges_1_1 && !appliedChanges_1_1.done && (_c = appliedChanges_1.return)) _c.call(appliedChanges_1);
|
|
289
|
+
}
|
|
290
|
+
finally { if (e_3) throw e_3.error; }
|
|
247
291
|
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
250
294
|
}
|
|
251
|
-
|
|
295
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
296
|
+
finally {
|
|
297
|
+
try {
|
|
298
|
+
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
299
|
+
}
|
|
300
|
+
finally { if (e_2) throw e_2.error; }
|
|
301
|
+
}
|
|
302
|
+
}
|
|
252
303
|
}
|
|
253
|
-
}
|
|
304
|
+
}
|
|
305
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
306
|
+
finally {
|
|
307
|
+
try {
|
|
308
|
+
if (mutations_1_1 && !mutations_1_1.done && (_a = mutations_1.return)) _a.call(mutations_1);
|
|
309
|
+
}
|
|
310
|
+
finally { if (e_1) throw e_1.error; }
|
|
311
|
+
}
|
|
254
312
|
});
|
|
255
313
|
// Wait for document.body to exist before observing
|
|
256
314
|
// This prevents "parameter 1 is not of type 'Node'" errors when SDK loads in <head>
|
|
@@ -305,24 +363,23 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
305
363
|
});
|
|
306
364
|
}); };
|
|
307
365
|
// Listen to popstate (back/forward navigation)
|
|
308
|
-
|
|
366
|
+
this.popstateHandler = handleURLChange;
|
|
367
|
+
window.addEventListener('popstate', this.popstateHandler);
|
|
309
368
|
// Intercept pushState and replaceState
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
369
|
+
this.originalPushState = history.pushState;
|
|
370
|
+
this.originalReplaceState = history.replaceState;
|
|
371
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
372
|
+
var self = this;
|
|
373
|
+
history.pushState = function (data, unused, url) {
|
|
374
|
+
if (self.originalPushState) {
|
|
375
|
+
self.originalPushState.call(history, data, unused, url);
|
|
316
376
|
}
|
|
317
|
-
originalPushState.apply(history, args);
|
|
318
377
|
handleURLChange();
|
|
319
378
|
};
|
|
320
|
-
history.replaceState = function () {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
args[_i] = arguments[_i];
|
|
379
|
+
history.replaceState = function (data, unused, url) {
|
|
380
|
+
if (self.originalReplaceState) {
|
|
381
|
+
self.originalReplaceState.call(history, data, unused, url);
|
|
324
382
|
}
|
|
325
|
-
originalReplaceState.apply(history, args);
|
|
326
383
|
handleURLChange();
|
|
327
384
|
};
|
|
328
385
|
if (this.config.debug) {
|
|
@@ -336,18 +393,14 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
336
393
|
DOMChangesPluginLite.prototype.removeAllChanges = function () {
|
|
337
394
|
return __awaiter(this, void 0, void 0, function () {
|
|
338
395
|
return __generator(this, function (_a) {
|
|
339
|
-
//
|
|
396
|
+
// ExposureTracker will re-register on next applyChanges
|
|
340
397
|
this.exposedExperiments.clear();
|
|
341
|
-
//
|
|
342
|
-
// The stylesheets will be reused or cleared on next applyChanges
|
|
398
|
+
// StyleSheetManager doesn't have a remove method, stylesheets will be reused on next applyChanges
|
|
343
399
|
this.styleManagers.clear();
|
|
344
|
-
// Clear applied changes
|
|
345
400
|
if (this.persistenceManager) {
|
|
346
401
|
this.persistenceManager.clearAll();
|
|
347
402
|
}
|
|
348
|
-
// Clear HTML injections
|
|
349
403
|
this.htmlInjector.destroy();
|
|
350
|
-
// Clear variant extractor cache to force re-extraction
|
|
351
404
|
this.variantExtractor.clearCache();
|
|
352
405
|
if (this.config.debug) {
|
|
353
406
|
(0, debug_1.logDebug)('[ABsmartly] All change tracking cleared for URL change');
|
|
@@ -427,10 +480,10 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
427
480
|
};
|
|
428
481
|
DOMChangesPluginLite.prototype.applyChanges = function (experimentName) {
|
|
429
482
|
return __awaiter(this, void 0, void 0, function () {
|
|
430
|
-
var startTime, currentURL, error_3, allExperiments, totalApplied, experimentStats, allExperiments_1, allExperiments_1_1, _a, expName, experimentData, currentVariant, variantData, urlFilter, globalDefaults, anyVariantMatchesURL, shouldApplyVisualChanges, changes, allVariantChanges, hasAnyChangesInAnyVariant, stats,
|
|
431
|
-
var
|
|
432
|
-
return __generator(this, function (
|
|
433
|
-
switch (
|
|
483
|
+
var startTime, currentURL, error_3, allExperiments, totalApplied, experimentStats, allExperiments_1, allExperiments_1_1, _a, expName, experimentData, currentVariant, variantData, urlFilter, globalDefaults, anyVariantMatchesURL, shouldApplyVisualChanges, changes, allVariantChanges, hasAnyChangesInAnyVariant, stats, changes_2, changes_2_1, change, success, elements, hasAnyViewportTriggerInAnyVariant, hasAnyImmediateTriggerInAnyVariant, allVariantsData, allVariantsData_1, allVariantsData_1_1, _b, idx, data, allVariantsData_2, allVariantsData_2_1, _c, variantIndex, variantData_1, variantChanges, variantMatchesURL, config, urlFilterConfig, variantChanges_1, variantChanges_1_1, change, duration;
|
|
484
|
+
var e_6, _d, e_7, _e, e_8, _f, e_9, _g, e_10, _h;
|
|
485
|
+
return __generator(this, function (_j) {
|
|
486
|
+
switch (_j.label) {
|
|
434
487
|
case 0:
|
|
435
488
|
startTime = performance.now();
|
|
436
489
|
currentURL = window.location.href;
|
|
@@ -445,15 +498,15 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
445
498
|
(0, debug_1.logDebug)('[ABsmartly] Current URL:', currentURL);
|
|
446
499
|
(0, debug_1.logDebug)('[ABsmartly] Context ready:', true);
|
|
447
500
|
}
|
|
448
|
-
|
|
501
|
+
_j.label = 1;
|
|
449
502
|
case 1:
|
|
450
|
-
|
|
503
|
+
_j.trys.push([1, 3, , 4]);
|
|
451
504
|
return [4 /*yield*/, this.config.context.ready()];
|
|
452
505
|
case 2:
|
|
453
|
-
|
|
506
|
+
_j.sent();
|
|
454
507
|
return [3 /*break*/, 4];
|
|
455
508
|
case 3:
|
|
456
|
-
error_3 =
|
|
509
|
+
error_3 = _j.sent();
|
|
457
510
|
(0, debug_1.logDebug)('[ABsmartly] Failed to wait for context ready:', error_3);
|
|
458
511
|
return [2 /*return*/];
|
|
459
512
|
case 4:
|
|
@@ -539,8 +592,8 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
539
592
|
// Apply visual changes only if URL matches for user's variant AND user has changes
|
|
540
593
|
if (shouldApplyVisualChanges && changes && changes.length > 0) {
|
|
541
594
|
try {
|
|
542
|
-
for (
|
|
543
|
-
change =
|
|
595
|
+
for (changes_2 = (e_7 = void 0, __values(changes)), changes_2_1 = changes_2.next(); !changes_2_1.done; changes_2_1 = changes_2.next()) {
|
|
596
|
+
change = changes_2_1.value;
|
|
544
597
|
// Skip delete changes with viewport triggers - they must be applied AFTER exposure
|
|
545
598
|
// Otherwise the element is removed before it can be observed
|
|
546
599
|
if (change.type === 'delete' && change.trigger_on_view) {
|
|
@@ -570,12 +623,12 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
570
623
|
}
|
|
571
624
|
}
|
|
572
625
|
}
|
|
573
|
-
catch (
|
|
626
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
574
627
|
finally {
|
|
575
628
|
try {
|
|
576
|
-
if (
|
|
629
|
+
if (changes_2_1 && !changes_2_1.done && (_e = changes_2.return)) _e.call(changes_2);
|
|
577
630
|
}
|
|
578
|
-
finally { if (
|
|
631
|
+
finally { if (e_7) throw e_7.error; }
|
|
579
632
|
}
|
|
580
633
|
}
|
|
581
634
|
else if (changes && changes.length > 0) {
|
|
@@ -589,21 +642,31 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
589
642
|
allVariantsDataSize: allVariantsData.size,
|
|
590
643
|
allVariantChangesLength: allVariantChanges.length,
|
|
591
644
|
});
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
(0,
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
645
|
+
try {
|
|
646
|
+
// Log the structure of each variant's data
|
|
647
|
+
for (allVariantsData_1 = (e_8 = void 0, __values(allVariantsData)), allVariantsData_1_1 = allVariantsData_1.next(); !allVariantsData_1_1.done; allVariantsData_1_1 = allVariantsData_1.next()) {
|
|
648
|
+
_b = __read(allVariantsData_1_1.value, 2), idx = _b[0], data = _b[1];
|
|
649
|
+
(0, debug_1.logDebug)("[ABsmartly] Variant ".concat(idx, " data structure:"), {
|
|
650
|
+
isArray: Array.isArray(data),
|
|
651
|
+
isObject: typeof data === 'object',
|
|
652
|
+
hasUrlFilter: data && typeof data === 'object' && !Array.isArray(data) && 'urlFilter' in data,
|
|
653
|
+
keys: data && typeof data === 'object' && !Array.isArray(data) ? Object.keys(data) : 'N/A',
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
658
|
+
finally {
|
|
659
|
+
try {
|
|
660
|
+
if (allVariantsData_1_1 && !allVariantsData_1_1.done && (_f = allVariantsData_1.return)) _f.call(allVariantsData_1);
|
|
661
|
+
}
|
|
662
|
+
finally { if (e_8) throw e_8.error; }
|
|
663
|
+
}
|
|
601
664
|
}
|
|
602
665
|
try {
|
|
603
666
|
// Loop through ALL variants (not just ones with changes)
|
|
604
667
|
// We need to check URL filters from the raw data, which includes variants without changes
|
|
605
|
-
for (
|
|
606
|
-
|
|
668
|
+
for (allVariantsData_2 = (e_9 = void 0, __values(allVariantsData)), allVariantsData_2_1 = allVariantsData_2.next(); !allVariantsData_2_1.done; allVariantsData_2_1 = allVariantsData_2.next()) {
|
|
669
|
+
_c = __read(allVariantsData_2_1.value, 2), variantIndex = _c[0], variantData_1 = _c[1];
|
|
607
670
|
variantChanges = allVariantChanges[variantIndex];
|
|
608
671
|
if (!variantChanges || variantChanges.length === 0) {
|
|
609
672
|
continue;
|
|
@@ -623,7 +686,7 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
623
686
|
// Only collect trigger types from variants whose URL filters match
|
|
624
687
|
if (variantMatchesURL) {
|
|
625
688
|
try {
|
|
626
|
-
for (variantChanges_1 = (
|
|
689
|
+
for (variantChanges_1 = (e_10 = void 0, __values(variantChanges)), variantChanges_1_1 = variantChanges_1.next(); !variantChanges_1_1.done; variantChanges_1_1 = variantChanges_1.next()) {
|
|
627
690
|
change = variantChanges_1_1.value;
|
|
628
691
|
if (change.trigger_on_view) {
|
|
629
692
|
hasAnyViewportTriggerInAnyVariant = true;
|
|
@@ -637,12 +700,12 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
637
700
|
}
|
|
638
701
|
}
|
|
639
702
|
}
|
|
640
|
-
catch (
|
|
703
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
641
704
|
finally {
|
|
642
705
|
try {
|
|
643
|
-
if (variantChanges_1_1 && !variantChanges_1_1.done && (
|
|
706
|
+
if (variantChanges_1_1 && !variantChanges_1_1.done && (_h = variantChanges_1.return)) _h.call(variantChanges_1);
|
|
644
707
|
}
|
|
645
|
-
finally { if (
|
|
708
|
+
finally { if (e_10) throw e_10.error; }
|
|
646
709
|
}
|
|
647
710
|
if (this.config.debug) {
|
|
648
711
|
(0, debug_1.logDebug)("[ABsmartly] Variant ".concat(variantIndex, " matches URL - hasImmediate: ").concat(hasAnyImmediateTriggerInAnyVariant, ", hasViewport: ").concat(hasAnyViewportTriggerInAnyVariant));
|
|
@@ -658,12 +721,12 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
658
721
|
}
|
|
659
722
|
}
|
|
660
723
|
}
|
|
661
|
-
catch (
|
|
724
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
662
725
|
finally {
|
|
663
726
|
try {
|
|
664
|
-
if (
|
|
727
|
+
if (allVariantsData_2_1 && !allVariantsData_2_1.done && (_g = allVariantsData_2.return)) _g.call(allVariantsData_2);
|
|
665
728
|
}
|
|
666
|
-
finally { if (
|
|
729
|
+
finally { if (e_9) throw e_9.error; }
|
|
667
730
|
}
|
|
668
731
|
if (this.config.debug) {
|
|
669
732
|
(0, debug_1.logDebug)("[TRIGGER-DETECTION] [".concat(expName, "] Final trigger decision for '").concat(expName, "':"), {
|
|
@@ -709,12 +772,12 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
709
772
|
(0, debug_1.logExperimentSummary)(expName, stats.total, stats.success, stats.pending);
|
|
710
773
|
}
|
|
711
774
|
}
|
|
712
|
-
catch (
|
|
775
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
713
776
|
finally {
|
|
714
777
|
try {
|
|
715
|
-
if (allExperiments_1_1 && !allExperiments_1_1.done && (
|
|
778
|
+
if (allExperiments_1_1 && !allExperiments_1_1.done && (_d = allExperiments_1.return)) _d.call(allExperiments_1);
|
|
716
779
|
}
|
|
717
|
-
finally { if (
|
|
780
|
+
finally { if (e_6) throw e_6.error; }
|
|
718
781
|
}
|
|
719
782
|
duration = performance.now() - startTime;
|
|
720
783
|
(0, debug_1.logPerformance)('Apply changes', duration, {
|
|
@@ -754,7 +817,7 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
754
817
|
* Get all experiments with their variant data and metadata
|
|
755
818
|
*/
|
|
756
819
|
DOMChangesPluginLite.prototype.getAllExperimentsData = function () {
|
|
757
|
-
var
|
|
820
|
+
var e_11, _a;
|
|
758
821
|
var experiments = new Map();
|
|
759
822
|
var allVariants = this.variantExtractor.extractAllChanges();
|
|
760
823
|
(0, debug_1.logDebug)('[GET-EXPERIMENTS] Extracting experiment data from context', {
|
|
@@ -806,6 +869,8 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
806
869
|
globalDefaults = {
|
|
807
870
|
waitForElement: config.waitForElement,
|
|
808
871
|
persistStyle: config.persistStyle,
|
|
872
|
+
persistAttribute: config.persistAttribute,
|
|
873
|
+
persistScript: config.persistScript,
|
|
809
874
|
important: config.important,
|
|
810
875
|
observerRoot: config.observerRoot,
|
|
811
876
|
};
|
|
@@ -813,12 +878,12 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
813
878
|
experiments.set(expName, { variantData: variantData, urlFilter: urlFilter, globalDefaults: globalDefaults });
|
|
814
879
|
}
|
|
815
880
|
}
|
|
816
|
-
catch (
|
|
881
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
817
882
|
finally {
|
|
818
883
|
try {
|
|
819
884
|
if (allVariants_1_1 && !allVariants_1_1.done && (_a = allVariants_1.return)) _a.call(allVariants_1);
|
|
820
885
|
}
|
|
821
|
-
finally { if (
|
|
886
|
+
finally { if (e_11) throw e_11.error; }
|
|
822
887
|
}
|
|
823
888
|
return experiments;
|
|
824
889
|
};
|
|
@@ -842,8 +907,8 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
842
907
|
}
|
|
843
908
|
// Apply global defaults to each change
|
|
844
909
|
return changes.map(function (change) {
|
|
845
|
-
var _a, _b, _c, _d;
|
|
846
|
-
return (__assign(__assign({}, change), { waitForElement: (_a = change.waitForElement) !== null && _a !== void 0 ? _a : globalDefaults.waitForElement, persistStyle: (_b = change.persistStyle) !== null && _b !== void 0 ? _b : globalDefaults.persistStyle,
|
|
910
|
+
var _a, _b, _c, _d, _e, _f;
|
|
911
|
+
return (__assign(__assign({}, change), { waitForElement: (_a = change.waitForElement) !== null && _a !== void 0 ? _a : globalDefaults.waitForElement, persistStyle: (_b = change.persistStyle) !== null && _b !== void 0 ? _b : globalDefaults.persistStyle, persistAttribute: (_c = change.persistAttribute) !== null && _c !== void 0 ? _c : globalDefaults.persistAttribute, persistScript: (_d = change.persistScript) !== null && _d !== void 0 ? _d : globalDefaults.persistScript, important: (_e = change.important) !== null && _e !== void 0 ? _e : globalDefaults.important, observerRoot: (_f = change.observerRoot) !== null && _f !== void 0 ? _f : globalDefaults.observerRoot }));
|
|
847
912
|
});
|
|
848
913
|
};
|
|
849
914
|
/**
|
|
@@ -871,14 +936,16 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
871
936
|
globalDefaults = {
|
|
872
937
|
waitForElement: config.waitForElement,
|
|
873
938
|
persistStyle: config.persistStyle,
|
|
939
|
+
persistAttribute: config.persistAttribute,
|
|
940
|
+
persistScript: config.persistScript,
|
|
874
941
|
important: config.important,
|
|
875
942
|
observerRoot: config.observerRoot,
|
|
876
943
|
};
|
|
877
944
|
}
|
|
878
945
|
// Apply global defaults
|
|
879
946
|
var processedChanges = variantChanges.map(function (change) {
|
|
880
|
-
var _a, _b, _c, _d;
|
|
881
|
-
return (__assign(__assign({}, change), { waitForElement: (_a = change.waitForElement) !== null && _a !== void 0 ? _a : globalDefaults.waitForElement, persistStyle: (_b = change.persistStyle) !== null && _b !== void 0 ? _b : globalDefaults.persistStyle,
|
|
947
|
+
var _a, _b, _c, _d, _e, _f;
|
|
948
|
+
return (__assign(__assign({}, change), { waitForElement: (_a = change.waitForElement) !== null && _a !== void 0 ? _a : globalDefaults.waitForElement, persistStyle: (_b = change.persistStyle) !== null && _b !== void 0 ? _b : globalDefaults.persistStyle, persistAttribute: (_c = change.persistAttribute) !== null && _c !== void 0 ? _c : globalDefaults.persistAttribute, persistScript: (_d = change.persistScript) !== null && _d !== void 0 ? _d : globalDefaults.persistScript, important: (_e = change.important) !== null && _e !== void 0 ? _e : globalDefaults.important, observerRoot: (_f = change.observerRoot) !== null && _f !== void 0 ? _f : globalDefaults.observerRoot }));
|
|
882
949
|
});
|
|
883
950
|
processedVariants.push(processedChanges);
|
|
884
951
|
};
|
|
@@ -923,12 +990,23 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
923
990
|
change: change,
|
|
924
991
|
});
|
|
925
992
|
}
|
|
993
|
+
else {
|
|
994
|
+
this.emit('change_failed', {
|
|
995
|
+
experimentName: experimentName,
|
|
996
|
+
change: change,
|
|
997
|
+
reason: 'selector_not_found_or_apply_failed',
|
|
998
|
+
});
|
|
999
|
+
}
|
|
926
1000
|
return success;
|
|
927
1001
|
}
|
|
928
1002
|
catch (error) {
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
1003
|
+
(0, debug_1.logDebug)('[ABsmartly] Error applying change:', error);
|
|
1004
|
+
this.emit('error', {
|
|
1005
|
+
type: 'change_apply_error',
|
|
1006
|
+
experimentName: experimentName,
|
|
1007
|
+
change: change,
|
|
1008
|
+
error: (error === null || error === void 0 ? void 0 : error.message) || String(error),
|
|
1009
|
+
});
|
|
932
1010
|
return false;
|
|
933
1011
|
}
|
|
934
1012
|
};
|
|
@@ -950,7 +1028,7 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
950
1028
|
}
|
|
951
1029
|
};
|
|
952
1030
|
DOMChangesPluginLite.prototype.emit = function (event, data) {
|
|
953
|
-
var
|
|
1031
|
+
var e_12, _a;
|
|
954
1032
|
var listeners = this.eventListeners.get(event) || [];
|
|
955
1033
|
try {
|
|
956
1034
|
for (var listeners_1 = __values(listeners), listeners_1_1 = listeners_1.next(); !listeners_1_1.done; listeners_1_1 = listeners_1.next()) {
|
|
@@ -963,12 +1041,12 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
963
1041
|
}
|
|
964
1042
|
}
|
|
965
1043
|
}
|
|
966
|
-
catch (
|
|
1044
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
967
1045
|
finally {
|
|
968
1046
|
try {
|
|
969
1047
|
if (listeners_1_1 && !listeners_1_1.done && (_a = listeners_1.return)) _a.call(listeners_1);
|
|
970
1048
|
}
|
|
971
|
-
finally { if (
|
|
1049
|
+
finally { if (e_12) throw e_12.error; }
|
|
972
1050
|
}
|
|
973
1051
|
};
|
|
974
1052
|
DOMChangesPluginLite.prototype.getStyleManager = function (experimentName) {
|
|
@@ -1019,10 +1097,23 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
1019
1097
|
}
|
|
1020
1098
|
};
|
|
1021
1099
|
DOMChangesPluginLite.prototype.destroy = function () {
|
|
1100
|
+
var e_13, _a;
|
|
1022
1101
|
this.domManipulator.destroy();
|
|
1023
1102
|
this.exposureTracker.destroy();
|
|
1024
1103
|
this.htmlInjector.destroy();
|
|
1025
|
-
|
|
1104
|
+
try {
|
|
1105
|
+
for (var _b = __values(this.styleManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1106
|
+
var manager = _c.value;
|
|
1107
|
+
manager.destroy();
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
1111
|
+
finally {
|
|
1112
|
+
try {
|
|
1113
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1114
|
+
}
|
|
1115
|
+
finally { if (e_13) throw e_13.error; }
|
|
1116
|
+
}
|
|
1026
1117
|
this.styleManagers.clear();
|
|
1027
1118
|
if (this.mutationObserver) {
|
|
1028
1119
|
this.mutationObserver.disconnect();
|
|
@@ -1041,6 +1132,18 @@ var DOMChangesPluginLite = /** @class */ (function () {
|
|
|
1041
1132
|
if (antiFlickerStyle) {
|
|
1042
1133
|
antiFlickerStyle.remove();
|
|
1043
1134
|
}
|
|
1135
|
+
// Restore history methods
|
|
1136
|
+
if (this.originalPushState) {
|
|
1137
|
+
history.pushState = this.originalPushState;
|
|
1138
|
+
}
|
|
1139
|
+
if (this.originalReplaceState) {
|
|
1140
|
+
history.replaceState = this.originalReplaceState;
|
|
1141
|
+
}
|
|
1142
|
+
// Remove popstate listener
|
|
1143
|
+
if (this.popstateHandler) {
|
|
1144
|
+
window.removeEventListener('popstate', this.popstateHandler);
|
|
1145
|
+
this.popstateHandler = null;
|
|
1146
|
+
}
|
|
1044
1147
|
this.eventListeners.clear();
|
|
1045
1148
|
this.exposedExperiments.clear();
|
|
1046
1149
|
this.unregisterFromContext();
|