@absmartly/sdk-plugins 1.1.0 → 1.1.2
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/README.md +34 -33
- 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-sdk-plugins.min.js +1 -1
- package/dist/absmartly-vitals.min.js +1 -1
- package/es/cookies/CookiePlugin.js +10 -8
- package/es/cookies/CookiePlugin.js.map +1 -1
- package/es/core/DOMChangesPluginLite.js +130 -111
- package/es/core/DOMChangesPluginLite.js.map +1 -1
- package/es/core/DOMManipulatorLite.js +2 -1
- package/es/core/DOMManipulatorLite.js.map +1 -1
- package/es/core/ExposureTracker.js +6 -15
- package/es/core/ExposureTracker.js.map +1 -1
- package/es/parsers/VariantExtractor.js +71 -65
- package/es/parsers/VariantExtractor.js.map +1 -1
- package/es/vitals/WebVitalsPlugin.js +19 -4
- package/es/vitals/WebVitalsPlugin.js.map +1 -1
- package/lib/cookies/CookiePlugin.d.ts +2 -1
- package/lib/cookies/CookiePlugin.js +10 -8
- package/lib/cookies/CookiePlugin.js.map +1 -1
- package/lib/core/DOMChangesPluginLite.d.ts +3 -2
- package/lib/core/DOMChangesPluginLite.js +130 -111
- package/lib/core/DOMChangesPluginLite.js.map +1 -1
- package/lib/core/DOMManipulatorLite.js +2 -1
- package/lib/core/DOMManipulatorLite.js.map +1 -1
- package/lib/core/ExposureTracker.d.ts +4 -1
- package/lib/core/ExposureTracker.js +6 -15
- package/lib/core/ExposureTracker.js.map +1 -1
- package/lib/parsers/VariantExtractor.d.ts +4 -5
- package/lib/parsers/VariantExtractor.js +71 -65
- package/lib/parsers/VariantExtractor.js.map +1 -1
- package/lib/types/index.d.ts +4 -12
- package/lib/vitals/WebVitalsPlugin.d.ts +2 -0
- package/lib/vitals/WebVitalsPlugin.js +19 -4
- package/lib/vitals/WebVitalsPlugin.js.map +1 -1
- package/package.json +1 -1
- package/types/cookies/CookiePlugin.d.ts +2 -1
- package/types/core/DOMChangesPluginLite.d.ts +3 -2
- package/types/core/ExposureTracker.d.ts +4 -1
- package/types/parsers/VariantExtractor.d.ts +4 -5
- package/types/types/index.d.ts +4 -12
- package/types/vitals/WebVitalsPlugin.d.ts +2 -0
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ A comprehensive collection of plugins for the ABsmartly JavaScript SDK including
|
|
|
9
9
|
- **Smart Exposure Tracking**: Cross-variant tracking prevents sample ratio mismatch
|
|
10
10
|
- **Dynamic Content Support**: Pending changes with `waitForElement` for SPAs
|
|
11
11
|
- **React/Vue Compatibility**: StyleRules survive re-renders
|
|
12
|
-
- **
|
|
12
|
+
- **Anti-Flicker Support**: Hide content until experiments load to prevent visual flash
|
|
13
13
|
|
|
14
14
|
### 2. OverridesPlugin
|
|
15
15
|
- **Query String Overrides**: Force experiments via URL parameters
|
|
@@ -60,9 +60,7 @@ const domPlugin = new DOMChangesPlugin({
|
|
|
60
60
|
autoApply: true, // Automatically apply changes on init
|
|
61
61
|
spa: true, // Enable SPA support
|
|
62
62
|
visibilityTracking: true, // Track when changes become visible
|
|
63
|
-
|
|
64
|
-
dataSource: 'variable', // Use variables (or 'customField')
|
|
65
|
-
dataFieldName: '__dom_changes', // Variable/field name for DOM changes
|
|
63
|
+
variableName: '__dom_changes', // Variable name for DOM changes
|
|
66
64
|
debug: true // Enable debug logging
|
|
67
65
|
});
|
|
68
66
|
|
|
@@ -92,9 +90,9 @@ vitalsPlugin.ready().then(() => {
|
|
|
92
90
|
});
|
|
93
91
|
```
|
|
94
92
|
|
|
95
|
-
### With Experiment Overrides
|
|
93
|
+
### With Experiment Overrides
|
|
96
94
|
|
|
97
|
-
The OverridesPlugin enables experiment overrides for internal testing and
|
|
95
|
+
The OverridesPlugin enables experiment overrides for internal testing and development. Simply load it before SDK initialization and it will automatically check for and apply any overrides:
|
|
98
96
|
|
|
99
97
|
```javascript
|
|
100
98
|
import {
|
|
@@ -127,8 +125,7 @@ overridesPlugin.ready().then(() => {
|
|
|
127
125
|
const domPlugin = new DOMChangesPlugin({
|
|
128
126
|
context: context,
|
|
129
127
|
autoApply: true,
|
|
130
|
-
|
|
131
|
-
dataFieldName: '__dom_changes',
|
|
128
|
+
variableName: '__dom_changes',
|
|
132
129
|
debug: true
|
|
133
130
|
});
|
|
134
131
|
|
|
@@ -254,7 +251,7 @@ The plugin supports comprehensive DOM manipulation with advanced features:
|
|
|
254
251
|
}
|
|
255
252
|
```
|
|
256
253
|
|
|
257
|
-
### Style Rules (With Pseudo-States)
|
|
254
|
+
### Style Rules (With Pseudo-States)
|
|
258
255
|
```javascript
|
|
259
256
|
{
|
|
260
257
|
selector: '.button',
|
|
@@ -344,7 +341,7 @@ The plugin supports comprehensive DOM manipulation with advanced features:
|
|
|
344
341
|
}
|
|
345
342
|
```
|
|
346
343
|
|
|
347
|
-
### Pending Changes (Elements Not Yet in DOM)
|
|
344
|
+
### Pending Changes (Elements Not Yet in DOM)
|
|
348
345
|
```javascript
|
|
349
346
|
{
|
|
350
347
|
selector: '.lazy-loaded-button',
|
|
@@ -404,19 +401,11 @@ const changes = plugin.getAppliedChanges('experiment-name');
|
|
|
404
401
|
plugin.destroy();
|
|
405
402
|
```
|
|
406
403
|
|
|
407
|
-
## Browser Extension Integration
|
|
408
|
-
|
|
409
|
-
The plugin communicates with the ABsmartly Browser Extension for visual editing:
|
|
410
|
-
|
|
411
|
-
- **Automatic Detection**: Detects and connects to the extension
|
|
412
|
-
- **Message Protocol**: Two-way communication for preview mode and visual editing
|
|
413
|
-
- **Preview Support**: Test changes before creating experiments
|
|
414
|
-
|
|
415
404
|
## Documentation
|
|
416
405
|
|
|
417
406
|
For detailed documentation:
|
|
418
407
|
|
|
419
|
-
- **[
|
|
408
|
+
- **[Optimized Loading Guide](docs/OPTIMIZED_LOADING.md)** - Best practices for loading the SDK and plugins with minimal performance impact
|
|
420
409
|
- **[Exposure Tracking Guide](docs/EXPOSURE_TRACKING_GUIDE.md)** - Understanding trigger_on_view and preventing sample ratio mismatch
|
|
421
410
|
|
|
422
411
|
## Anti-Flicker Support
|
|
@@ -449,11 +438,20 @@ const domPlugin = new DOMChangesPlugin({
|
|
|
449
438
|
```javascript
|
|
450
439
|
const domPlugin = new DOMChangesPlugin({
|
|
451
440
|
context: context,
|
|
452
|
-
hideUntilReady: '
|
|
441
|
+
hideUntilReady: '[data-absmartly-hide]', // CSS selector for elements to hide
|
|
453
442
|
hideTransition: '0.4s ease-out'
|
|
454
443
|
});
|
|
455
444
|
```
|
|
456
445
|
|
|
446
|
+
**Hide multiple types of elements:**
|
|
447
|
+
```javascript
|
|
448
|
+
const domPlugin = new DOMChangesPlugin({
|
|
449
|
+
context: context,
|
|
450
|
+
hideUntilReady: '[data-absmartly-hide], [data-custom-hide], .test-element',
|
|
451
|
+
hideTransition: '0.3s ease-in'
|
|
452
|
+
});
|
|
453
|
+
```
|
|
454
|
+
|
|
457
455
|
### How It Works
|
|
458
456
|
|
|
459
457
|
1. **During Load (Before Experiments Applied):**
|
|
@@ -481,10 +479,11 @@ const domPlugin = new DOMChangesPlugin({
|
|
|
481
479
|
```javascript
|
|
482
480
|
new DOMChangesPlugin({
|
|
483
481
|
// Anti-flicker configuration
|
|
484
|
-
hideUntilReady: 'body', //
|
|
485
|
-
//
|
|
486
|
-
//
|
|
487
|
-
//
|
|
482
|
+
hideUntilReady: 'body', // CSS selector for elements to hide
|
|
483
|
+
// Examples:
|
|
484
|
+
// 'body' - hide entire page
|
|
485
|
+
// '[data-absmartly-hide]' - hide only marked elements
|
|
486
|
+
// '[data-absmartly-hide], .test' - hide multiple selectors
|
|
488
487
|
// false: disabled (default)
|
|
489
488
|
|
|
490
489
|
hideTimeout: 3000, // Max wait time in ms (default: 3000)
|
|
@@ -494,9 +493,6 @@ new DOMChangesPlugin({
|
|
|
494
493
|
hideTransition: '0.3s ease-in', // CSS transition for fade-in
|
|
495
494
|
// Examples: '0.3s ease-in', '0.5s linear'
|
|
496
495
|
// false: instant reveal (default)
|
|
497
|
-
|
|
498
|
-
hideSelector: '[data-absmartly-hide]' // Custom selector for 'elements' mode
|
|
499
|
-
// default: '[data-absmartly-hide]'
|
|
500
496
|
})
|
|
501
497
|
```
|
|
502
498
|
|
|
@@ -518,7 +514,7 @@ User sees: [Hidden] → Experiment Version (smooth fade-in)
|
|
|
518
514
|
|
|
519
515
|
### Best Practices
|
|
520
516
|
|
|
521
|
-
**✅ Use `hideUntilReady: '
|
|
517
|
+
**✅ Use `hideUntilReady: '[data-absmartly-hide]'` (Recommended)**
|
|
522
518
|
- Mark only elements being tested
|
|
523
519
|
- Faster perceived load time
|
|
524
520
|
- Better user experience
|
|
@@ -533,6 +529,14 @@ User sees: [Hidden] → Experiment Version (smooth fade-in)
|
|
|
533
529
|
<main>Rest of content visible immediately</main>
|
|
534
530
|
```
|
|
535
531
|
|
|
532
|
+
```javascript
|
|
533
|
+
const domPlugin = new DOMChangesPlugin({
|
|
534
|
+
context: context,
|
|
535
|
+
hideUntilReady: '[data-absmartly-hide]',
|
|
536
|
+
hideTransition: '0.3s ease-in'
|
|
537
|
+
});
|
|
538
|
+
```
|
|
539
|
+
|
|
536
540
|
**✅ Use `hideUntilReady: 'body'` (For whole-page experiments)**
|
|
537
541
|
- Complete redesigns
|
|
538
542
|
- Multiple changes across page
|
|
@@ -1077,16 +1081,13 @@ new DOMChangesPlugin({
|
|
|
1077
1081
|
spa: true, // Enable SPA support
|
|
1078
1082
|
// ✅ Auto-enables: waitForElement + persistStyle
|
|
1079
1083
|
visibilityTracking: true, // Track viewport visibility
|
|
1080
|
-
|
|
1081
|
-
dataSource: 'variable', // 'variable' or 'customField'
|
|
1082
|
-
dataFieldName: '__dom_changes', // Variable/field name for changes
|
|
1084
|
+
variableName: '__dom_changes', // Variable name for DOM changes
|
|
1083
1085
|
debug: false, // Enable debug logging
|
|
1084
1086
|
|
|
1085
1087
|
// Anti-flicker options
|
|
1086
|
-
hideUntilReady: false, // 'body'
|
|
1088
|
+
hideUntilReady: false, // CSS selector (e.g., 'body', '[data-absmartly-hide]') or false
|
|
1087
1089
|
hideTimeout: 3000, // Max wait time (ms)
|
|
1088
1090
|
hideTransition: false, // CSS transition (e.g., '0.3s ease-in') or false
|
|
1089
|
-
hideSelector: '[data-absmartly-hide]' // Custom selector for elements mode
|
|
1090
1091
|
})
|
|
1091
1092
|
```
|
|
1092
1093
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ABsmartlyCookie=t():e.ABsmartlyCookie=t()}(this,()=>(()=>{"use strict";var e={91:function(e,t,o){var i=this&&this.__awaiter||function(e,t,o,i){return new(o||(o=Promise))(function(r,a){function n(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o(function(e){e(t)})).then(n,s)}c((i=i.apply(e,t||[])).next())})},r=this&&this.__generator||function(e,t){var o,i,r,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},n=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return n.next=s(0),n.throw=s(1),n.return=s(2),"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function s(s){return function(c){return function(s){if(o)throw new TypeError("Generator is already executing.");for(;n&&(n=0,s[0]&&(a=0)),a;)try{if(o=1,i&&(r=2&s[0]?i.return:s[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,s[1])).done)return r;switch(i=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,i=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){a.label=s[1];break}if(6===s[0]&&a.label<r[1]){a.label=r[1],r=s;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(s);break}r[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],i=0}finally{o=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}},a=this&&this.__read||function(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var i,r,a=o.call(e),n=[];try{for(;(void 0===t||t-- >0)&&!(i=a.next()).done;)n.push(i.value)}catch(e){r={error:e}}finally{try{i&&!i.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}return n},n=this&&this.__spreadArray||function(e,t,o){if(o||2===arguments.length)for(var i,r=0,a=t.length;r<a;r++)!i&&r in t||(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.CookiePlugin=void 0;var s=o(609),c=o(319),l=function(){function e(e){void 0===e&&(e={}),this.context=e.context,this.debug=e.debug||!1,this.cookieDomain=e.cookieDomain||".absmartly.com",this.cookiePath=e.cookiePath||"/",this.sameSite=e.sameSite||"Lax",this.secure=e.secure||!1,this.cookieExpiryDays=e.cookieExpiryDays||730,this.unitIdCookieName=e.unitIdCookieName||"abs",this.publicIdCookieName=e.publicIdCookieName||"abs_public",this.expiryCookieName=e.expiryCookieName||"abs_expiry",this.utmCookieName=e.utmCookieName||"abs_utm_params",this.utmParams=e.utmParamsList||["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],this.autoUpdateExpiry=!1!==e.autoUpdateExpiry,this.expiryCheckInterval=e.expiryCheckInterval||30}return e.prototype.debugLog=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.debug&&s.logDebug.apply(void 0,n(["[CookiePlugin]"],a(e),!1))},e.prototype.setCookie=function(e,t,o){var i=void 0!==o?o:this.cookieExpiryDays,r=(0,c.setCookie)(e,t,i,{domain:this.cookieDomain,path:this.cookiePath,sameSite:this.sameSite,secure:this.secure});return r&&this.debugLog("Set cookie ".concat(e,":"),t),r},e.prototype.deleteCookie=function(e){(0,c.deleteCookie)(e,{domain:this.cookieDomain,path:this.cookiePath})},e.prototype.getUnitId=function(){if(this.unitId)return this.unitId;var e=navigator.cookieEnabled,t=(0,c.isLocalStorageAvailable)(),o=null;return e&&(o=(0,c.getCookie)(this.unitIdCookieName)||(0,c.getCookie)(this.publicIdCookieName)),!o&&t&&(o=localStorage.getItem("abs_id")),o&&(this.unitId=o),o},e.prototype.setUnitId=function(e){this.unitId=e;var t=navigator.cookieEnabled,o=(0,c.isLocalStorageAvailable)();t&&(this.setCookie(this.unitIdCookieName,e),this.setCookie(this.publicIdCookieName,e),this.autoUpdateExpiry&&this.updateExpiryTimestamp()),o&&localStorage.setItem("abs_id",e),this.debugLog("Unit ID set:",e)},e.prototype.generateAndSetUnitId=function(){var e=(0,c.generateUniqueId)();return this.setUnitId(e),e},e.prototype.updateExpiryTimestamp=function(){if(navigator.cookieEnabled){var e=Date.now();this.setCookie(this.expiryCookieName,e.toString()),this.debugLog("Updated expiry timestamp:",e)}},e.prototype.isExpiryFresh=function(){if(!navigator.cookieEnabled)return!1;var e=(0,c.getCookie)(this.expiryCookieName);if(!e)return!1;try{var t=parseInt(e,10),o=(Date.now()-t)/864e5,i=o<=this.expiryCheckInterval;return this.debugLog("Expiry check:",{daysSinceSet:o,isFresh:i}),i}catch(e){return this.debugLog("Error parsing expiry cookie:",e),!1}},e.prototype.getUtmParams=function(){var e={},t=new URLSearchParams(window.location.search);if(this.utmParams.forEach(function(o){var i=t.get(o);i&&(e[o]=i)}),0===Object.keys(e).length&&document.referrer)try{var o=new URL(document.referrer);this.utmParams.forEach(function(t){var i=o.searchParams.get(t);i&&(e[t]=i)})}catch(e){this.debugLog("Error parsing referrer URL:",e)}if(0===Object.keys(e).length){var i=this.getStoredUtmParams();if(i)return i}return e},e.prototype.storeUtmParams=function(e){if(0!==Object.keys(e).length){var t={params:e,timestamp:Date.now()},o=navigator.cookieEnabled;if((0,c.isLocalStorageAvailable)())try{localStorage.setItem(this.utmCookieName,JSON.stringify(t)),this.debugLog("Stored UTM params in localStorage:",e)}catch(e){this.debugLog("Failed to store UTM params in localStorage:",e)}o&&(this.setCookie(this.utmCookieName,JSON.stringify(t),30),this.debugLog("Stored UTM params in cookie:",e))}},e.prototype.getStoredUtmParams=function(){var e=null,t=(0,c.isLocalStorageAvailable)(),o=navigator.cookieEnabled;if(t)try{e=localStorage.getItem(this.utmCookieName)}catch(e){this.debugLog("Failed to get UTM params from localStorage:",e)}if(!e&&o&&(e=(0,c.getCookie)(this.utmCookieName)),e)try{var i=JSON.parse(e);if(Date.now()-i.timestamp<2592e6)return i.params}catch(e){this.debugLog("Failed to parse stored UTM params:",e)}return null},e.prototype.applyUtmAttributesToContext=function(e){var t=this,o=e||this.context;if(o){var i=this.getUtmParams();Object.keys(i).length>0&&this.storeUtmParams(i),Object.entries(i).forEach(function(e){var i=a(e,2),r=i[0],n=i[1],s=r.slice(4);o.attribute(s,n),t.debugLog("Set attribute ".concat(s,":"),n)})}else(0,s.logDebug)("[CookiePlugin] No context available to apply UTM attributes")},e.prototype.clearAllCookies=function(){this.deleteCookie(this.unitIdCookieName),this.deleteCookie(this.publicIdCookieName),this.deleteCookie(this.expiryCookieName),this.deleteCookie(this.utmCookieName),(0,c.isLocalStorageAvailable)()&&(localStorage.removeItem("abs_id"),localStorage.removeItem(this.utmCookieName)),this.unitId=void 0,this.debugLog("All cookies and storage cleared")},e.prototype.initialize=function(){return i(this,void 0,void 0,function(){var e;return r(this,function(t){return this.debugLog("Initializing CookiePlugin"),(e=this.getUnitId())?(this.debugLog("Using existing unit ID:",e),this.autoUpdateExpiry&&!this.isExpiryFresh()&&this.updateExpiryTimestamp()):(e=this.generateAndSetUnitId(),this.debugLog("Generated new unit ID:",e)),this.context&&this.applyUtmAttributesToContext(),this.debugLog("CookiePlugin initialized successfully"),[2]})})},e.prototype.setContext=function(e){this.context=e,this.debugLog("Context set for CookiePlugin")},e.prototype.needsWorkerCall=function(e){var t=e||new URLSearchParams(window.location.search);if(Array.from(t.keys()).some(function(e){return e.startsWith("exp_")}))return this.debugLog("Worker call needed due to experiment overrides"),!0;var o=this.getUnitId(),i=navigator.cookieEnabled,r=(0,c.isLocalStorageAvailable)();if(o){if(i&&!this.isExpiryFresh())return this.debugLog("Existing ID present but expiry not fresh - need worker call"),!0}else if(i||r){var a=(0,c.getCookie)(this.expiryCookieName);return this.debugLog(a?"No existing ID but expiry cookie exists - need worker call":"No existing ID and no expiry cookie - need worker call"),!0}return!1},e.prototype.trackLanding=function(e){var t=e||this.context;if(t){var o=new URLSearchParams(window.location.search),i=this.utmParams.some(function(e){return o.get(e)}),r=document.referrer,a=r&&!r.includes(this.cookieDomain.replace(".","")),n=navigator.cookieEnabled||(0,c.isLocalStorageAvailable)(),l=!!((0,c.getCookie)(this.unitIdCookieName)||(0,c.getCookie)(this.publicIdCookieName)||(0,c.getCookie)(this.expiryCookieName)||(0,c.isLocalStorageAvailable)()&&localStorage.getItem("abs_id"));if(i||a||n&&!l){var u={referrer_url:r||"",landing_url:window.location.href,accepts_cookies:navigator.cookieEnabled,accepts_storage:(0,c.isLocalStorageAvailable)(),has_utm:i};this.debugLog("Tracking landing:",u),t.track("landing",u)}}else(0,s.logDebug)("[CookiePlugin] No context available for tracking landing")},e}();t.CookiePlugin=l},319:(e,t)=>{function o(e,t,o,i){void 0===i&&(i={});try{var r=new Date;r.setTime(r.getTime()+24*o*60*60*1e3);var a="expires=".concat(r.toUTCString()),n=i.path||"/",s="".concat(e,"=").concat(t,";").concat(a,";path=").concat(n);i.domain&&"localhost"!==i.domain&&(s+=";domain=".concat(i.domain));var c=i.sameSite||"Lax";return s+=";SameSite=".concat(c),i.secure&&(s+=";Secure"),document.cookie=s,!0}catch(t){return console.error("Unable to set cookie ".concat(e,":"),t),!1}}Object.defineProperty(t,"__esModule",{value:!0}),t.getCookie=function(e){var t,o="; ".concat(document.cookie).split("; ".concat(e,"="));if(2===o.length){return(null===(t=o.pop())||void 0===t?void 0:t.split(";").shift())||null}return null},t.setCookie=o,t.deleteCookie=function(e,t){void 0===t&&(t={});o(e,"",-1,t)},t.generateUniqueId=function(){return Date.now().toString(36)+Math.random().toString(36).substring(2)},t.generateUUID=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})},t.isLocalStorageAvailable=function(){try{var e="__localStorage_test__";return localStorage.setItem(e,e),localStorage.removeItem(e),!0}catch(e){return!1}}},609:function(e,t){var o=this&&this.__assign||function(){return o=Object.assign||function(e){for(var t,o=1,i=arguments.length;o<i;o++)for(var r in t=arguments[o])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},o.apply(this,arguments)},i=this&&this.__read||function(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var i,r,a=o.call(e),n=[];try{for(;(void 0===t||t-- >0)&&!(i=a.next()).done;)n.push(i.value)}catch(e){r={error:e}}finally{try{i&&!i.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}return n},r=this&&this.__spreadArray||function(e,t,o){if(o||2===arguments.length)for(var i,r=0,a=t.length;r<a;r++)!i&&r in t||(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))};function a(){for(var e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];if(t.DEBUG)if(2===e.length&&"string"==typeof e[0]&&"object"==typeof e[1]){var a=i(e,2),n=a[0],s=a[1];if(n.includes("Original state already stored"))return;if(n.includes("State store operation"))return;if(n.includes("Performance:")&&(null==s?void 0:s.duration)&&s.duration<5)return;if(n.includes("Message sent:")||n.includes("Message received:"))return;var c=(new Date).toISOString(),l="[ABsmartly Debug]";console.log("".concat(l," [").concat(c,"] ").concat(n),s)}else if(1===e.length&&"string"==typeof e[0]){if((n=e[0]).includes("Original state already stored"))return;if(n.includes("State store operation"))return;if(n.includes("Message sent:")||n.includes("Message received:"))return;c=(new Date).toISOString(),l="[ABsmartly Debug]";console.log("".concat(l," [").concat(c,"] ").concat(n))}else console.log.apply(console,r([],i(e),!1))}Object.defineProperty(t,"__esModule",{value:!0}),t.DEBUG=void 0,t.logDebug=a,t.logChangeApplication=function(e,o,i,r,n){if(t.DEBUG){a("".concat(n?"✓":"✗"," Applied ").concat(i," change to ").concat(r," element(s)"),{experimentName:e,selector:o,changeType:i,elementsCount:r,success:n})}},t.logChangeRemoval=function(e,o,i,r){if(t.DEBUG){a("Restored ".concat(r," element(s) to original state"),{experimentName:e,selector:o,changeType:i,elementsCount:r,action:"restore"})}},t.logExperimentSummary=function(e,o,i,r){if(t.DEBUG){a('Experiment "'.concat(e,'" summary'),{experimentName:e,totalChanges:o,successfulChanges:i,pendingChanges:r,successRate:o>0?"".concat(Math.round(i/o*100),"%"):"N/A"})}},t.logStateOperation=function(e,o,i,r){if(t.DEBUG){a("State ".concat(e," operation"),{operation:e,selector:o,changeType:i,experimentName:r})}},t.logVisibilityEvent=function(e,o,i){if(t.DEBUG){a(i?"Element became visible - experiment triggered":"Element visibility changed",{experimentName:e,selector:o.className||o.id||o.tagName,triggered:i,action:"visibility"})}},t.logMessage=function(e,o,i){if(t.DEBUG){a("Message ".concat(e,": ").concat(o),{direction:e,messageType:o,payload:i,bridge:"extension"})}},t.logPerformance=function(e,i,r){if(t.DEBUG){a("Performance: ".concat(e," took ").concat(i,"ms"),o({operation:e,duration:i,performance:!0},r))}},t.DEBUG=!1}},t={};function o(i){var r=t[i];if(void 0!==r)return r.exports;var a=t[i]={exports:{}};return e[i].call(a.exports,a,a.exports,o),a.exports}var i={};return(()=>{var e=i;Object.defineProperty(e,"__esModule",{value:!0}),e.CookiePlugin=void 0;var t=o(91);Object.defineProperty(e,"CookiePlugin",{enumerable:!0,get:function(){return t.CookiePlugin}}),e.default=t.CookiePlugin})(),i})());
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ABsmartlyCookie=t():e.ABsmartlyCookie=t()}(this,()=>(()=>{"use strict";var e={91:function(e,t,o){var i=this&&this.__awaiter||function(e,t,o,i){return new(o||(o=Promise))(function(r,a){function n(e){try{c(i.next(e))}catch(e){a(e)}}function s(e){try{c(i.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o(function(e){e(t)})).then(n,s)}c((i=i.apply(e,t||[])).next())})},r=this&&this.__generator||function(e,t){var o,i,r,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},n=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return n.next=s(0),n.throw=s(1),n.return=s(2),"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function s(s){return function(c){return function(s){if(o)throw new TypeError("Generator is already executing.");for(;n&&(n=0,s[0]&&(a=0)),a;)try{if(o=1,i&&(r=2&s[0]?i.return:s[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,s[1])).done)return r;switch(i=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,i=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){a.label=s[1];break}if(6===s[0]&&a.label<r[1]){a.label=r[1],r=s;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(s);break}r[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],i=0}finally{o=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}},a=this&&this.__read||function(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var i,r,a=o.call(e),n=[];try{for(;(void 0===t||t-- >0)&&!(i=a.next()).done;)n.push(i.value)}catch(e){r={error:e}}finally{try{i&&!i.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}return n},n=this&&this.__spreadArray||function(e,t,o){if(o||2===arguments.length)for(var i,r=0,a=t.length;r<a;r++)!i&&r in t||(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.CookiePlugin=void 0;var s=o(609),c=o(319),l=function(){function e(e){void 0===e&&(e={}),this.context=e.context,this.debug=e.debug||!1,this.cookieDomain=e.cookieDomain||".absmartly.com",this.cookiePath=e.cookiePath||"/",this.sameSite=e.sameSite||"Lax",this.secure=e.secure||!1,this.cookieExpiryDays=e.cookieExpiryDays||730,this.unitIdCookieName=e.unitIdCookieName||"abs",this.publicIdCookieName=e.publicIdCookieName||"abs_public",this.expiryCookieName=e.expiryCookieName||"abs_expiry",this.utmCookieName=e.utmCookieName||"abs_utm_params",this.utmParams=e.utmParamsList||["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],this.autoUpdateExpiry=!1!==e.autoUpdateExpiry,this.expiryCheckInterval=e.expiryCheckInterval||30}return e.prototype.debugLog=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.debug&&s.logDebug.apply(void 0,n(["[CookiePlugin]"],a(e),!1))},e.prototype.setCookie=function(e,t,o){var i=void 0!==o?o:this.cookieExpiryDays,r=(0,c.setCookie)(e,t,i,{domain:this.cookieDomain,path:this.cookiePath,sameSite:this.sameSite,secure:this.secure});return r&&this.debugLog("Set cookie ".concat(e,":"),t),r},e.prototype.deleteCookie=function(e){(0,c.deleteCookie)(e,{domain:this.cookieDomain,path:this.cookiePath})},e.prototype.getUnitId=function(){if(this.unitId)return this.unitId;var e=navigator.cookieEnabled,t=(0,c.isLocalStorageAvailable)(),o=null;return e&&(o=(0,c.getCookie)(this.unitIdCookieName)||(0,c.getCookie)(this.publicIdCookieName)),!o&&t&&(o=localStorage.getItem("abs_id")),o&&(this.unitId=o),o},e.prototype.setUnitId=function(e){this.unitId=e;var t=navigator.cookieEnabled,o=(0,c.isLocalStorageAvailable)();t&&(this.setCookie(this.unitIdCookieName,e),this.setCookie(this.publicIdCookieName,e),this.autoUpdateExpiry&&this.updateExpiryTimestamp()),o&&localStorage.setItem("abs_id",e),this.debugLog("Unit ID set:",e)},e.prototype.generateAndSetUnitId=function(){var e=(0,c.generateUniqueId)();return this.setUnitId(e),e},e.prototype.updateExpiryTimestamp=function(){if(navigator.cookieEnabled){var e=Date.now();this.setCookie(this.expiryCookieName,e.toString()),this.debugLog("Updated expiry timestamp:",e)}},e.prototype.isExpiryFresh=function(){if(!navigator.cookieEnabled)return!1;var e=(0,c.getCookie)(this.expiryCookieName);if(!e)return!1;try{var t=parseInt(e,10),o=(Date.now()-t)/864e5,i=o<=this.expiryCheckInterval;return this.debugLog("Expiry check:",{daysSinceSet:o,isFresh:i}),i}catch(e){return this.debugLog("Error parsing expiry cookie:",e),!1}},e.prototype.getUtmParams=function(){var e={},t=new URLSearchParams(window.location.search);if(this.utmParams.forEach(function(o){var i=t.get(o);i&&(e[o]=i)}),0===Object.keys(e).length&&document.referrer)try{var o=new URL(document.referrer);this.utmParams.forEach(function(t){var i=o.searchParams.get(t);i&&(e[t]=i)})}catch(e){this.debugLog("Error parsing referrer URL:",e)}if(0===Object.keys(e).length){var i=this.getStoredUtmParams();if(i)return i}return e},e.prototype.storeUtmParams=function(e){if(0!==Object.keys(e).length){var t={params:e,timestamp:Date.now()},o=navigator.cookieEnabled;if((0,c.isLocalStorageAvailable)())try{localStorage.setItem(this.utmCookieName,JSON.stringify(t)),this.debugLog("Stored UTM params in localStorage:",e)}catch(e){this.debugLog("Failed to store UTM params in localStorage:",e)}o&&(this.setCookie(this.utmCookieName,JSON.stringify(t),30),this.debugLog("Stored UTM params in cookie:",e))}},e.prototype.getStoredUtmParams=function(){var e=null,t=(0,c.isLocalStorageAvailable)(),o=navigator.cookieEnabled;if(t)try{e=localStorage.getItem(this.utmCookieName)}catch(e){this.debugLog("Failed to get UTM params from localStorage:",e)}if(!e&&o&&(e=(0,c.getCookie)(this.utmCookieName)),e)try{var i=JSON.parse(e);if(Date.now()-i.timestamp<2592e6)return i.params}catch(e){this.debugLog("Failed to parse stored UTM params:",e)}return null},e.prototype.applyUtmAttributesToContext=function(e){var t=this,o=e||this.context;if(o){var i=this.getUtmParams();Object.keys(i).length>0&&this.storeUtmParams(i),Object.entries(i).forEach(function(e){var i=a(e,2),r=i[0],n=i[1],s=r.slice(4);o.attribute(s,n),t.debugLog("Set attribute ".concat(s,":"),n)})}else(0,s.logDebug)("[CookiePlugin] No context available to apply UTM attributes")},e.prototype.clearAllCookies=function(){this.deleteCookie(this.unitIdCookieName),this.deleteCookie(this.publicIdCookieName),this.deleteCookie(this.expiryCookieName),this.deleteCookie(this.utmCookieName),(0,c.isLocalStorageAvailable)()&&(localStorage.removeItem("abs_id"),localStorage.removeItem(this.utmCookieName)),this.unitId=void 0,this.debugLog("All cookies and storage cleared")},e.prototype.ready=function(){return i(this,void 0,void 0,function(){var e;return r(this,function(t){return this.debugLog("Initializing CookiePlugin"),(e=this.getUnitId())?(this.debugLog("Using existing unit ID:",e),this.autoUpdateExpiry&&!this.isExpiryFresh()&&this.updateExpiryTimestamp()):(e=this.generateAndSetUnitId(),this.debugLog("Generated new unit ID:",e)),this.context&&this.applyUtmAttributesToContext(),this.debugLog("CookiePlugin initialized successfully"),[2]})})},e.prototype.initialize=function(){return i(this,void 0,void 0,function(){return r(this,function(e){return[2,this.ready()]})})},e.prototype.setContext=function(e){this.context=e,this.debugLog("Context set for CookiePlugin")},e.prototype.needsServerSideCookie=function(){var e=this.getUnitId(),t=navigator.cookieEnabled,o=(0,c.isLocalStorageAvailable)();if(e){if(t&&!this.isExpiryFresh())return this.debugLog("Existing ID present but expiry not fresh - need worker call"),!0}else if(t||o){var i=(0,c.getCookie)(this.expiryCookieName);return this.debugLog(i?"No existing ID but expiry cookie exists - need worker call":"No existing ID and no expiry cookie - need worker call"),!0}return!1},e.prototype.trackLanding=function(e){var t=e||this.context;if(t){var o=new URLSearchParams(window.location.search),i=this.utmParams.some(function(e){return o.get(e)}),r=document.referrer,a=r&&!r.includes(this.cookieDomain.replace(".","")),n=navigator.cookieEnabled||(0,c.isLocalStorageAvailable)(),l=!!((0,c.getCookie)(this.unitIdCookieName)||(0,c.getCookie)(this.publicIdCookieName)||(0,c.getCookie)(this.expiryCookieName)||(0,c.isLocalStorageAvailable)()&&localStorage.getItem("abs_id"));if(i||a||n&&!l){var u={referrer_url:r||"",landing_url:window.location.href,accepts_cookies:navigator.cookieEnabled,accepts_storage:(0,c.isLocalStorageAvailable)(),has_utm:i};this.debugLog("Tracking landing:",u),t.track("landing",u)}}else(0,s.logDebug)("[CookiePlugin] No context available for tracking landing")},e}();t.CookiePlugin=l},319:(e,t)=>{function o(e,t,o,i){void 0===i&&(i={});try{var r=new Date;r.setTime(r.getTime()+24*o*60*60*1e3);var a="expires=".concat(r.toUTCString()),n=i.path||"/",s="".concat(e,"=").concat(t,";").concat(a,";path=").concat(n);i.domain&&"localhost"!==i.domain&&(s+=";domain=".concat(i.domain));var c=i.sameSite||"Lax";return s+=";SameSite=".concat(c),i.secure&&(s+=";Secure"),document.cookie=s,!0}catch(t){return console.error("Unable to set cookie ".concat(e,":"),t),!1}}Object.defineProperty(t,"__esModule",{value:!0}),t.getCookie=function(e){var t,o="; ".concat(document.cookie).split("; ".concat(e,"="));if(2===o.length){return(null===(t=o.pop())||void 0===t?void 0:t.split(";").shift())||null}return null},t.setCookie=o,t.deleteCookie=function(e,t){void 0===t&&(t={});o(e,"",-1,t)},t.generateUniqueId=function(){return Date.now().toString(36)+Math.random().toString(36).substring(2)},t.generateUUID=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})},t.isLocalStorageAvailable=function(){try{var e="__localStorage_test__";return localStorage.setItem(e,e),localStorage.removeItem(e),!0}catch(e){return!1}}},609:function(e,t){var o=this&&this.__assign||function(){return o=Object.assign||function(e){for(var t,o=1,i=arguments.length;o<i;o++)for(var r in t=arguments[o])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},o.apply(this,arguments)},i=this&&this.__read||function(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var i,r,a=o.call(e),n=[];try{for(;(void 0===t||t-- >0)&&!(i=a.next()).done;)n.push(i.value)}catch(e){r={error:e}}finally{try{i&&!i.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}return n},r=this&&this.__spreadArray||function(e,t,o){if(o||2===arguments.length)for(var i,r=0,a=t.length;r<a;r++)!i&&r in t||(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))};function a(){for(var e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];if(t.DEBUG)if(2===e.length&&"string"==typeof e[0]&&"object"==typeof e[1]){var a=i(e,2),n=a[0],s=a[1];if(n.includes("Original state already stored"))return;if(n.includes("State store operation"))return;if(n.includes("Performance:")&&(null==s?void 0:s.duration)&&s.duration<5)return;if(n.includes("Message sent:")||n.includes("Message received:"))return;var c=(new Date).toISOString(),l="[ABsmartly Debug]";console.log("".concat(l," [").concat(c,"] ").concat(n),s)}else if(1===e.length&&"string"==typeof e[0]){if((n=e[0]).includes("Original state already stored"))return;if(n.includes("State store operation"))return;if(n.includes("Message sent:")||n.includes("Message received:"))return;c=(new Date).toISOString(),l="[ABsmartly Debug]";console.log("".concat(l," [").concat(c,"] ").concat(n))}else console.log.apply(console,r([],i(e),!1))}Object.defineProperty(t,"__esModule",{value:!0}),t.DEBUG=void 0,t.logDebug=a,t.logChangeApplication=function(e,o,i,r,n){if(t.DEBUG){a("".concat(n?"✓":"✗"," Applied ").concat(i," change to ").concat(r," element(s)"),{experimentName:e,selector:o,changeType:i,elementsCount:r,success:n})}},t.logChangeRemoval=function(e,o,i,r){if(t.DEBUG){a("Restored ".concat(r," element(s) to original state"),{experimentName:e,selector:o,changeType:i,elementsCount:r,action:"restore"})}},t.logExperimentSummary=function(e,o,i,r){if(t.DEBUG){a('Experiment "'.concat(e,'" summary'),{experimentName:e,totalChanges:o,successfulChanges:i,pendingChanges:r,successRate:o>0?"".concat(Math.round(i/o*100),"%"):"N/A"})}},t.logStateOperation=function(e,o,i,r){if(t.DEBUG){a("State ".concat(e," operation"),{operation:e,selector:o,changeType:i,experimentName:r})}},t.logVisibilityEvent=function(e,o,i){if(t.DEBUG){a(i?"Element became visible - experiment triggered":"Element visibility changed",{experimentName:e,selector:o.className||o.id||o.tagName,triggered:i,action:"visibility"})}},t.logMessage=function(e,o,i){if(t.DEBUG){a("Message ".concat(e,": ").concat(o),{direction:e,messageType:o,payload:i,bridge:"extension"})}},t.logPerformance=function(e,i,r){if(t.DEBUG){a("Performance: ".concat(e," took ").concat(i,"ms"),o({operation:e,duration:i,performance:!0},r))}},t.DEBUG=!1}},t={};function o(i){var r=t[i];if(void 0!==r)return r.exports;var a=t[i]={exports:{}};return e[i].call(a.exports,a,a.exports,o),a.exports}var i={};return(()=>{var e=i;Object.defineProperty(e,"__esModule",{value:!0}),e.CookiePlugin=void 0;var t=o(91);Object.defineProperty(e,"CookiePlugin",{enumerable:!0,get:function(){return t.CookiePlugin}}),e.default=t.CookiePlugin})(),i})());
|