@walkeros/walker.js 0.0.7
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 +305 -0
- package/dist/index.d.mts +34 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.es5.js +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -0
- package/dist/walker.js +1 -0
- package/package.json +69 -0
package/README.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# Walker.js
|
|
2
|
+
|
|
3
|
+
A ready-to-use walkerOS bundle that combines the browser source, collector, and
|
|
4
|
+
dataLayer support into a single JavaScript file. Perfect for quickly adding
|
|
5
|
+
privacy-friendly event tracking to any website.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- ๐ **Drop-in ready** - Single JavaScript file with everything included
|
|
10
|
+
- ๐ **Privacy-first** - Built on walkerOS's privacy-centric architecture
|
|
11
|
+
- ๐ฏ **DOM tracking** - Automatic event collection via data attributes
|
|
12
|
+
- ๐ **DataLayer support** - Compatible with existing dataLayer implementations
|
|
13
|
+
- ๐ง **Flexible configuration** - Multiple ways to configure (inline, object, or
|
|
14
|
+
default)
|
|
15
|
+
- โก **Async loading** - Works seamlessly with async/defer script loading
|
|
16
|
+
- ๐ฆ **Queue support** - Events are queued until walker.js loads (elbLayer)
|
|
17
|
+
- ๐งช **Well tested** - Comprehensive test suite included
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
### 1. Add elbLayer Function (Recommended)
|
|
22
|
+
|
|
23
|
+
Add this before walker.js loads to queue events:
|
|
24
|
+
|
|
25
|
+
```html
|
|
26
|
+
<script>
|
|
27
|
+
function elb() {
|
|
28
|
+
(window.elbLayer = window.elbLayer || []).push(arguments);
|
|
29
|
+
}
|
|
30
|
+
</script>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Include walker.js
|
|
34
|
+
|
|
35
|
+
```html
|
|
36
|
+
<!-- Recommended: Async loading with configuration -->
|
|
37
|
+
<script async data-elbconfig="elbConfig" src="./walker.js"></script>
|
|
38
|
+
|
|
39
|
+
<!-- Or from CDN -->
|
|
40
|
+
<script
|
|
41
|
+
async
|
|
42
|
+
data-elbconfig="elbConfig"
|
|
43
|
+
src="https://cdn.jsdelivr.net/npm/@walkeros/walker.js@latest/dist/walker.js"
|
|
44
|
+
></script>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 3. Configure
|
|
48
|
+
|
|
49
|
+
#### Option A: Default Configuration
|
|
50
|
+
|
|
51
|
+
Just load the `walker.js` script - it will look for `window.elbConfig`:
|
|
52
|
+
|
|
53
|
+
```html
|
|
54
|
+
<script>
|
|
55
|
+
window.elbConfig = {
|
|
56
|
+
/* your config */
|
|
57
|
+
};
|
|
58
|
+
</script>
|
|
59
|
+
<script async src="./walker.js"></script>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### Option B: Named Configuration Object
|
|
63
|
+
|
|
64
|
+
Use `data-elbconfig` on the script tag to define the configuration object.
|
|
65
|
+
|
|
66
|
+
```html
|
|
67
|
+
<script>
|
|
68
|
+
window.trackingConfig = {
|
|
69
|
+
elb: 'elb', // Global function name
|
|
70
|
+
name: 'walkerjs', // Global instance name
|
|
71
|
+
dataLayer: true, // Enable dataLayer integration
|
|
72
|
+
collector: {
|
|
73
|
+
destinations: {
|
|
74
|
+
// Add your destinations here
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
</script>
|
|
79
|
+
<script async data-elbconfig="trackingConfig" src="./walker.js"></script>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### Option C: Inline Configuration
|
|
83
|
+
|
|
84
|
+
Configure directly in the script tag. Use simple key:value pairs separated by
|
|
85
|
+
semicolon.
|
|
86
|
+
|
|
87
|
+
```html
|
|
88
|
+
<script
|
|
89
|
+
async
|
|
90
|
+
data-elbconfig="elb:track;run:true;instance:myWalker"
|
|
91
|
+
src="./walker.js"
|
|
92
|
+
></script>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 3. Track Events
|
|
96
|
+
|
|
97
|
+
#### Automatic DOM Tracking
|
|
98
|
+
|
|
99
|
+
Add data attributes to your HTML:
|
|
100
|
+
|
|
101
|
+
```html
|
|
102
|
+
<!-- Product tracking -->
|
|
103
|
+
<div data-elb="product" data-elb-product="id:123;name:Blue T-Shirt;price:29.99">
|
|
104
|
+
<button data-elbaction="click:add">Add to Cart</button>
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<!-- Global properties -->
|
|
108
|
+
<div data-elbglobals="pagetype:product_detail"></div>
|
|
109
|
+
|
|
110
|
+
<!-- Context information -->
|
|
111
|
+
<div data-elbcontext="section:recommendations"></div>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### Manual Event Tracking
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
// Using the global elb function
|
|
118
|
+
elb('product add', {
|
|
119
|
+
id: '123',
|
|
120
|
+
price: 29.99,
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Configuration
|
|
125
|
+
|
|
126
|
+
### Configuration Options
|
|
127
|
+
|
|
128
|
+
Walker.js can be configured in multiple ways:
|
|
129
|
+
|
|
130
|
+
1. **Script tag with `data-elbconfig`** - Highest priority
|
|
131
|
+
2. **`window.elbConfig`** - Default fallback
|
|
132
|
+
3. **Manual initialization** - When `run: false`
|
|
133
|
+
|
|
134
|
+
### Full Configuration Object
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
window.elbConfig = {
|
|
138
|
+
// Global configuration
|
|
139
|
+
elb: 'elb', // Global function name (default: 'elb')
|
|
140
|
+
name: 'walkerjs', // Global instance name
|
|
141
|
+
run: true, // Auto-initialize (default: true)
|
|
142
|
+
|
|
143
|
+
// Browser source settings
|
|
144
|
+
browser: {
|
|
145
|
+
run: true, // Auto-start DOM tracking
|
|
146
|
+
session: true, // Enable session tracking
|
|
147
|
+
scope: document.body, // Tracking scope
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
// DataLayer integration
|
|
151
|
+
dataLayer: true, // Enable dataLayer
|
|
152
|
+
// or detailed config:
|
|
153
|
+
dataLayer: {
|
|
154
|
+
name: 'dataLayer', // DataLayer variable name
|
|
155
|
+
prefix: 'dataLayer', // Event prefix
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
// Collector configuration
|
|
159
|
+
collector: {
|
|
160
|
+
consent: { functional: true }, // Default consent state
|
|
161
|
+
destinations: {
|
|
162
|
+
// Your destinations
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Destination Configuration
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
const walkerjs = Walkerjs({
|
|
172
|
+
collector: {
|
|
173
|
+
destinations: {
|
|
174
|
+
console: {
|
|
175
|
+
type: 'console',
|
|
176
|
+
push: (event) => console.log(event),
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
api: {
|
|
180
|
+
type: 'custom-api',
|
|
181
|
+
push: async (event) => {
|
|
182
|
+
await fetch('/api/events', {
|
|
183
|
+
method: 'POST',
|
|
184
|
+
body: JSON.stringify(event),
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Advanced Usage
|
|
194
|
+
|
|
195
|
+
### Async Loading & Event Queueing
|
|
196
|
+
|
|
197
|
+
Walker.js supports async loading with automatic event queueing:
|
|
198
|
+
|
|
199
|
+
```html
|
|
200
|
+
<script>
|
|
201
|
+
// 1. Define elb function to queue events
|
|
202
|
+
function elb() {
|
|
203
|
+
(window.elbLayer = window.elbLayer || []).push(arguments);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// 2. Track events immediately (even before walker.js loads)
|
|
207
|
+
elb('page view');
|
|
208
|
+
elb('product view', { id: '123', name: 'Blue T-Shirt' });
|
|
209
|
+
</script>
|
|
210
|
+
|
|
211
|
+
<!-- 3. Walker.js will process queued events when it loads -->
|
|
212
|
+
<script async data-elbconfig="elbConfig" src="./walker.js"></script>
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**Benefits:**
|
|
216
|
+
|
|
217
|
+
- No timing issues with async scripts
|
|
218
|
+
- Events are never lost
|
|
219
|
+
- Works with any loading strategy (async, defer, dynamic)
|
|
220
|
+
- Zero dependencies for the queue function
|
|
221
|
+
|
|
222
|
+
### Build Variants
|
|
223
|
+
|
|
224
|
+
Walker.js provides multiple build formats:
|
|
225
|
+
|
|
226
|
+
- `walker.js` - Standard IIFE bundle for browsers
|
|
227
|
+
- `index.es5.js` - GTM-compatible ES2015 build
|
|
228
|
+
- `index.mjs` - ES modules for modern bundlers
|
|
229
|
+
- `index.js` - CommonJS for Node.js environments
|
|
230
|
+
|
|
231
|
+
## API Reference
|
|
232
|
+
|
|
233
|
+
### Factory Function
|
|
234
|
+
|
|
235
|
+
#### `createWalkerjs(config?): Walkerjs.Instance`
|
|
236
|
+
|
|
237
|
+
Creates a new walker.js instance with the provided configuration.
|
|
238
|
+
|
|
239
|
+
### Instance Properties
|
|
240
|
+
|
|
241
|
+
- `collector` - The walkerOS collector instance
|
|
242
|
+
- `elb` - Browser push function for event tracking
|
|
243
|
+
|
|
244
|
+
### Additional Methods
|
|
245
|
+
|
|
246
|
+
- `getAllEvents(scope?, prefix?)` - Get all trackable events on the page
|
|
247
|
+
- `getEvents(target, trigger, prefix?)` - Get events for a specific element and
|
|
248
|
+
trigger
|
|
249
|
+
- `getGlobals(prefix?, scope?)` - Get global properties from the page
|
|
250
|
+
|
|
251
|
+
### Utility Functions
|
|
252
|
+
|
|
253
|
+
You can also import and use the utility functions directly:
|
|
254
|
+
|
|
255
|
+
```javascript
|
|
256
|
+
import { getAllEvents, getEvents, getGlobals } from '@walkeros/walker.js';
|
|
257
|
+
|
|
258
|
+
// Get all events on the page
|
|
259
|
+
const events = getAllEvents();
|
|
260
|
+
|
|
261
|
+
// Get events for a specific button click
|
|
262
|
+
const button = document.querySelector('button');
|
|
263
|
+
const clickEvents = getEvents(button, 'click');
|
|
264
|
+
|
|
265
|
+
// Get global properties
|
|
266
|
+
const globals = getGlobals();
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## Development
|
|
270
|
+
|
|
271
|
+
### Building
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
npm run build
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Testing
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
npm test # Run tests once
|
|
281
|
+
npm run dev # Watch mode
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Development Server
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
npm run preview # Serve examples on localhost:3333
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## License
|
|
291
|
+
|
|
292
|
+
MIT License - see LICENSE file for details.
|
|
293
|
+
|
|
294
|
+
## Contributing
|
|
295
|
+
|
|
296
|
+
This package is part of the walkerOS monorepo. Please see the main repository
|
|
297
|
+
for contribution guidelines.
|
|
298
|
+
|
|
299
|
+
## Related Packages
|
|
300
|
+
|
|
301
|
+
- [@walkeros/collector](../../../packages/collector) - Core collector
|
|
302
|
+
- [@walkeros/web-source-browser](../../../packages/web/sources/browser) -
|
|
303
|
+
Browser source
|
|
304
|
+
- [@walkeros/web-source-dataLayer](../../../packages/web/sources/dataLayer) -
|
|
305
|
+
DataLayer source
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Collector } from '@walkeros/core';
|
|
2
|
+
import { SourceBrowser } from '@walkeros/web-source-browser';
|
|
3
|
+
export { getAllEvents, getEvents, getGlobals } from '@walkeros/web-source-browser';
|
|
4
|
+
import { SourceDataLayer } from '@walkeros/web-source-dataLayer';
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
[key: string]: DataLayer;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
interface Instance {
|
|
12
|
+
collector: Collector.Instance;
|
|
13
|
+
elb: SourceBrowser.BrowserPush;
|
|
14
|
+
}
|
|
15
|
+
interface Config {
|
|
16
|
+
collector?: Collector.InitConfig;
|
|
17
|
+
browser?: Partial<SourceBrowser.Settings>;
|
|
18
|
+
dataLayer?: boolean | Partial<SourceDataLayer.Settings>;
|
|
19
|
+
elb?: string;
|
|
20
|
+
name?: string;
|
|
21
|
+
run?: boolean;
|
|
22
|
+
}
|
|
23
|
+
type DataLayer = undefined | Array<unknown>;
|
|
24
|
+
|
|
25
|
+
type index_Config = Config;
|
|
26
|
+
type index_DataLayer = DataLayer;
|
|
27
|
+
type index_Instance = Instance;
|
|
28
|
+
declare namespace index {
|
|
29
|
+
export type { index_Config as Config, index_DataLayer as DataLayer, index_Instance as Instance };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare function createWalkerjs(config?: Config): Promise<Instance>;
|
|
33
|
+
|
|
34
|
+
export { index as Walkerjs, createWalkerjs, createWalkerjs as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Collector } from '@walkeros/core';
|
|
2
|
+
import { SourceBrowser } from '@walkeros/web-source-browser';
|
|
3
|
+
export { getAllEvents, getEvents, getGlobals } from '@walkeros/web-source-browser';
|
|
4
|
+
import { SourceDataLayer } from '@walkeros/web-source-dataLayer';
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
[key: string]: DataLayer;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
interface Instance {
|
|
12
|
+
collector: Collector.Instance;
|
|
13
|
+
elb: SourceBrowser.BrowserPush;
|
|
14
|
+
}
|
|
15
|
+
interface Config {
|
|
16
|
+
collector?: Collector.InitConfig;
|
|
17
|
+
browser?: Partial<SourceBrowser.Settings>;
|
|
18
|
+
dataLayer?: boolean | Partial<SourceDataLayer.Settings>;
|
|
19
|
+
elb?: string;
|
|
20
|
+
name?: string;
|
|
21
|
+
run?: boolean;
|
|
22
|
+
}
|
|
23
|
+
type DataLayer = undefined | Array<unknown>;
|
|
24
|
+
|
|
25
|
+
type index_Config = Config;
|
|
26
|
+
type index_DataLayer = DataLayer;
|
|
27
|
+
type index_Instance = Instance;
|
|
28
|
+
declare namespace index {
|
|
29
|
+
export type { index_Config as Config, index_DataLayer as DataLayer, index_Instance as Instance };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare function createWalkerjs(config?: Config): Promise<Instance>;
|
|
33
|
+
|
|
34
|
+
export { index as Walkerjs, createWalkerjs, createWalkerjs as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function _array_like_to_array(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function _array_with_holes(e){if(Array.isArray(e))return e}function _array_without_holes(e){if(Array.isArray(e))return _array_like_to_array(e)}function asyncGeneratorStep(e,t,n,r,o,a,i){try{var c=e[a](i),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(r,o)}function _async_to_generator(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var a=e.apply(t,n);function i(e){asyncGeneratorStep(a,r,o,i,c,"next",e)}function c(e){asyncGeneratorStep(a,r,o,i,c,"throw",e)}i(void 0)})}}function _define_property(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _instanceof(e,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function _iterable_to_array(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _iterable_to_array_limit(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,a=[],i=!0,c=!1;try{for(n=n.call(e);!(i=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);i=!0);}catch(e){c=!0,o=e}finally{try{i||null==n.return||n.return()}finally{if(c)throw o}}return a}}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _non_iterable_spread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _object_spread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){_define_property(e,t,n[t])})}return e}function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function _object_spread_props(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function _sliced_to_array(e,t){return _array_with_holes(e)||_iterable_to_array_limit(e,t)||_unsupported_iterable_to_array(e,t)||_non_iterable_rest()}function _to_consumable_array(e){return _array_without_holes(e)||_iterable_to_array(e)||_unsupported_iterable_to_array(e)||_non_iterable_spread()}function _type_of(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function _unsupported_iterable_to_array(e,t){if(e){if("string"==typeof e)return _array_like_to_array(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_array_like_to_array(e,t):void 0}}function _ts_generator(e,t){var n,r,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=c(0),i.throw=c(1),i.return=c(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(s){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}}var Walkerjs=function(){var e,t,n=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};n=_object_spread({},Xe,n);var r=Object.entries(t).reduce(function(t,r){var o=_sliced_to_array(r,2),a=o[0],i=o[1],c=e[a];return n.merge&&Array.isArray(c)&&Array.isArray(i)?t[a]=i.reduce(function(e,t){return e.includes(t)?e:_to_consumable_array(e).concat([t])},_to_consumable_array(c)):(n.extend||a in e)&&(t[a]=i),t},{});return n.shallow?_object_spread({},e,r):(Object.assign(e,r),e)},r=function(e){return Array.isArray(e)},o=function(e){return void 0!==e},a=function(e){return"object"==(void 0===e?"undefined":_type_of(e))&&null!==e&&!r(e)&&"[object Object]"===Object.prototype.toString.call(e)},i=function(e){return"string"==typeof e},c=function(e){var t=_object_spread({},arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}),n={},r=void 0===e;return Object.keys(t).forEach(function(o){t[o]&&(n[o]=!0,e&&e[o]&&(r=!0))}),!!r&&n},s=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:6,t="";t.length<e;)t+=(36*Math.random()|0).toString(36);return t},u=function(e){return Ke(e)?e:void 0},l=function(e,t,n){return function(){for(var r=arguments.length,o=new Array(r),a=0;a<r;a++)o[a]=arguments[a];try{return e.apply(void 0,_to_consumable_array(o))}catch(e){if(!t)return;return t(e)}finally{null==n||n()}}},d=function(e,t,n){return function(){for(var r=arguments.length,o=new Array(r),a=0;a<r;a++)o[a]=arguments[a];return _async_to_generator(function(){var r;return _ts_generator(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,4,6]),[4,e.apply(void 0,_to_consumable_array(o))];case 1:case 3:return[2,a.sent()];case 2:return r=a.sent(),t?[4,t(r)]:[2];case 4:return[4,null==n?void 0:n()];case 5:return a.sent(),[7];case 6:return[2]}})})()}},f=function(e,t){return _async_to_generator(function(){var n,o,a,i,c,s,u,l,d,f;return _ts_generator(this,function(_){return o=_sliced_to_array((e.event||"").split(" "),2),a=o[0],i=o[1],t&&a&&i?(s="",l=i,d=function(t){if(t)return(t=r(t)?t:[t]).find(function(t){return!t.condition||t.condition(e)})},t[u=a]||(u="*"),[2,((f=t[u])&&(f[l]||(l="*"),c=d(f[l])),c||(u="*",l="*",c=d(null===(n=t[u])||void 0===n?void 0:n[l])),c&&(s="".concat(u," ").concat(l)),{eventMapping:c,mappingKey:s})]):[2,{}]})})()},_=function(e){return _async_to_generator(function(e){var t,n,i,c,s,u,l,f,_,p,v,g,y,m=arguments;return _ts_generator(this,function(b){switch(b.label){case 0:if(t=m.length>1&&void 0!==m[1]?m[1]:{},n=m.length>2&&void 0!==m[2]?m[2]:{},!o(e))return[2];c=a(e)&&e.consent||n.consent||(null===(i=n.collector)||void 0===i?void 0:i.consent),s=r(t)?t:[t],u=!0,l=!1,f=void 0,b.label=1;case 1:b.trys.push([1,6,7,8]),_=s[Symbol.iterator](),b.label=2;case 2:return(u=(p=_.next()).done)?[3,5]:(v=p.value,[4,d(Ve)(e,v,_object_spread_props(_object_spread({},n),{consent:c}))]);case 3:if(g=b.sent(),o(g))return[2,g];b.label=4;case 4:return u=!0,[3,2];case 5:return[3,8];case 6:return y=b.sent(),l=!0,f=y,[3,8];case 7:try{u||null==_.return||_.return()}finally{if(l)throw f}return[7];case 8:return[2]}})}).apply(this,arguments)},p=function(e,t,n){return function(){for(var r=arguments.length,o=new Array(r),a=0;a<r;a++)o[a]=arguments[a];var i,c="post"+t,s=n["pre"+t],u=n[c];return i=s?s.apply(void 0,[{fn:e}].concat(_to_consumable_array(o))):e.apply(void 0,_to_consumable_array(o)),u&&(i=u.apply(void 0,[{fn:e,result:i}].concat(_to_consumable_array(o)))),i}},v=function(e,t,n,r){var o,a,i,c=n||[];if(n||(c=e.on[t]||[],Object.values(e.destinations).forEach(function(e){var n,r=null===(n=e.config.on)||void 0===n?void 0:n[t];r&&(c=c.concat(r))})),c.length)switch(t){case Ye.Commands.Consent:o=e,a=c,i=r||o.consent,a.forEach(function(e){Object.keys(i).filter(function(t){return t in e}).forEach(function(t){l(e[t])(o,i)})});break;case Ye.Commands.Ready:case Ye.Commands.Run:!function(e,t){e.allowed&&t.forEach(function(t){l(t)(e)})}(e,c);break;case Ye.Commands.Session:!function(e,t){e.session&&t.forEach(function(t){l(t)(e,e.session)})}(e,c)}},g=function(e,t,o,c){return _async_to_generator(function(){var s,u;return _ts_generator(this,function(l){switch(l.label){case 0:switch(t){case Ye.Commands.Config:return[3,1];case Ye.Commands.Consent:return[3,2];case Ye.Commands.Custom:return[3,5];case Ye.Commands.Destination:return[3,6];case Ye.Commands.Globals:return[3,9];case Ye.Commands.On:return[3,10];case Ye.Commands.Run:return[3,11];case Ye.Commands.User:return[3,13]}return[3,14];case 1:return a(o)&&n(e.config,o,{shallow:!1}),[3,14];case 2:return a(o)?[4,x(e,o)]:[3,4];case 3:s=l.sent(),l.label=4;case 4:return[3,14];case 5:return a(o)&&(e.custom=n(e.custom,o)),[3,14];case 6:return u=a(o)&&function(e){return"function"==typeof e}(o.push),u?[4,b(e,o,c)]:[3,8];case 7:u=s=l.sent(),l.label=8;case 8:return[3,14];case 9:return a(o)&&(e.globals=n(e.globals,o)),[3,14];case 10:return i(o)&&function(e,t,n){var o=e.on,a=o[t]||[],i=r(n)?n:[n];i.forEach(function(e){a.push(e)}),o[t]=a,v(e,t,i)}(e,o,c),[3,14];case 11:return[4,m(e,o)];case 12:return s=l.sent(),[3,14];case 13:a(o)&&n(e.user,o,{shallow:!1}),l.label=14;case 14:return[2,s||{ok:!0,successful:[],queued:[],failed:[]}]}})})()},y=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=function(e,t){return(void 0===e?"undefined":_type_of(e))==(void 0===t?"undefined":_type_of(t))}(t,"")?_object_spread({event:t},n):_object_spread({},n,t||{});if(!r.event)throw new Error("Event name is required");var o=_sliced_to_array(r.event.split(" "),2),a=o[0],i=o[1];if(!a||!i)throw new Error("Event name is invalid");if(a===$e.Walker)return{command:i};++e.count;var c=r.timestamp,s=void 0===c?Date.now():c,u=r.group,l=void 0===u?e.group:u,d=r.count,f=void 0===d?e.count:d,_=r.event,p=void 0===_?"".concat(a," ").concat(i):_,v=r.data,g=void 0===v?{}:v,y=r.context,m=void 0===y?{}:y,b=r.globals,h=void 0===b?e.globals:b,w=r.custom,k=void 0===w?{}:w,j=r.user,S=void 0===j?e.user:j,O=r.nested,x=void 0===O?[]:O,E=r.consent,C=void 0===E?e.consent:E,A=r.id,L=void 0===A?"".concat(s,"-").concat(l,"-").concat(f):A,P=r.trigger,q=void 0===P?"":P,D=r.entity,I=void 0===D?a:D,U=r.action,R=void 0===U?i:U,W=r.timing,N=void 0===W?0:W,X=r.version,M=void 0===X?{source:e.version,tagging:e.config.tagging||0}:X,T=r.source;return{event:{event:p,data:g,context:m,globals:h,custom:k,user:S,nested:x,consent:C,id:L,trigger:q,entity:I,action:R,timestamp:s,timing:N,group:l,count:f,version:M,source:void 0===T?{type:"collector",id:"",previous_id:""}:T}}},m=function(e,t){return _async_to_generator(function(){return _ts_generator(this,function(r){switch(r.label){case 0:return e.allowed=!0,e.count=0,e.group=s(),e.timing=Date.now(),t&&(t.consent&&(e.consent=n(e.consent,t.consent)),t.user&&(e.user=n(e.user,t.user)),t.globals&&(e.globals=n(e.config.globalsStatic||{},t.globals)),t.custom&&(e.custom=n(e.custom,t.custom))),Object.values(e.destinations).forEach(function(e){e.queue=[]}),e.round++,v(e,"run"),[4,h(e)];case 1:return[2,r.sent()]}})})()},b=function(e,t,n){return _async_to_generator(function(){var r,o,a;return _ts_generator(this,function(i){if(r=n||t.config||{init:!1},o=_object_spread_props(_object_spread({},t),{config:r}),!(a=r.id))do{a=s(4)}while(e.destinations[a]);return[2,(e.destinations[a]=o,!1!==r.queue&&(o.queue=_to_consumable_array(e.queue)),h(e,void 0,_define_property({},a,o)))]})})()},h=function(e,t,r){return _async_to_generator(function(){var o,a,i,s,u,l,f,p,v,g,y,m,b,h,S,O;return _ts_generator(this,function(x){switch(x.label){case 0:return o=e.allowed,a=e.consent,i=e.globals,s=e.user,o?(t&&e.queue.push(t),r||(r=e.destinations),[4,Promise.all(Object.entries(r||{}).map(function(r){var o=_sliced_to_array(r,2),u=o[0],l=o[1];return _async_to_generator(function(){var r,o,f,p,v;return _ts_generator(this,function(g){switch(g.label){case 0:return r=(l.queue||[]).map(function(e){return _object_spread_props(_object_spread({},e),{consent:a})}),l.queue=[],t?(o=Me(t),[4,Promise.all(Object.entries(l.config.policy||[]).map(function(n){var r=_sliced_to_array(n,2),a=r[0],i=r[1];return _async_to_generator(function(){var n;return _ts_generator(this,function(r){switch(r.label){case 0:return[4,_(t,i,{collector:e})];case 1:return n=r.sent(),o=function(e,t,n){for(var r=Me(e),o=t.split("."),a=r,i=0;i<o.length;i++){var c=o[i];i===o.length-1?a[c]=n:(c in a&&"object"==_type_of(a[c])&&null!==a[c]||(a[c]={}),a=a[c])}return r}(o,a,n),[2]}})})()}))]):[3,2];case 1:g.sent(),r.push(o),g.label=2;case 2:return r.length?(f=[],p=r.filter(function(e){var t=c(l.config.consent,a,e.consent);return!t||(e.consent=t,f.push(e),!1)}),l.queue.concat(p),f.length?[4,d(w)(e,l)]:[2,{id:u,destination:l,queue:r}]):[2,{id:u,destination:l,skipped:!0}];case 3:return g.sent()?(v=!1,l.dlq||(l.dlq=[]),[4,Promise.all(f.map(function(t){return _async_to_generator(function(){return _ts_generator(this,function(r){switch(r.label){case 0:return t.globals=n(i,t.globals),t.user=n(s,t.user),[4,d(k,function(n){return e.config.onError&&e.config.onError(n,e),v=!0,l.dlq.push([t,n]),!1})(e,l,t)];case 1:return[2,(r.sent(),t)]}})})()}))]):[2,{id:u,destination:l,queue:r}];case 4:return[2,(g.sent(),{id:u,destination:l,error:v})]}})})()}))]):[2,j({ok:!1})];case 1:u=x.sent(),l=[],f=[],p=[],v=!0,g=!1,y=void 0;try{for(m=u[Symbol.iterator]();!(v=(b=m.next()).done);v=!0)(h=b.value).skipped||(S=h.destination,O={id:h.id,destination:S},h.error?p.push(O):h.queue&&h.queue.length?(S.queue=(S.queue||[]).concat(h.queue),f.push(O)):l.push(O))}catch(e){g=!0,y=e}finally{try{v||null==m.return||m.return()}finally{if(g)throw y}}return[2,j({ok:!p.length,event:t,successful:l,queued:f,failed:p})]}})})()},w=function(e,t){return _async_to_generator(function(){var n,r;return _ts_generator(this,function(o){switch(o.label){case 0:return!t.init||t.config.init?[3,2]:(n={collector:e,config:t.config,wrap:O(t,e)},[4,p(t.init,"DestinationInit",e.hooks)(n)]);case 1:if(!1===(r=o.sent()))return[2,r];t.config=_object_spread_props(_object_spread({},r||t.config),{init:!0}),o.label=2;case 2:return[2,!0]}})})()},k=function(e,t,r){return _async_to_generator(function(){var i,c,s,u,l,d,v,g,y,m,b;return _ts_generator(this,function(h){switch(h.label){case 0:return i=t.config,[4,f(r,i.mapping)];case 1:return c=h.sent(),s=c.eventMapping,u=c.mappingKey,(d=i.data)?[4,_(r,i.data,{collector:e})]:[3,3];case 2:d=h.sent(),h.label=3;case 3:return l=d,s?s.ignore?[2,!1]:(s.name&&(r.event=s.name),s.data?(g=s.data)?[4,_(r,s.data,{collector:e})]:[3,5]:[3,6]):[3,6];case 4:g=h.sent(),h.label=5;case 5:v=g,l=a(l)&&a(v)?n(l,v):v,h.label=6;case 6:return y={collector:e,config:i,data:l,mapping:s,wrap:O(t,e)},(null==s?void 0:s.batch)&&t.pushBatch?((b=s.batched||{key:u||"",events:[],data:[]}).events.push(r),o(l)&&b.data.push(l),s.batchFn=s.batchFn||function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e3,r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=null,a=!1;return function(){for(var i=arguments.length,c=new Array(i),s=0;s<i;s++)c[s]=arguments[s];return new Promise(function(i){var s=r&&!a;o&&clearTimeout(o),o=setTimeout(function(){o=null,r&&!a||(t=e.apply(void 0,_to_consumable_array(c)),i(t))},n),s&&(a=!0,t=e.apply(void 0,_to_consumable_array(c)),i(t))})}}(function(e,t){var n={collector:t,config:i,data:l,mapping:s,wrap:O(e,t)};p(e.pushBatch,"DestinationPushBatch",t.hooks)(b,n),b.events=[],b.data=[]},s.batch),s.batched=b,null===(m=s.batchFn)||void 0===m||m.call(s,t,e),[3,9]):[3,7];case 7:return[4,p(t.push,"DestinationPush",e.hooks)(r,y)];case 8:h.sent(),h.label=9;case 9:return[2,!0]}})})()},j=function(e){var t;return n({ok:!(null==e||null===(t=e.failed)||void 0===t?void 0:t.length),successful:[],queued:[],failed:[]},e)},S=function(e){return Object.entries(e).reduce(function(e,t){var n=_sliced_to_array(t,2),r=n[0],o=n[1];return e[r]=_object_spread_props(_object_spread({},o),{config:a(o.config)?o.config:{}}),e},{})},O=function(e,t){var n,r=e.config.wrapper||{},a=null!==(n=e.config.dryRun)&&void 0!==n?n:null==t?void 0:t.config.dryRun;return function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"unknown",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.dryRun,r=void 0!==n&&n,o=t.mockReturn,a=t.onCall;return function(t,n){return"function"!=typeof n?n:function(){for(var i=arguments.length,c=new Array(i),s=0;s<i;s++)c[s]=arguments[s];return a&&a({name:t,type:e},c),r?o:n.apply(void 0,_to_consumable_array(c))}}}(e.type||"unknown",_object_spread({},r,o(a)&&{dryRun:a}))},x=function(e,t){return _async_to_generator(function(){var r,o,a;return _ts_generator(this,function(i){return r=e.consent,o=!1,a={},[2,(Object.entries(t).forEach(function(e){var t=_sliced_to_array(e,2),n=t[0],r=!!t[1];a[n]=r,o=o||r}),e.consent=n(r,a),v(e,"consent",void 0,a),o?h(e):j({ok:!0}))]})})()},E=function(e,t,n){return _async_to_generator(function(){var r,o,a,i,c,u;return _ts_generator(this,function(l){switch(l.label){case 0:return(a={disabled:null!==(r=n.disabled)&&void 0!==r&&r,settings:null!==(o=n.settings)&&void 0!==o?o:{},onError:n.onError}).disabled?[2,{}]:[4,d(t)(e,a)];case 1:return(i=l.sent())&&i.source?(c=a.type||i.source.type||"",u=n.id||"".concat(c,"_").concat(s(5)),i.source&&i.elb&&(i.source.elb=i.elb),[2,(e.sources[u]={type:c,settings:a.settings,mapping:void 0,elb:i.elb},i)]):[2,{}]}})})()},C=function(e){return _async_to_generator(function(e){var t,n,r,o,a,i,c,s,u,l,d,f,_,p,v=arguments;return _ts_generator(this,function(g){switch(g.label){case 0:t=v.length>1&&void 0!==v[1]?v[1]:{},n=!0,r=!1,o=void 0,g.label=1;case 1:g.trys.push([1,6,7,8]),a=Object.entries(t)[Symbol.iterator](),g.label=2;case 2:return(n=(i=a.next()).done)?[3,5]:(c=_sliced_to_array(i.value,2),s=c[0],u=c[1],l=u.code,d=u.config,f=_object_spread({id:s},void 0===d?{}:d),[4,E(e,l,f)]);case 3:(_=g.sent()).source&&(_.elb&&(_.source.elb=_.elb),e.sources[s]={type:_.source.type,settings:_.source.config.settings,mapping:void 0,elb:_.elb}),g.label=4;case 4:return n=!0,[3,2];case 5:return[3,8];case 6:return p=g.sent(),r=!0,o=p,[3,8];case 7:try{n||null==a.return||a.return()}finally{if(r)throw o}return[7];case 8:return[2]}})}).apply(this,arguments)},A=function(){return _async_to_generator(function(){var e,t,r,o,a,i,c,s=arguments;return _ts_generator(this,function(u){switch(u.label){case 0:return t=function(e){var t=ze().version,r=n({dryRun:!1,globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:o,run:!0,destinations:{},consent:{},user:{},globals:{},custom:{}},e,{merge:!1,extend:!1});function o(e,t){!function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1]&&console.dir(e,{depth:4})}({message:e},t||r.verbose)}r.onLog=o;var a=_object_spread({},r.globalsStatic,r.globals),i={allowed:!1,config:r,consent:r.consent||{},count:0,custom:r.custom||{},destinations:S(r.destinations||{}),globals:a,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:r.user||{},version:t,sources:{},push:void 0};return i.push=function(e,t,n){return p(function(r,o,a){return _async_to_generator(function(){return _ts_generator(this,function(i){switch(i.label){case 0:return[4,d(function(){return _async_to_generator(function(){var i,c,s,u,l,d;return _ts_generator(this,function(f){switch(f.label){case 0:return"string"==typeof r&&r.startsWith("walker ")?(i=r.replace("walker ",""),[4,t(e,i,o,a)]):[3,2];case 1:return[2,f.sent()];case 2:return c=n("string"==typeof r?{event:r}:r),s=y(e,c.event,c),u=s.event,(l=s.command)?[4,t(e,l,o,a)]:[3,4];case 3:return d=f.sent(),[3,6];case 4:return[4,h(e,u)];case 5:d=f.sent(),f.label=6;case 6:return[2,d]}})})()},function(){return j({ok:!1})})()];case 1:return[2,i.sent()]}})})()},"Push",e.hooks)}(i,g,function(e){return _object_spread({timing:Math.round((Date.now()-i.timing)/10)/100,source:{type:"collector",id:"",previous_id:""}},e)}),i}(e=s.length>0&&void 0!==s[0]?s[0]:{}),r=e.consent,o=e.user,a=e.globals,i=e.custom,c=e.sources,r?[4,t.push("walker consent",r)]:[3,2];case 1:u.sent(),u.label=2;case 2:return o?[4,t.push("walker user",o)]:[3,4];case 3:u.sent(),u.label=4;case 4:return a&&Object.assign(t.globals,a),i&&Object.assign(t.custom,i),c?[4,C(t,c)]:[3,6];case 5:u.sent(),u.label=6;case 6:return t.config.run?[4,t.push("walker run")]:[3,8];case 7:u.sent(),u.label=8;case 8:return[2,{collector:t,elb:t.push}]}})}).apply(this,arguments)},L=function(e,t){return(e.getAttribute(t)||"").trim()},P=function(e){var t,n=getComputedStyle(e);if("none"===n.display)return!1;if("visible"!==n.visibility)return!1;if(n.opacity&&Number(n.opacity)<.1)return!1;var r=window.innerHeight,o=e.getBoundingClientRect(),a=o.height,i=o.y,c=i+a,s={x:o.x+e.offsetWidth/2,y:o.y+e.offsetHeight/2};if(a<=r){if(e.offsetWidth+o.width===0||e.offsetHeight+o.height===0)return!1;if(s.x<0)return!1;if(s.x>(document.documentElement.clientWidth||window.innerWidth))return!1;if(s.y<0)return!1;if(s.y>(document.documentElement.clientHeight||window.innerHeight))return!1;t=document.elementFromPoint(s.x,s.y)}else{var u=r/2;if(i<0&&c<u)return!1;if(c>r&&i>u)return!1;t=document.elementFromPoint(s.x,r/2)}if(t)do{if(t===e)return!0}while(t=t.parentElement);return!1},q=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.cb,n=e.consent,a=e.collector,i=e.storage,s=(null==a?void 0:a.push)||Qe;if(!n)return D((i?R:W)(e),a,t);var u,l,d,f=(u=e,l=t,function(e,t){if(!o(d)||d!==(null==e?void 0:e.group)){d=null==e?void 0:e.group;var n=function(){return W(u)};if(u.consent){var a=(r(u.consent)?u.consent:[u.consent]).reduce(function(e,t){return _object_spread_props(_object_spread({},e),_define_property({},t,!0))},{});c(a,t)&&(n=function(){return R(u)})}return D(n(),e,l)}});s("walker on","consent",(r(n)?n:[n]).reduce(function(e,t){return _object_spread_props(_object_spread({},e),_define_property({},t,f))},{}))},D=function(e,t,n){return!1===n?e:(n||(n=Ze),n(e,t,Ze))},I=function(e){var t,n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ne.Utils.Storage.Session;function o(e){try{return JSON.parse(e||"")}catch(r){var t=1,n="";return e&&(t=0,n=e),{e:t,v:n}}}switch(r){case Ne.Utils.Storage.Cookie:var a;t=decodeURIComponent((null===(a=document.cookie.split("; ").find(function(t){return t.startsWith(e+"=")}))||void 0===a?void 0:a.split("=")[1])||"");break;case Ne.Utils.Storage.Local:n=o(window.localStorage.getItem(e));break;case Ne.Utils.Storage.Session:n=o(window.sessionStorage.getItem(e))}return n&&(t=n.v,0!=n.e&&n.e<Date.now()&&(function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ne.Utils.Storage.Session;switch(t){case Ne.Utils.Storage.Cookie:U(e,"",0,t);break;case Ne.Utils.Storage.Local:window.localStorage.removeItem(e);break;case Ne.Utils.Storage.Session:window.sessionStorage.removeItem(e)}}(e,r),t="")),function(e){if("true"===e)return!0;if("false"===e)return!1;var t=Number(e);return e==t&&""!==e?t:String(e)}(t||"")},U=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:30,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Ne.Utils.Storage.Session,o=arguments.length>4?arguments[4]:void 0,a={e:Date.now()+6e4*n,v:String(t)},i=JSON.stringify(a);switch(r){case Ne.Utils.Storage.Cookie:t="object"==(void 0===t?"undefined":_type_of(t))?JSON.stringify(t):t;var c="".concat(e,"=").concat(encodeURIComponent(t),"; max-age=").concat(60*n,"; path=/; SameSite=Lax; secure");o&&(c+="; domain="+o),document.cookie=c;break;case Ne.Utils.Storage.Local:window.localStorage.setItem(e,i);break;case Ne.Utils.Storage.Session:window.sessionStorage.setItem(e,i)}return I(e,r)},R=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=Date.now(),n=e.length,r=void 0===n?30:n,o=e.deviceKey,a=void 0===o?"elbDeviceId":o,i=e.deviceStorage,c=void 0===i?"local":i,u=e.deviceAge,d=void 0===u?30:u,f=e.sessionKey,_=void 0===f?"elbSessionId":f,p=e.sessionStorage,v=void 0===p?"local":p,g=e.pulse,y=void 0!==g&&g,m=W(e),b=!1,h=l(function(e,t,n){var r=I(e,n);return r||(r=s(8),U(e,r,1440*t,n)),String(r)})(a,d,c),w=l(function(e,n){var o=JSON.parse(String(I(e,n)));return y||(o.isNew=!1,m.marketing&&(Object.assign(o,m),b=!0),b||o.updated+6e4*r<t?(delete o.id,delete o.referrer,o.start=t,o.count++,o.runs=1,b=!0):o.runs++),o},function(){b=!0})(_,v)||{},k={id:s(12),start:t,isNew:!0,count:1,runs:1},j=Object.assign(k,m,w,{device:h},{isStart:b,storage:!0,updated:t},e.data);return U(_,JSON.stringify(j),2*r,v),j},W=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.isStart||!1,r={isStart:t,storage:!1};if(!1===e.isStart)return r;if(!t&&"navigate"!==_sliced_to_array(performance.getEntriesByType("navigation"),1)[0].type)return r;var o=new URL(e.url||window.location.href),a=e.referrer||document.referrer,i=a&&new URL(a).hostname,c=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r="clickId",o={},a={utm_campaign:"campaign",utm_content:"content",utm_medium:"medium",utm_source:"source",utm_term:"term",dclid:r,fbclid:r,gclid:r,msclkid:r,ttclid:r,twclid:r,igshid:r,sclid:r};return Object.entries(n(a,t)).forEach(function(t){var n=_sliced_to_array(t,2),a=n[0],i=n[1],c=e.searchParams.get(a);c&&(i===r&&(i=a,o[r]=a),o[i]=c)}),o}(o,e.parameters);if(Object.keys(c).length&&(c.marketing||(c.marketing=!0),t=!0),!t){var u=e.domains||[];u.push(o.hostname),t=!u.includes(i)}return t?Object.assign({isStart:t,storage:!1,start:Date.now(),id:s(12),referrer:i},c,e.data):r},N=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};n=_object_spread({},nt,n);var r=Object.entries(t).reduce(function(t,r){var o=_sliced_to_array(r,2),a=o[0],i=o[1],c=e[a];return n.merge&&Array.isArray(c)&&Array.isArray(i)?t[a]=i.reduce(function(e,t){return e.includes(t)?e:_to_consumable_array(e).concat([t])},_to_consumable_array(c)):(n.extend||a in e)&&(t[a]=i),t},{});return n.shallow?_object_spread({},e,r):(Object.assign(e,r),e)},X=function(e){return Array.isArray(e)},M=function(e){return"object"==(void 0===e?"undefined":_type_of(e))&&null!==e&&!X(e)&&"[object Object]"===Object.prototype.toString.call(e)},T=function(e){return"string"==typeof e},H=function(e){if("true"===e)return!0;if("false"===e)return!1;var t=Number(e);return e==t&&""!==e?t:String(e)},G=function(e,t,n){return function(){for(var r=arguments.length,o=new Array(r),a=0;a<r;a++)o[a]=arguments[a];try{return e.apply(void 0,_to_consumable_array(o))}catch(e){if(!t)return;return t(e)}finally{null==n||n()}}},K=function(e){return e?e.trim().replace(/^'|'$/g,"").trim():""},V=function(e,t){return e+(null!=t?(!(arguments.length>2&&void 0!==arguments[2])||arguments[2]?"-":"")+t:"")},B=function(e,t,n){return ee(L(t,V(e,n,!(arguments.length>3&&void 0!==arguments[3])||arguments[3]))||"").reduce(function(e,n){var r=_sliced_to_array(te(n),2),o=r[0],a=r[1];if(!o)return e;if(a||(o.endsWith(":")&&(o=o.slice(0,-1)),a=""),a.startsWith("#")){a=a.slice(1);try{var i=t[a];i||"selected"!==a||(i=t.options[t.selectedIndex].text),a=String(i)}catch(i){a=""}}return o.endsWith("[]")?(o=o.slice(0,-2),X(e[o])||(e[o]=[]),e[o].push(H(a))):e[o]=H(a),e},{})},F=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document.body,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Ye.Commands.Prefix,n=[],r=Ye.Commands.Action,o="[".concat(V(t,r,!1),"]"),a=function(e){Object.keys(B(t,e,r,!1)).forEach(function(r){n=n.concat(J(e,r,t))})};return e!==document&&e.matches(o)&&a(e),Z(e,o,a),n},J=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Ye.Commands.Prefix,r=[],o=function(e,t,n){for(var r=t;r;){var o=$(L(r,V(e,Ye.Commands.Action,!1)));if(o[n]||"click"!==n)return o[n];r=Y(e,r)}return[]}(n,e,t);return o?(o.forEach(function(o){var a=ee(o.actionParams||"",",").reduce(function(e,t){return e[K(t)]=!0,e},{}),i=function(e,t,n){var r=[],o=t;for(n=0!==Object.keys(n||{}).length?n:void 0;o;){var a=rt(e,o,t,n);a&&r.push(a),o=Y(e,o)}return r}(n,e,a);if(!i.length){var c="page",s="[".concat(V(n,c),"]"),u=_sliced_to_array(Q(e,s,n,c),2),l=u[0],d=u[1];i.push({type:c,data:l,nested:[],context:d})}i.forEach(function(e){r.push({entity:e.type,action:o.action,data:e.data,trigger:t,context:e.context,nested:e.nested})})}),r):r},z=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Ye.Commands.Prefix,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document,n=V(e,Ye.Commands.Globals,!1),r={};return Z(t,"[".concat(n,"]"),function(t){r=N(r,B(e,t,Ye.Commands.Globals,!1))}),r},$=function(e){var t={};return ee(e).forEach(function(e){var n=_sliced_to_array(te(e),2),r=n[0],o=n[1],a=_sliced_to_array(ne(r),2),i=a[0],c=a[1];if(i){var s=_sliced_to_array(ne(o||""),2),u=s[0],l=s[1];u=u||i,t[i]||(t[i]=[]),t[i].push({trigger:i,triggerParams:c,action:u,actionParams:l})}}),t},Y=function(e,t){var n=V(e,Ye.Commands.Link,!1);if(t.matches("[".concat(n,"]"))){var r=_sliced_to_array(te(L(t,n)),2),o=r[0];if("child"===r[1])return document.querySelector("[".concat(n,'="').concat(o,':parent"]'))}return!t.parentElement&&t.getRootNode&&_instanceof(t.getRootNode(),ShadowRoot)?t.getRootNode().host:t.parentElement},Q=function(e,t,n,r){for(var o={},a={},i=e,c="[".concat(V(n,Ye.Commands.Context,!1),"]"),s=0;i;)i.matches(t)&&(o=N(B(n,i,""),o),o=N(B(n,i,r),o)),i.matches(c)&&(Object.entries(B(n,i,Ye.Commands.Context,!1)).forEach(function(e){var t=_sliced_to_array(e,2),n=t[0],r=t[1];r&&!a[n]&&(a[n]=[r,s])}),++s),i=Y(n,i);return[o,a]},Z=function(e,t,n){e.querySelectorAll(t).forEach(n)},ee=function(e){if(!e)return[];var t=new RegExp("(?:[^".concat(arguments.length>1&&void 0!==arguments[1]?arguments[1]:";","']+|'[^']*')+"),"ig");return e.match(t)||[]},te=function(e){var t=_sliced_to_array(e.split(/:(.+)/,2),2),n=t[0],r=t[1];return[K(n),K(r)]},ne=function(e){var t=_sliced_to_array(e.split("(",2),2),n=t[0],r=t[1];return[n,r?r.slice(0,-1):""]},re=function(e){var t=Date.now(),n=it.get(e);return(!n||t-n.lastChecked>500)&&(n={isVisible:P(e),lastChecked:t},it.set(e,n)),n.isVisible},oe=function(e){if(window.IntersectionObserver)return G(function(){return new window.IntersectionObserver(function(t){t.forEach(function(t){!function(e,t){var n,r,o=t.target,a=e._visibilityState;if(a){var i=a.timers.get(o);if(t.intersectionRatio>0){var c=Date.now(),s=at.get(o);if((!s||c-s.lastChecked>1e3)&&(s={isLarge:o.offsetHeight>window.innerHeight,lastChecked:c},at.set(o,s)),t.intersectionRatio>=.5||s.isLarge&&re(o)){var u=null==(n=a.elementConfigs)?void 0:n.get(o);if((null==u?void 0:u.multiple)&&u.blocked)return;if(!i){var l=window.setTimeout(function(){return _async_to_generator(function(){var t,n;return _ts_generator(this,function(r){switch(r.label){case 0:return re(o)?[4,fe(e,o,st.Visible,"data-elb")]:[3,2];case 1:r.sent(),(null==(n=null==(t=a.elementConfigs)?void 0:t.get(o))?void 0:n.multiple)?n.blocked=!0:function(e,t){var n=e._visibilityState;if(n){n.observer&&n.observer.unobserve(t);var r=n.timers.get(t);r&&(clearTimeout(r),n.timers.delete(t)),at.delete(t),it.delete(t)}}(e,o),r.label=2;case 2:return[2]}})})()},a.duration);a.timers.set(o,l)}return}}i&&(clearTimeout(i),a.timers.delete(o));var d=null==(r=a.elementConfigs)?void 0:r.get(o);(null==d?void 0:d.multiple)&&(d.blocked=!1)}}(e,t)})},{rootMargin:"0px",threshold:[0,.5]})},function(){})()},ae=function(e,t){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{multiple:!1},o=e._visibilityState;(null==o?void 0:o.observer)&&t&&(o.elementConfigs||(o.elementConfigs=new WeakMap),o.elementConfigs.set(t,{multiple:null!=(n=r.multiple)&&n,blocked:!1}),o.observer.observe(t))},ie=function(e){var t=e._visibilityState;t&&(t.observer&&t.observer.disconnect(),delete e._visibilityState)},ce=function(e,t,n,r,o,a,i){if(T(t)&&t.startsWith("walker ")){if("walker config"===t)return e.push("walker config",n);if("walker consent"===t)return e.push("walker consent",n);if("walker user"===t)return e.push("walker user",n);if("walker run"===t)return e.push("walker run",n)}if(M(t)){var c=t;return c.source||(c.source=le()),e.push(c)}if(T(t)&&t.length>0){var s={event:t,data:se(n||{}),context:ue(o||{}),custom:i,nested:a,source:le()};return T(r)&&(s.trigger=r),e.push(s)}if(!function(e){return void 0!==e}(t))return Promise.resolve({ok:!0,successful:[],queued:[],failed:[]});var u={event:String(t||""),data:se(n||{}),context:ue(o||{}),custom:i,nested:a,source:le()};return T(r)&&(u.trigger=r),e.push(u)},se=function(e){return e&&(void 0===e?"undefined":_type_of(e))==_type_of({})?e:{}},ue=function(e){return e?(t=e)===document||_instanceof(t,Element)?{}:M(e)&&Object.keys(e).length?e:{}:{};var t},le=function(){return{type:"browser",id:window.location.href,previous_id:document.referrer}},de=function(e,t){var n,r,o,a,i,c,s,u,l=t.prefix,d=t.scope;if(t.pageview){var f=_sliced_to_array((n=l,r=d,o=window.location,a="page",i=r===document?document.body:r,c=_sliced_to_array(Q(i,"[".concat(V(n,a),"]"),n,a),2),s=c[0],u=c[1],s.domain=o.hostname,s.title=document.title,s.referrer=document.referrer,o.search&&(s.search=o.search),o.hash&&(s.hash=o.hash),[s,u]),2),_=f[0],p=f[1];ce(e,"page view",_,st.Load,p)}!function(e,t,n){ct=[],ie(e),function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e3;e._visibilityState||(e._visibilityState={observer:oe(e),timers:new WeakMap,duration:t})}(e,1e3);var r=V(t,Ye.Commands.Action,!1),o=n||document;o!==document&&_e(e,o,r,t),o.querySelectorAll("[".concat(r,"]")).forEach(function(n){return _e(e,n,r,t)}),ct.length&&function(e,t){var n=function(e,t){return e.filter(function(e){var n=_sliced_to_array(e,2),r=n[0],o=n[1],a=window.scrollY+window.innerHeight,i=r.offsetTop;if(a<i)return!0;var c=r.clientHeight;return!(100*(1-(i+c-a)/(c||1))>=o&&(fe(t,r,st.Scroll,"data-elb"),1))})};ot||(ot=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e3,n=null;return function(){for(var r=arguments.length,o=new Array(r),a=0;a<r;a++)o[a]=arguments[a];if(null===n)return n=setTimeout(function(){n=null},t),e.apply(void 0,_to_consumable_array(o))}}(function(){ct=n.call(t,ct,e)}),t.addEventListener("scroll",ot))}(e,o)}(e,l,d)},fe=function(e,t,n,r){return _async_to_generator(function(){var o;return _ts_generator(this,function(a){return o=J(t,n,r),[2,Promise.all(o.map(function(t){return ce(e,_object_spread_props(_object_spread({event:"".concat(t.entity," ").concat(t.action)},t),{trigger:n}))}))]})})()},_e=function(e,t,n,r){var o=L(t,n);o&&Object.values($(o)).forEach(function(n){return n.forEach(function(n){switch(n.trigger){case st.Hover:o=e,a=r,t.addEventListener("mouseenter",G(function(e){_instanceof(e.target,Element)&&fe(o,e.target,st.Hover,a)}));break;case st.Load:!function(e,t,n){fe(e,t,st.Load,n)}(e,t,r);break;case st.Pulse:!function(e,t){var n=arguments.length>3?arguments[3]:void 0;setInterval(function(){document.hidden||fe(e,t,st.Pulse,n)},parseInt((arguments.length>2&&void 0!==arguments[2]?arguments[2]:"")||"")||15e3)}(e,t,n.triggerParams,r);break;case st.Scroll:!function(e){var t=parseInt((arguments.length>1&&void 0!==arguments[1]?arguments[1]:"")||"")||50;t<0||t>100||ct.push([e,t])}(t,n.triggerParams);break;case st.Visible:ae(e,t);break;case st.Visibles:ae(e,t,{multiple:!0});break;case st.Wait:!function(e,t){var n=arguments.length>3?arguments[3]:void 0;setTimeout(function(){return fe(e,t,st.Wait,n)},parseInt((arguments.length>2&&void 0!==arguments[2]?arguments[2]:"")||"")||15e3)}(e,t,n.triggerParams,r)}var o,a})})},pe=function(e,t){fe(e,t.target,st.Click,"data-elb")},ve=function(e,t){t.target&&fe(e,t.target,st.Submit,"data-elb")},ge=function(e,t){null!=t&&""!==t&&"number"!=typeof t&&"string"!=typeof t&&G(function(){if(ye(t)){var n=Array.from(t);if(n.length>=1){var r=_sliced_to_array(n,4),o=r[0],a=r[1],i=r[2],c=r[3];"string"==typeof o&&o.length>0&&ce(e,o,a,i,c)}}else if("object"==(void 0===t?"undefined":_type_of(t))&&null!==t){if(0===Object.keys(t).length)return;ce(e,t)}},function(){})()},ye=function(e){return null!=e&&"object"==(void 0===e?"undefined":_type_of(e))&&"length"in e&&"number"==typeof e.length},me=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;if(!t.filter||!0!==l(function(){return t.filter(n)},function(){return!1})()){var o,c,s=a(o=n)&&i(o.event)?o:r(o)&&o.length>=2?be(o):null!=(c=o)&&"object"==(void 0===c?"undefined":_type_of(c))&&"length"in c&&"number"==typeof c.length&&c.length>0?be(Array.from(o)):null;if(s){var u={event:"".concat(t.prefix||"dataLayer"," ").concat(s.event),data:s,context:{},globals:{},custom:{},consent:{},nested:[],user:{},id:Math.random().toString(36).substring(2,15),trigger:"",entity:"",action:"",timestamp:Date.now(),timing:0,group:"",count:0,version:{source:"1.0.0",tagging:2},source:{type:"dataLayer",id:"",previous_id:""}};l(function(){return e.push(u)},function(){})()}}},be=function(e){var t=_sliced_to_array(e,3),n=t[0],r=t[1],o=t[2];if(!i(n))return null;var c,s={};switch(n){case"consent":if(!i(r)||e.length<3)return null;if(!a(o)||null===o)return null;c="".concat(n," ").concat(r),s=_object_spread({},o);break;case"event":if(!i(r))return null;c=r,a(o)&&(s=_object_spread({},o));break;case"config":if(!i(r))return null;c="".concat(n," ").concat(r),a(o)&&(s=_object_spread({},o));break;case"set":if(i(r))c="".concat(n," ").concat(r),a(o)&&(s=_object_spread({},o));else{if(!a(r))return null;c="".concat(n," custom"),s=_object_spread({},r)}break;default:return null}return _object_spread({event:c},s)},he=function(){return["consent","update",{ad_user_data:"granted",ad_personalization:"granted",ad_storage:"denied",analytics_storage:"granted"}]},we=function(){return["consent","default",{ad_storage:"denied",analytics_storage:"denied",ad_user_data:"denied",ad_personalization:"denied"}]},ke=function(){return["event","purchase",{transaction_id:"T_12345",value:25.42,currency:"EUR",items:[{item_id:"SKU_12345",item_name:"Product Name",item_category:"Category",quantity:1,price:25.42}]}]},je=function(){return["event","add_to_cart",{currency:"EUR",value:15.25,items:[{item_id:"SKU_12345",item_name:"Product Name",item_variant:"red",quantity:1,price:15.25}]}]},Se=function(){return["event","view_item",{currency:"EUR",value:15.25,items:[{item_id:"SKU_12345",item_name:"Product Name",item_category:"Category",price:15.25}]}]},Oe=function(){return["config","G-XXXXXXXXXX",{page_title:"Custom Page Title",page_location:"https://example.com/page",send_page_view:!1}]},xe=function(){return["set",{currency:"EUR",country:"DE"}]},Ee=function(){return{event:"custom_event",custom_parameter:"custom_value",user_id:"user123"}},Ce=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=function(t,n){var r=_object_spread_props(_object_spread({},n),{settings:_object_spread({name:"dataLayer",prefix:"dataLayer"},e,n.settings)});return kt(t,r)};return t.init=function(e,t){return kt(e,{type:"dataLayer",settings:t.settings})},t.settings=_object_spread({name:"dataLayer",prefix:"dataLayer"},e),t.type="dataLayer",t},Ae=function(){window.dataLayer=window.dataLayer||[];var e=function(e){a(e)&&a(e.source)&&String(e.source.type).includes("dataLayer")||window.dataLayer.push(e)};return{type:"dataLayer",config:{},push:function(t,n){e(n.data||t)},pushBatch:function(t){e({event:"batch",batched_event:t.key,events:t.data.length?t.data:t.events})}}},Le=function(){return _async_to_generator(function(){var e,t,r,o,i,c,s,u,l=arguments;return _ts_generator(this,function(d){switch(d.label){case 0:return e=l.length>0&&void 0!==l[0]?l[0]:{},t={collector:{destinations:{dataLayer:Ae()}},browser:{run:!0,session:!0},dataLayer:!1,elb:"elb"},r=n(t,e),o=_object_spread_props(_object_spread({},r.collector),{sources:{browser:{code:ut,config:{settings:r.browser}}}}),r.dataLayer&&(i=a(r.dataLayer)?r.dataLayer:{},o.sources&&(o.sources.dataLayer={code:Ce(i),config:{settings:i}})),[4,A(o)];case 1:if(c=d.sent().collector,!(null==(s=c.sources.browser)?void 0:s.elb))throw new Error("Failed to initialize browser source");return u={collector:c,elb:s.elb},r.elb&&(window[r.elb]=s.elb),r.name&&(window[r.name]=c),[2,u]}})}).apply(this,arguments)},Pe=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,De=Object.getOwnPropertyNames,Ie=Object.prototype.hasOwnProperty,Ue={};!function(e,t){for(var n in t)Pe(e,n,{get:t[n],enumerable:!0})}(Ue,{Walkerjs:function(){return jt},createWalkerjs:function(){return Le},default:function(){return St},getAllEvents:function(){return F},getEvents:function(){return J},getGlobals:function(){return z}});var Re=Object.getOwnPropertyNames,We=(e={"package.json":function(e,t){t.exports={name:"@walkeros/core",description:"Core types and platform-agnostic utilities for walkerOS",version:"0.0.7",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/core"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","web analytics","product analytics","core","types","utils"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return t||(0,e[Re(e)[0]])((t={exports:{}}).exports,t),t.exports}),Ne={Utils:{Storage:{Local:"local",Session:"session",Cookie:"cookie"}}},Xe={merge:!0,shallow:!0,extend:!0};function Me(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new WeakMap;if("object"!=(void 0===e?"undefined":_type_of(e))||null===e)return e;if(t.has(e))return t.get(e);var n=Object.prototype.toString.call(e);if("[object Object]"===n){var r={};for(var o in t.set(e,r),e)Object.prototype.hasOwnProperty.call(e,o)&&(r[o]=Me(e[o],t));return r}if("[object Array]"===n){var a=[];return t.set(e,a),e.forEach(function(e){a.push(Me(e,t))}),a}if("[object Date]"===n)return new Date(e.getTime());if("[object RegExp]"===n){var i=e;return new RegExp(i.source,i.flags)}return e}function Te(e){for(var t=arguments.length>2?arguments[2]:void 0,n=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"").split("."),a=e,i=0;i<n.length;i++){var c=n[i];if("*"===c&&r(a)){var s=n.slice(i+1).join("."),u=[],l=!0,d=!1,f=void 0;try{for(var _,p=a[Symbol.iterator]();!(l=(_=p.next()).done);l=!0){var v=Te(_.value,s,t);u.push(v)}}catch(e){d=!0,f=e}finally{try{l||null==p.return||p.return()}finally{if(d)throw f}}return u}if(!(a=_instanceof(a,Object)?a[c]:void 0))break}return o(a)?a:t}var He,Ge;We().version;function Ke(e){return function(e){return"boolean"==typeof e}(e)||i(e)||function(e){return"number"==typeof e&&!Number.isNaN(e)}(e)||!o(e)||r(e)&&e.every(Ke)||a(e)&&Object.values(e).every(Ke)}function Ve(e,t){return _async_to_generator(function(e,t){var n,a,s,l=arguments;return _ts_generator(this,function(f){return a=(n=l.length>2&&void 0!==l[2]?l[2]:{}).collector,s=n.consent,[2,(r(t)?t:[t]).reduce(function(t,l){return _async_to_generator(function(){var f,p,v,g,y,m,b,h,w,k,j,S,O,x,E,C,A,L,P,q,D;return _ts_generator(this,function(I){switch(I.label){case 0:return[4,t];case 1:return(f=I.sent())?[2,f]:(p=i(l)?{key:l}:l,Object.keys(p).length?(v=p.condition,g=p.consent,y=p.fn,m=p.key,b=p.loop,h=p.map,w=p.set,k=p.validate,j=p.value,(S=v)?[4,d(v)(e,l,a)]:[3,3]):[2]);case 2:S=!I.sent(),I.label=3;case 3:return S?[2]:g&&!c(g,s)?[2,j]:(O=o(j)?j:e,y?[4,d(y)(e,l,n)]:[3,5]);case 4:O=I.sent(),I.label=5;case 5:return m&&(O=Te(e,m,j)),b?(x=_sliced_to_array(b,2),E=x[0],C=x[1],"this"!==E?[3,6]:(L=[e],[3,8])):[3,11];case 6:return[4,_(e,E,n)];case 7:L=I.sent(),I.label=8;case 8:return r(A=L)?[4,Promise.all(A.map(function(e){return _(e,C,n)}))]:[3,10];case 9:O=I.sent().filter(o),I.label=10;case 10:return[3,17];case 11:return h?[4,Object.entries(h).reduce(function(t,r){var a=_sliced_to_array(r,2),i=a[0],c=a[1];return _async_to_generator(function(){var r,a;return _ts_generator(this,function(s){switch(s.label){case 0:return[4,t];case 1:return r=s.sent(),[4,_(e,c,n)];case 2:return a=s.sent(),[2,(o(a)&&(r[i]=a),r)]}})})()},Promise.resolve({}))]:[3,13];case 12:return O=I.sent(),[3,16];case 13:return(P=w)?[4,Promise.all(w.map(function(t){return Ve(e,t,n)}))]:[3,15];case 14:P=O=I.sent(),I.label=15;case 15:I.label=16;case 16:I.label=17;case 17:return(q=k)?[4,d(k)(O)]:[3,19];case 18:q=!I.sent(),I.label=19;case 19:return q&&(O=void 0),D=u(O),[2,o(D)?D:u(j)]}})})()},Promise.resolve(void 0))]})}).apply(this,arguments)}var Be,Fe,Je=Object.getOwnPropertyNames,ze=(He={"package.json":function(e,t){t.exports={name:"@walkeros/collector",description:"Unified platform-agnostic collector for walkerOS",version:"0.0.7",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{"@walkeros/core":"0.0.7"},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/collector"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","collector","event processing"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return Ge||(0,He[Je(He)[0]])((Ge={exports:{}}).exports,Ge),Ge.exports}),$e={Action:"action",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},Ye={Commands:$e,Utils:{Storage:{Cookie:"cookie",Local:"local",Session:"session"}}},Qe=function(){var e=window;(e.elbLayer=e.elbLayer||[]).push(arguments)},Ze=function(e,t){var n=(null==t?void 0:t.push)||Qe,r={};return e.id&&(r.session=e.id),e.storage&&e.device&&(r.device=e.device),n("walker user",r),e.isStart&&n({event:"session start",data:e}),e},et=Object.getOwnPropertyNames,tt=(Be={"package.json":function(e,t){t.exports={name:"@walkeros/core",description:"Core types and platform-agnostic utilities for walkerOS",version:"0.0.7",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/core"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","web analytics","product analytics","core","types","utils"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return Fe||(0,Be[et(Be)[0]])((Fe={exports:{}}).exports,Fe),Fe.exports}),nt={merge:!0,shallow:!0,extend:!0};tt().version;function rt(e,t,n,r){var o=L(t,V(e));if(!o||r&&!r[o])return null;var a=[t],i="[".concat(V(e,o),"],[").concat(V(e,""),"]"),c=V(e,Ye.Commands.Link,!1),s={},u=[],l=_sliced_to_array(Q(n||t,i,e,o),2),d=l[0],f=l[1];Z(t,"[".concat(c,"]"),function(t){var n=_sliced_to_array(te(L(t,c)),2),r=n[0];"parent"===n[1]&&Z(document.body,"[".concat(c,'="').concat(r,':child"]'),function(t){a.push(t);var n=rt(e,t);n&&u.push(n)})});var _=[];a.forEach(function(e){e.matches(i)&&_.push(e),Z(e,i,function(e){return _.push(e)})});var p={};return _.forEach(function(t){p=N(p,B(e,t,"")),s=N(s,B(e,t,o))}),s=N(N(p,s),d),a.forEach(function(t){Z(t,"[".concat(V(e),"]"),function(t){var n=rt(e,t);n&&u.push(n)})}),{type:o,data:s,context:f,nested:u}}var ot,at=new WeakMap,it=new WeakMap,ct=[],st={Click:"click",Custom:"custom",Hover:"hover",Load:"load",Pulse:"pulse",Scroll:"scroll",Submit:"submit",Visible:"visible",Visibles:"visibles",Wait:"wait"},ut=function(e,t){return _async_to_generator(function(){var n,r,o,a,i,c;return _ts_generator(this,function(s){switch(s.label){case 0:return n=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.scope||document;return _object_spread_props(_object_spread({prefix:"data-elb",pageview:!0,session:!0,elb:"elb",name:"walkerjs",elbLayer:"elbLayer"},e),{scope:t})}(t.settings),r=_object_spread_props(_object_spread({},t),{settings:n}),o=n.scope,a={type:"browser",config:r,collector:e,destroy:function(){ie(e)}},!1!==n.elbLayer&&function(e){var t=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).name||"elbLayer";window[t]||(window[t]=[]);var n,r,o,a,i=window[t];Array.isArray(i)&&i.length>0&&(n=e,o=[],a=[],(r=i).forEach(function(e){!function(e){if(ye(e)){var t=Array.from(e);return"string"==typeof t[0]&&t[0].startsWith("walker ")}return!1}(e)?a.push(e):o.push(e)}),o.forEach(function(e){ge(n,e)}),a.forEach(function(e){ge(n,e)}),r.length=0)}(e,{name:T(n.elbLayer)?n.elbLayer:"elbLayer"}),function(e,t){t.addEventListener("click",G(function(t){pe.call(this,e,t)})),t.addEventListener("submit",G(function(t){ve.call(this,e,t)}))}(e,o),n.session&&(i="boolean"==typeof n.session?{}:n.session,function(e){var t,n,r,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=o.config||{},i=N(e.config.sessionStatic||{},o.data||{});(t=q,n="SessionStart",r=e.hooks,function(){for(var e=arguments.length,o=new Array(e),a=0;a<e;a++)o[a]=arguments[a];var i,c="post"+n,s=r["pre"+n],u=r[c];return i=s?s.apply(void 0,[{fn:t}].concat(_to_consumable_array(o))):t.apply(void 0,_to_consumable_array(o)),u&&(i=u.apply(void 0,[{fn:t,result:i}].concat(_to_consumable_array(o)))),i})(_object_spread_props(_object_spread({},a),{cb:function(e,t,n){var r,o=a;return!1!==o.cb&&o.cb?r=o.cb(e,t,n):!1!==o.cb&&(r=n(e,t,n)),t&&(t.session=e,v(t,"session")),r},data:i,collector:e}))}(e,{config:i})),[4,function(e,t,n){return _async_to_generator(function(){var r;return _ts_generator(this,function(o){return r=function(){e(t,n),v(t,"ready")},"loading"!==document.readyState?r():document.addEventListener("DOMContentLoaded",r),[2]})})()}(de,e,n)];case 1:return s.sent(),c=e._destroy,e._destroy=function(){var e;null==(e=a.destroy)||e.call(a),c&&c()},[2,{source:a,elb:function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];var o=_sliced_to_array(n,6),a=o[0],i=o[1],c=o[2],s=o[3],u=o[4],l=o[5];return ce(e,a,i,c,s,u,l)}}]}})})()},lt=Object.defineProperty,dt=function(e,t){for(var n in t)lt(e,n,{get:t[n],enumerable:!0})},ft=!1;dt({},{add_to_cart:function(){return je},config:function(){return Oe},consentDefault:function(){return we},consentUpdate:function(){return he},directDataLayerEvent:function(){return Ee},purchase:function(){return ke},setCustom:function(){return xe},view_item:function(){return Se}});dt({},{add_to_cart:function(){return gt},config:function(){return ht},configGA4:function(){return mt},consentOnlyMapping:function(){return wt},consentUpdate:function(){return pt},customEvent:function(){return bt},purchase:function(){return vt},view_item:function(){return yt}});var _t,pt={name:"walker consent",settings:{command:{map:{functional:{value:!0},analytics:{key:"analytics_storage",fn:function(e){return"granted"===e}},marketing:{key:"ad_storage",fn:function(e){return"granted"===e}}}}}},vt={name:"order complete",data:{map:{id:"transaction_id",total:"value",currency:"currency",nested:{loop:["items",{map:{type:{value:"product"},data:{map:{id:"item_id",name:"item_name",category:"item_category",quantity:"quantity",price:"price"}}}}]}}}},gt={name:"product add",data:{map:{id:"items.0.item_id",name:"items.0.item_name",price:"value",currency:"currency",color:"items.0.item_variant",quantity:"items.0.quantity"}}},yt={name:"product view",data:{map:{id:"items.0.item_id",name:"items.0.item_name",category:"items.0.item_category",price:"items.0.price",currency:"currency"}}},mt={name:"page view",data:{map:{title:"page_title",url:"page_location"}}},bt={data:{map:{user_id:"user_id",custom_parameter:"custom_parameter"}}},ht={consent:{update:pt},purchase:vt,add_to_cart:gt,view_item:yt,"config G-XXXXXXXXXX":mt,custom_event:bt,"*":{data:{}}},wt={consent:{update:pt}},kt=function(e,t){var n=t.settings,r={type:"dataLayer",config:t,collector:e,destroy:function(){var e=n.name||"dataLayer";window[e]&&Array.isArray(window[e])}};return function(e,t){var n=t.settings,r=(null==n?void 0:n.name)||"dataLayer",o=window[r];if(Array.isArray(o)&&!ft){ft=!0;try{var a=!0,i=!1,c=void 0;try{for(var s,u=o[Symbol.iterator]();!(a=(s=u.next()).done);a=!0){var l=s.value;me(e,n,l)}}catch(e){i=!0,c=e}finally{try{a||null==u.return||u.return()}finally{if(i)throw c}}}finally{ft=!1}}}(e,t),function(e,t){var n=t.settings,r=(null==n?void 0:n.name)||"dataLayer";window[r]||(window[r]=[]);var o=window[r];if(Array.isArray(o)){var a=o.push.bind(o);o.push=function(){for(var t=arguments.length,r=new Array(t),o=0;o<t;o++)r[o]=arguments[o];if(ft)return a.apply(void 0,_to_consumable_array(r));ft=!0;try{var i=!0,c=!1,s=void 0;try{for(var u,l=r[Symbol.iterator]();!(i=(u=l.next()).done);i=!0){var d=u.value;me(e,n,d)}}catch(e){c=!0,s=e}finally{try{i||null==l.return||l.return()}finally{if(c)throw s}}}finally{ft=!1}return a.apply(void 0,_to_consumable_array(r))}}}(e,t),{source:r,elb:function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var o,a=n.name||"dataLayer",i=window[a];return Array.isArray(i)?Promise.resolve((o=i).push.apply(o,_to_consumable_array(t))):Promise.resolve(0)}}},jt={},St=Le;return _t=Ue,function(e,t,n,r){if(t&&"object"===(void 0===t?"undefined":_type_of(t))||"function"==typeof t){var o=!0,a=!1,i=void 0;try{for(var c,s=function(){var o=c.value;Ie.call(e,o)||o===n||Pe(e,o,{get:function(){return t[o]},enumerable:!(r=qe(t,o))||r.enumerable})},u=De(t)[Symbol.iterator]();!(o=(c=u.next()).done);o=!0)s()}catch(e){a=!0,i=e}finally{try{o||null==u.return||u.return()}finally{if(a)throw i}}}return e}(Pe({},"__esModule",{value:!0}),_t)}();
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e,r=Object.defineProperty,t=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,s={};((e,t)=>{for(var a in t)r(e,a,{get:t[a],enumerable:!0})})(s,{Walkerjs:()=>d,createWalkerjs:()=>w,default:()=>y,getAllEvents:()=>l.getAllEvents,getEvents:()=>l.getEvents,getGlobals:()=>l.getGlobals}),module.exports=(e=s,((e,s,c,n)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let l of a(s))o.call(e,l)||l===c||r(e,l,{get:()=>s[l],enumerable:!(n=t(s,l))||n.enumerable});return e})(r({},"__esModule",{value:!0}),e));var c=require("@walkeros/collector"),n=require("@walkeros/core"),l=require("@walkeros/web-source-browser"),i=require("@walkeros/web-source-dataLayer"),u=require("@walkeros/core");function b(){window.dataLayer=window.dataLayer||[];const e=e=>{(0,u.isObject)(e)&&(0,u.isObject)(e.source)&&String(e.source.type).includes("dataLayer")||window.dataLayer.push(e)};return{type:"dataLayer",config:{},push:(r,t)=>{e(t.data||r)},pushBatch:r=>{e({event:"batch",batched_event:r.key,events:r.data.length?r.data:r.events})}}}var d={};async function w(e={}){const r={collector:{destinations:{dataLayer:b()}},browser:{run:!0,session:!0},dataLayer:!1,elb:"elb"},t=(0,n.assign)(r,e),a={...t.collector,sources:{browser:{code:l.sourceBrowser,config:{settings:t.browser}}}};if(t.dataLayer){const e=(0,n.isObject)(t.dataLayer)?t.dataLayer:{};a.sources&&(a.sources.dataLayer={code:(0,i.sourceDataLayer)(e),config:{settings:e}})}const{collector:o}=await(0,c.createCollector)(a),s=o.sources.browser;if(!(null==s?void 0:s.elb))throw new Error("Failed to initialize browser source");const u={collector:o,elb:s.elb};return t.elb&&(window[t.elb]=s.elb),t.name&&(window[t.name]=o),u}var y=w;//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/destination.ts","../src/types/index.ts"],"sourcesContent":["import type { Config, Instance } from './types';\nimport { createCollector, type CollectorConfig } from '@walkeros/collector';\nimport { assign, isObject } from '@walkeros/core';\nimport {\n sourceBrowser,\n getAllEvents,\n getEvents,\n getGlobals,\n type SourceBrowser,\n} from '@walkeros/web-source-browser';\nimport { sourceDataLayer } from '@walkeros/web-source-dataLayer';\nimport { dataLayerDestination } from './destination';\n\n// Re-export types\nexport * as Walkerjs from './types';\n\nexport { getAllEvents, getEvents, getGlobals };\n\n// Factory function to create walker.js instance\nexport async function createWalkerjs(config: Config = {}): Promise<Instance> {\n // Default configuration\n const defaultConfig: Config = {\n collector: {\n destinations: {\n dataLayer: dataLayerDestination(),\n },\n },\n browser: {\n run: true,\n session: true,\n },\n dataLayer: false,\n elb: 'elb',\n };\n\n const fullConfig = assign(defaultConfig, config);\n\n // Build collector config with sources\n const collectorConfig: Partial<CollectorConfig> = {\n ...fullConfig.collector,\n sources: {\n browser: {\n code: sourceBrowser,\n config: {\n settings: fullConfig.browser,\n },\n },\n },\n };\n\n // Add dataLayer source if configured\n if (fullConfig.dataLayer) {\n const dataLayerSettings = isObject(fullConfig.dataLayer)\n ? fullConfig.dataLayer\n : {};\n\n if (collectorConfig.sources) {\n collectorConfig.sources.dataLayer = {\n code: sourceDataLayer(dataLayerSettings),\n config: {\n settings: dataLayerSettings,\n },\n };\n }\n }\n\n const { collector } = await createCollector(collectorConfig);\n\n // Get browser elb function\n const browserSource = collector.sources.browser;\n if (!browserSource?.elb) {\n throw new Error('Failed to initialize browser source');\n }\n\n const instance: Instance = {\n collector,\n elb: browserSource.elb as SourceBrowser.BrowserPush,\n };\n\n // Set up global variables if configured\n if (fullConfig.elb) window[fullConfig.elb] = browserSource.elb;\n if (fullConfig.name) window[fullConfig.name] = collector;\n\n return instance;\n}\n\n// Export factory function as default\nexport default createWalkerjs;\n","import type { Destination } from '@walkeros/core';\nimport type { DataLayer } from './types';\nimport { isObject } from '@walkeros/core';\n\nexport function dataLayerDestination(): Destination.InitDestination {\n window.dataLayer = window.dataLayer || [];\n const dataLayerPush = (event: unknown) => {\n // Do not process events from dataLayer source\n if (\n isObject(event) &&\n isObject(event.source) &&\n String(event.source.type).includes('dataLayer')\n )\n return;\n\n (window.dataLayer as DataLayer)!.push(event);\n };\n const destination: Destination.Instance = {\n type: 'dataLayer',\n config: {},\n push: (event, context) => {\n dataLayerPush(context.data || event);\n },\n pushBatch: (batch) => {\n dataLayerPush({\n event: 'batch',\n batched_event: batch.key,\n events: batch.data.length ? batch.data : batch.events,\n });\n },\n };\n\n return destination;\n}\n","import type { Collector, Source, WalkerOS } from '@walkeros/core';\nimport type { SourceBrowser } from '@walkeros/web-source-browser';\nimport type { SourceDataLayer } from '@walkeros/web-source-dataLayer';\n\ndeclare global {\n interface Window {\n [key: string]: DataLayer;\n }\n}\n\n// Instance interface\nexport interface Instance {\n collector: Collector.Instance;\n elb: SourceBrowser.BrowserPush;\n}\n\n// Configuration interface\nexport interface Config {\n // Collector configuration\n collector?: Collector.InitConfig;\n\n // Browser source configuration\n browser?: Partial<SourceBrowser.Settings>;\n\n // DataLayer configuration\n dataLayer?: boolean | Partial<SourceDataLayer.Settings>;\n\n // Global configuration\n elb?: string; // Name for the global elb function\n name?: string; // Name for the global instance\n run?: boolean; // Auto-run on initialization (default: true)\n}\n\nexport type DataLayer = undefined | Array<unknown>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAsD;AACtD,IAAAA,eAAiC;AACjC,gCAMO;AACP,kCAAgC;;;ACRhC,kBAAyB;AAElB,SAAS,uBAAoD;AAClE,SAAO,YAAY,OAAO,aAAa,CAAC;AACxC,QAAM,gBAAgB,CAAC,UAAmB;AAExC,YACE,sBAAS,KAAK,SACd,sBAAS,MAAM,MAAM,KACrB,OAAO,MAAM,OAAO,IAAI,EAAE,SAAS,WAAW;AAE9C;AAEF,IAAC,OAAO,UAAyB,KAAK,KAAK;AAAA,EAC7C;AACA,QAAM,cAAoC;AAAA,IACxC,MAAM;AAAA,IACN,QAAQ,CAAC;AAAA,IACT,MAAM,CAAC,OAAO,YAAY;AACxB,oBAAc,QAAQ,QAAQ,KAAK;AAAA,IACrC;AAAA,IACA,WAAW,CAAC,UAAU;AACpB,oBAAc;AAAA,QACZ,OAAO;AAAA,QACP,eAAe,MAAM;AAAA,QACrB,QAAQ,MAAM,KAAK,SAAS,MAAM,OAAO,MAAM;AAAA,MACjD,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;;;ACjCA;;;AFmBA,eAAsB,eAAe,SAAiB,CAAC,GAAsB;AAE3E,QAAM,gBAAwB;AAAA,IAC5B,WAAW;AAAA,MACT,cAAc;AAAA,QACZ,WAAW,qBAAqB;AAAA,MAClC;AAAA,IACF;AAAA,IACA,SAAS;AAAA,MACP,KAAK;AAAA,MACL,SAAS;AAAA,IACX;AAAA,IACA,WAAW;AAAA,IACX,KAAK;AAAA,EACP;AAEA,QAAM,iBAAa,qBAAO,eAAe,MAAM;AAG/C,QAAM,kBAA4C;AAAA,IAChD,GAAG,WAAW;AAAA,IACd,SAAS;AAAA,MACP,SAAS;AAAA,QACP,MAAM;AAAA,QACN,QAAQ;AAAA,UACN,UAAU,WAAW;AAAA,QACvB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAGA,MAAI,WAAW,WAAW;AACxB,UAAM,wBAAoB,uBAAS,WAAW,SAAS,IACnD,WAAW,YACX,CAAC;AAEL,QAAI,gBAAgB,SAAS;AAC3B,sBAAgB,QAAQ,YAAY;AAAA,QAClC,UAAM,6CAAgB,iBAAiB;AAAA,QACvC,QAAQ;AAAA,UACN,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,EAAE,UAAU,IAAI,UAAM,kCAAgB,eAAe;AAG3D,QAAM,gBAAgB,UAAU,QAAQ;AACxC,MAAI,EAAC,+CAAe,MAAK;AACvB,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AAEA,QAAM,WAAqB;AAAA,IACzB;AAAA,IACA,KAAK,cAAc;AAAA,EACrB;AAGA,MAAI,WAAW,IAAK,QAAO,WAAW,GAAG,IAAI,cAAc;AAC3D,MAAI,WAAW,KAAM,QAAO,WAAW,IAAI,IAAI;AAE/C,SAAO;AACT;AAGA,IAAO,gBAAQ;","names":["import_core"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e,t,n=Object.getOwnPropertyNames,r=(e={"package.json"(e,t){t.exports={name:"@walkeros/core",description:"Core types and platform-agnostic utilities for walkerOS",version:"0.0.7",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/core"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","web analytics","product analytics","core","types","utils"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return t||(0,e[n(e)[0]])((t={exports:{}}).exports,t),t.exports}),o={Storage:{Local:"local",Session:"session",Cookie:"cookie"}},i={merge:!0,shallow:!0,extend:!0};function s(e,t={},n={}){n={...i,...n};const r=Object.entries(t).reduce((t,[r,o])=>{const i=e[r];return n.merge&&Array.isArray(i)&&Array.isArray(o)?t[r]=o.reduce((e,t)=>e.includes(t)?e:[...e,t],[...i]):(n.extend||r in e)&&(t[r]=o),t},{});return n.shallow?{...e,...r}:(Object.assign(e,r),e)}function a(e){return Array.isArray(e)}function c(e){return void 0!==e}function u(e){return"object"==typeof e&&null!==e&&!a(e)&&"[object Object]"===Object.prototype.toString.call(e)}function l(e){return"string"==typeof e}function d(e,t=new WeakMap){if("object"!=typeof e||null===e)return e;if(t.has(e))return t.get(e);const n=Object.prototype.toString.call(e);if("[object Object]"===n){const n={};t.set(e,n);for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=d(e[r],t));return n}if("[object Array]"===n){const n=[];return t.set(e,n),e.forEach(e=>{n.push(d(e,t))}),n}if("[object Date]"===n)return new Date(e.getTime());if("[object RegExp]"===n){const t=e;return new RegExp(t.source,t.flags)}return e}function f(e,t="",n){const r=t.split(".");let o=e;for(let e=0;e<r.length;e++){const t=r[e];if("*"===t&&a(o)){const t=r.slice(e+1).join("."),i=[];for(const e of o){const r=f(e,t,n);i.push(r)}return i}if(o=o instanceof Object?o[t]:void 0,!o)break}return c(o)?o:n}function g(e,t={},n={}){const r={...t,...n},o={};let i=void 0===e;return Object.keys(r).forEach(t=>{r[t]&&(o[t]=!0,e&&e[t]&&(i=!0))}),!!i&&o}var p,m,{version:y}=r();function b(e=6){let t="";for(let n=36;t.length<e;)t+=(Math.random()*n|0).toString(n);return t}function h(e){return function(e){return"boolean"==typeof e}(e)||l(e)||function(e){return"number"==typeof e&&!Number.isNaN(e)}(e)||!c(e)||a(e)&&e.every(h)||u(e)&&Object.values(e).every(h)}function w(e){return h(e)?e:void 0}function v(e,t,n){return function(...r){try{return e(...r)}catch(e){if(!t)return;return t(e)}finally{null==n||n()}}}function k(e,t,n){return async function(...r){try{return await e(...r)}catch(e){if(!t)return;return await t(e)}finally{await(null==n?void 0:n())}}}async function S(e,t={},n={}){var r;if(!c(e))return;const o=u(e)&&e.consent||n.consent||(null==(r=n.collector)?void 0:r.consent),i=a(t)?t:[t];for(const t of i){const r=await k(_)(e,t,{...n,consent:o});if(c(r))return r}}async function _(e,t,n={}){const{collector:r,consent:o}=n;return(a(t)?t:[t]).reduce(async(t,i)=>{const s=await t;if(s)return s;const u=l(i)?{key:i}:i;if(!Object.keys(u).length)return;const{condition:d,consent:p,fn:m,key:y,loop:b,map:h,set:v,validate:j,value:O}=u;if(d&&!await k(d)(e,i,r))return;if(p&&!g(p,o))return O;let x=c(O)?O:e;if(m&&(x=await k(m)(e,i,n)),y&&(x=f(e,y,O)),b){const[t,r]=b,o="this"===t?[e]:await S(e,t,n);a(o)&&(x=(await Promise.all(o.map(e=>S(e,r,n)))).filter(c))}else h?x=await Object.entries(h).reduce(async(t,[r,o])=>{const i=await t,s=await S(e,o,n);return c(s)&&(i[r]=s),i},Promise.resolve({})):v&&(x=await Promise.all(v.map(t=>_(e,t,n))));j&&!await k(j)(x)&&(x=void 0);const E=w(x);return c(E)?E:w(O)},Promise.resolve(void 0))}function j(e,t,n){return function(...r){let o;const i="post"+t,s=n["pre"+t],a=n[i];return o=s?s({fn:e},...r):e(...r),a&&(o=a({fn:e,result:o},...r)),o}}var O=Object.getOwnPropertyNames,x=(p={"package.json"(e,t){t.exports={name:"@walkeros/collector",description:"Unified platform-agnostic collector for walkerOS",version:"0.0.7",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{"@walkeros/core":"0.0.7"},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/collector"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","collector","event processing"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return m||(0,p[O(p)[0]])((m={exports:{}}).exports,m),m.exports}),E={Action:"action",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},L=E;function P(e,t,n,r){let o=n||[];if(n||(o=e.on[t]||[],Object.values(e.destinations).forEach(e=>{var n;const r=null==(n=e.config.on)?void 0:n[t];r&&(o=o.concat(r))})),o.length)switch(t){case L.Consent:!function(e,t,n){const r=n||e.consent;t.forEach(t=>{Object.keys(r).filter(e=>e in t).forEach(n=>{v(t[n])(e,r)})})}(e,o,r);break;case L.Ready:case L.Run:s=o,(i=e).allowed&&s.forEach(e=>{v(e)(i)});break;case L.Session:!function(e,t){e.session&&t.forEach(t=>{v(t)(e,e.session)})}(e,o)}var i,s}async function $(e,t,n,r){let o;switch(t){case L.Config:u(n)&&s(e.config,n,{shallow:!1});break;case L.Consent:u(n)&&(o=await async function(e,t){const{consent:n}=e;let r=!1;const o={};return Object.entries(t).forEach(([e,t])=>{const n=!!t;o[e]=n,r=r||n}),e.consent=s(n,o),P(e,"consent",void 0,o),r?C(e):D({ok:!0})}(e,n));break;case L.Custom:u(n)&&(e.custom=s(e.custom,n));break;case L.Destination:u(n)&&function(e){return"function"==typeof e}(n.push)&&(o=await async function(e,t,n){const r=n||t.config||{init:!1},o={...t,config:r};let i=r.id;if(!i)do{i=b(4)}while(e.destinations[i]);return e.destinations[i]=o,!1!==r.queue&&(o.queue=[...e.queue]),C(e,void 0,{[i]:o})}(e,n,r));break;case L.Globals:u(n)&&(e.globals=s(e.globals,n));break;case L.On:l(n)&&function(e,t,n){const r=e.on,o=r[t]||[],i=a(n)?n:[n];i.forEach(e=>{o.push(e)}),r[t]=o,P(e,t,i)}(e,n,r);break;case L.Run:o=await async function(e,t){return e.allowed=!0,e.count=0,e.group=b(),e.timing=Date.now(),t&&(t.consent&&(e.consent=s(e.consent,t.consent)),t.user&&(e.user=s(e.user,t.user)),t.globals&&(e.globals=s(e.config.globalsStatic||{},t.globals)),t.custom&&(e.custom=s(e.custom,t.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.round++,P(e,"run"),await C(e)}(e,n);break;case L.User:u(n)&&s(e.user,n,{shallow:!1})}return o||{ok:!0,successful:[],queued:[],failed:[]}}function A(e,t,n){return j(async(r,o,i)=>await k(async()=>{if("string"==typeof r&&r.startsWith("walker ")){const n=r.replace("walker ","");return await t(e,n,o,i)}{const s=n("string"==typeof r?{event:r}:r),{event:a,command:c}=function(e,t,n={}){const r=function(e){return typeof e==typeof""}(t)?{event:t,...n}:{...n,...t||{}};if(!r.event)throw new Error("Event name is required");const[o,i]=r.event.split(" ");if(!o||!i)throw new Error("Event name is invalid");if(o===E.Walker)return{command:i};++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:c=e.count}=r,{event:u=`${o} ${i}`,data:l={},context:d={},globals:f=e.globals,custom:g={},user:p=e.user,nested:m=[],consent:y=e.consent,id:b=`${s}-${a}-${c}`,trigger:h="",entity:w=o,action:v=i,timing:k=0,version:S={source:e.version,tagging:e.config.tagging||0},source:_={type:"collector",id:"",previous_id:""}}=r;return{event:{event:u,data:l,context:d,globals:f,custom:g,user:p,nested:m,consent:y,id:b,trigger:h,entity:w,action:v,timestamp:s,timing:k,group:a,count:c,version:S,source:_}}}(e,s.event,s);return c?await t(e,c,o,i):await C(e,a)}},()=>D({ok:!1}))(),"Push",e.hooks)}async function C(e,t,n){const{allowed:r,consent:o,globals:i,user:a}=e;if(!r)return D({ok:!1});t&&e.queue.push(t),n||(n=e.destinations);const c=await Promise.all(Object.entries(n||{}).map(async([n,r])=>{let c=(r.queue||[]).map(e=>({...e,consent:o}));if(r.queue=[],t){let n=d(t);await Promise.all(Object.entries(r.config.policy||[]).map(async([r,o])=>{const i=await S(t,o,{collector:e});n=function(e,t,n){const r=d(e),o=t.split(".");let i=r;for(let e=0;e<o.length;e++){const t=o[e];e===o.length-1?i[t]=n:(t in i&&"object"==typeof i[t]&&null!==i[t]||(i[t]={}),i=i[t])}return r}(n,r,i)})),c.push(n)}if(!c.length)return{id:n,destination:r,skipped:!0};const u=[],l=c.filter(e=>{const t=g(r.config.consent,o,e.consent);return!t||(e.consent=t,u.push(e),!1)});if(r.queue.concat(l),!u.length)return{id:n,destination:r,queue:c};if(!await k(q)(e,r))return{id:n,destination:r,queue:c};let f=!1;return r.dlq||(r.dlq=[]),await Promise.all(u.map(async t=>(t.globals=s(i,t.globals),t.user=s(a,t.user),await k(R,n=>(e.config.onError&&e.config.onError(n,e),f=!0,r.dlq.push([t,n]),!1))(e,r,t),t))),{id:n,destination:r,error:f}})),u=[],l=[],f=[];for(const e of c){if(e.skipped)continue;const t=e.destination,n={id:e.id,destination:t};e.error?f.push(n):e.queue&&e.queue.length?(t.queue=(t.queue||[]).concat(e.queue),l.push(n)):u.push(n)}return D({ok:!f.length,event:t,successful:u,queued:l,failed:f})}async function q(e,t){if(t.init&&!t.config.init){const n={collector:e,config:t.config,wrap:N(t,e)},r=await j(t.init,"DestinationInit",e.hooks)(n);if(!1===r)return r;t.config={...r||t.config,init:!0}}return!0}async function R(e,t,n){var r;const{config:o}=t,{eventMapping:i,mappingKey:l}=await async function(e,t){var n;const[r,o]=(e.event||"").split(" ");if(!t||!r||!o)return{};let i,s="",c=r,u=o;const l=t=>{if(t)return(t=a(t)?t:[t]).find(t=>!t.condition||t.condition(e))};t[c]||(c="*");const d=t[c];return d&&(d[u]||(u="*"),i=l(d[u])),i||(c="*",u="*",i=l(null==(n=t[c])?void 0:n[u])),i&&(s=`${c} ${u}`),{eventMapping:i,mappingKey:s}}(n,o.mapping);let d=o.data&&await S(n,o.data,{collector:e});if(i){if(i.ignore)return!1;if(i.name&&(n.event=i.name),i.data){const t=i.data&&await S(n,i.data,{collector:e});d=u(d)&&u(t)?s(d,t):t}}const f={collector:e,config:o,data:d,mapping:i,wrap:N(t,e)};if((null==i?void 0:i.batch)&&t.pushBatch){const s=i.batched||{key:l||"",events:[],data:[]};s.events.push(n),c(d)&&s.data.push(d),i.batchFn=i.batchFn||function(e,t=1e3,n=!1){let r,o=null,i=!1;return(...s)=>new Promise(a=>{const c=n&&!i;o&&clearTimeout(o),o=setTimeout(()=>{o=null,n&&!i||(r=e(...s),a(r))},t),c&&(i=!0,r=e(...s),a(r))})}((e,t)=>{const n={collector:t,config:o,data:d,mapping:i,wrap:N(e,t)};j(e.pushBatch,"DestinationPushBatch",t.hooks)(s,n),s.events=[],s.data=[]},i.batch),i.batched=s,null==(r=i.batchFn)||r.call(i,t,e)}else await j(t.push,"DestinationPush",e.hooks)(n,f);return!0}function D(e){var t;return s({ok:!(null==(t=null==e?void 0:e.failed)?void 0:t.length),successful:[],queued:[],failed:[]},e)}function I(e){return Object.entries(e).reduce((e,[t,n])=>(e[t]={...n,config:u(n.config)?n.config:{}},e),{})}function N(e,t){var n;const r=e.config.wrapper||{},o=null!=(n=e.config.dryRun)?n:null==t?void 0:t.config.dryRun;return function(e="unknown",{dryRun:t=!1,mockReturn:n,onCall:r}={}){return function(o,i){return"function"!=typeof i?i:(...s)=>(r&&r({name:o,type:e},s),t?n:i(...s))}}(e.type||"unknown",{...r,...c(o)&&{dryRun:o}})}async function W(e,t,n){var r,o;const i={disabled:null!=(r=n.disabled)&&r,settings:null!=(o=n.settings)?o:{},onError:n.onError};if(i.disabled)return{};const s=await k(t)(e,i);if(!s||!s.source)return{};const a=i.type||s.source.type||"",c=n.id||`${a}_${b(5)}`;return s.source&&s.elb&&(s.source.elb=s.elb),e.sources[c]={type:a,settings:i.settings,mapping:void 0,elb:s.elb},s}async function X(e={}){const t=function(e){const{version:t}=x(),n=s({dryRun:!1,globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:r,run:!0,destinations:{},consent:{},user:{},globals:{},custom:{}},e,{merge:!1,extend:!1});function r(e,t){!function(e,t=!1){t&&console.dir(e,{depth:4})}({message:e},t||n.verbose)}n.onLog=r;const o={...n.globalsStatic,...n.globals},i={allowed:!1,config:n,consent:n.consent||{},count:0,custom:n.custom||{},destinations:I(n.destinations||{}),globals:o,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:n.user||{},version:t,sources:{},push:void 0};return i.push=A(i,$,e=>({timing:Math.round((Date.now()-i.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),i}(e),{consent:n,user:r,globals:o,custom:i,sources:a}=e;return n&&await t.push("walker consent",n),r&&await t.push("walker user",r),o&&Object.assign(t.globals,o),i&&Object.assign(t.custom,i),a&&await async function(e,t={}){for(const[n,r]of Object.entries(t)){const{code:t,config:o={}}=r,i={id:n,...o},s=await W(e,t,i);s.source&&(s.elb&&(s.source.elb=s.elb),e.sources[n]={type:s.source.type,settings:s.source.config.settings,mapping:void 0,elb:s.elb})}}(t,a),t.config.run&&await t.push("walker run"),{collector:t,elb:t.push}}function H(e,t){return(e.getAttribute(t)||"").trim()}var M=function(){const e=window;(e.elbLayer=e.elbLayer||[]).push(arguments)};function U(e){const t=getComputedStyle(e);if("none"===t.display)return!1;if("visible"!==t.visibility)return!1;if(t.opacity&&Number(t.opacity)<.1)return!1;let n;const r=window.innerHeight,o=e.getBoundingClientRect(),i=o.height,s=o.y,a=s+i,c={x:o.x+e.offsetWidth/2,y:o.y+e.offsetHeight/2};if(i<=r){if(e.offsetWidth+o.width===0||e.offsetHeight+o.height===0)return!1;if(c.x<0)return!1;if(c.x>(document.documentElement.clientWidth||window.innerWidth))return!1;if(c.y<0)return!1;if(c.y>(document.documentElement.clientHeight||window.innerHeight))return!1;n=document.elementFromPoint(c.x,c.y)}else{const e=r/2;if(s<0&&a<e)return!1;if(a>r&&s>e)return!1;n=document.elementFromPoint(c.x,r/2)}if(n)do{if(n===e)return!0}while(n=n.parentElement);return!1}function T(e={}){const{cb:t,consent:n,collector:r,storage:o}=e,i=(null==r?void 0:r.push)||M;if(!n)return G((o?z:Y)(e),r,t);{const r=function(e,t){let n;return(r,o)=>{if(c(n)&&n===(null==r?void 0:r.group))return;n=null==r?void 0:r.group;let i=()=>Y(e);if(e.consent){g((a(e.consent)?e.consent:[e.consent]).reduce((e,t)=>({...e,[t]:!0}),{}),o)&&(i=()=>z(e))}return G(i(),r,t)}}(e,t);i("walker on","consent",(a(n)?n:[n]).reduce((e,t)=>({...e,[t]:r}),{}))}}function G(e,t,n){return!1===n?e:(n||(n=B),n(e,t,B))}var K,V,B=(e,t)=>{const n=(null==t?void 0:t.push)||M,r={};return e.id&&(r.session=e.id),e.storage&&e.device&&(r.device=e.device),n("walker user",r),e.isStart&&n({event:"session start",data:e}),e};function F(e,t=o.Storage.Session){var n;function r(e){try{return JSON.parse(e||"")}catch(t){let n=1,r="";return e&&(n=0,r=e),{e:n,v:r}}}let i,s;switch(t){case o.Storage.Cookie:i=decodeURIComponent((null==(n=document.cookie.split("; ").find(t=>t.startsWith(e+"=")))?void 0:n.split("=")[1])||"");break;case o.Storage.Local:s=r(window.localStorage.getItem(e));break;case o.Storage.Session:s=r(window.sessionStorage.getItem(e))}return s&&(i=s.v,0!=s.e&&s.e<Date.now()&&(function(e,t=o.Storage.Session){switch(t){case o.Storage.Cookie:J(e,"",0,t);break;case o.Storage.Local:window.localStorage.removeItem(e);break;case o.Storage.Session:window.sessionStorage.removeItem(e)}}(e,t),i="")),function(e){if("true"===e)return!0;if("false"===e)return!1;const t=Number(e);return e==t&&""!==e?t:String(e)}(i||"")}function J(e,t,n=30,r=o.Storage.Session,i){const s={e:Date.now()+6e4*n,v:String(t)},a=JSON.stringify(s);switch(r){case o.Storage.Cookie:{t="object"==typeof t?JSON.stringify(t):t;let r=`${e}=${encodeURIComponent(t)}; max-age=${60*n}; path=/; SameSite=Lax; secure`;i&&(r+="; domain="+i),document.cookie=r;break}case o.Storage.Local:window.localStorage.setItem(e,a);break;case o.Storage.Session:window.sessionStorage.setItem(e,a)}return F(e,r)}function z(e={}){const t=Date.now(),{length:n=30,deviceKey:r="elbDeviceId",deviceStorage:o="local",deviceAge:i=30,sessionKey:s="elbSessionId",sessionStorage:a="local",pulse:c=!1}=e,u=Y(e);let l=!1;const d=v((e,t,n)=>{let r=F(e,n);return r||(r=b(8),J(e,r,1440*t,n)),String(r)})(r,i,o),f=v((e,r)=>{const o=JSON.parse(String(F(e,r)));return c||(o.isNew=!1,u.marketing&&(Object.assign(o,u),l=!0),l||o.updated+6e4*n<t?(delete o.id,delete o.referrer,o.start=t,o.count++,o.runs=1,l=!0):o.runs++),o},()=>{l=!0})(s,a)||{},g={id:b(12),start:t,isNew:!0,count:1,runs:1},p=Object.assign(g,u,f,{device:d},{isStart:l,storage:!0,updated:t},e.data);return J(s,JSON.stringify(p),2*n,a),p}function Y(e={}){let t=e.isStart||!1;const n={isStart:t,storage:!1};if(!1===e.isStart)return n;if(!t){const[e]=performance.getEntriesByType("navigation");if("navigate"!==e.type)return n}const r=new URL(e.url||window.location.href),o=e.referrer||document.referrer,i=o&&new URL(o).hostname,a=function(e,t={}){const n="clickId",r={},o={utm_campaign:"campaign",utm_content:"content",utm_medium:"medium",utm_source:"source",utm_term:"term",dclid:n,fbclid:n,gclid:n,msclkid:n,ttclid:n,twclid:n,igshid:n,sclid:n};return Object.entries(s(o,t)).forEach(([t,o])=>{const i=e.searchParams.get(t);i&&(o===n&&(o=t,r[n]=t),r[o]=i)}),r}(r,e.parameters);if(Object.keys(a).length&&(a.marketing||(a.marketing=!0),t=!0),!t){const n=e.domains||[];n.push(r.hostname),t=!n.includes(i)}return t?Object.assign({isStart:t,storage:!1,start:Date.now(),id:b(12),referrer:i},a,e.data):n}var Q=Object.getOwnPropertyNames,Z=(K={"package.json"(e,t){t.exports={name:"@walkeros/core",description:"Core types and platform-agnostic utilities for walkerOS",version:"0.0.7",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/core"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","web analytics","product analytics","core","types","utils"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return V||(0,K[Q(K)[0]])((V={exports:{}}).exports,V),V.exports}),ee={merge:!0,shallow:!0,extend:!0};function te(e,t={},n={}){n={...ee,...n};const r=Object.entries(t).reduce((t,[r,o])=>{const i=e[r];return n.merge&&Array.isArray(i)&&Array.isArray(o)?t[r]=o.reduce((e,t)=>e.includes(t)?e:[...e,t],[...i]):(n.extend||r in e)&&(t[r]=o),t},{});return n.shallow?{...e,...r}:(Object.assign(e,r),e)}function ne(e){return Array.isArray(e)}function re(e){return"object"==typeof e&&null!==e&&!ne(e)&&"[object Object]"===Object.prototype.toString.call(e)}function oe(e){return"string"==typeof e}function ie(e){if("true"===e)return!0;if("false"===e)return!1;const t=Number(e);return e==t&&""!==e?t:String(e)}var{version:se}=Z();function ae(e,t,n){return function(...r){try{return e(...r)}catch(e){if(!t)return;return t(e)}finally{null==n||n()}}}function ce(e){return e?e.trim().replace(/^'|'$/g,"").trim():""}function ue(e,t,n=!0){return e+(null!=t?(n?"-":"")+t:"")}function le(e,t,n,r=!0){return we(H(t,ue(e,n,r))||"").reduce((e,n)=>{let[r,o]=ve(n);if(!r)return e;if(o||(r.endsWith(":")&&(r=r.slice(0,-1)),o=""),o.startsWith("#")){o=o.slice(1);try{let e=t[o];e||"selected"!==o||(e=t.options[t.selectedIndex].text),o=String(e)}catch(e){o=""}}return r.endsWith("[]")?(r=r.slice(0,-2),ne(e[r])||(e[r]=[]),e[r].push(ie(o))):e[r]=ie(o),e},{})}function de(e=document.body,t=L.Prefix){let n=[];const r=L.Action,o=`[${ue(t,r,!1)}]`,i=e=>{Object.keys(le(t,e,r,!1)).forEach(r=>{n=n.concat(fe(e,r,t))})};return e!==document&&e.matches(o)&&i(e),he(e,o,i),n}function fe(e,t,n=L.Prefix){const r=[],o=function(e,t,n){let r=t;for(;r;){const t=pe(H(r,ue(e,L.Action,!1)));if(t[n]||"click"!==n)return t[n];r=ye(e,r)}return[]}(n,e,t);return o?(o.forEach(o=>{const i=we(o.actionParams||"",",").reduce((e,t)=>(e[ce(t)]=!0,e),{}),s=function(e,t,n){const r=[];let o=t;for(n=0!==Object.keys(n||{}).length?n:void 0;o;){const i=me(e,o,t,n);i&&r.push(i),o=ye(e,o)}return r}(n,e,i);if(!s.length){const t="page",r=`[${ue(n,t)}]`,[o,i]=be(e,r,n,t);s.push({type:t,data:o,nested:[],context:i})}s.forEach(e=>{r.push({entity:e.type,action:o.action,data:e.data,trigger:t,context:e.context,nested:e.nested})})}),r):r}function ge(e=L.Prefix,t=document){const n=ue(e,L.Globals,!1);let r={};return he(t,`[${n}]`,t=>{r=te(r,le(e,t,L.Globals,!1))}),r}function pe(e){const t={};return we(e).forEach(e=>{const[n,r]=ve(e),[o,i]=ke(n);if(!o)return;let[s,a]=ke(r||"");s=s||o,t[o]||(t[o]=[]),t[o].push({trigger:o,triggerParams:i,action:s,actionParams:a})}),t}function me(e,t,n,r){const o=H(t,ue(e));if(!o||r&&!r[o])return null;const i=[t],s=`[${ue(e,o)}],[${ue(e,"")}]`,a=ue(e,L.Link,!1);let c={};const u=[],[l,d]=be(n||t,s,e,o);he(t,`[${a}]`,t=>{const[n,r]=ve(H(t,a));"parent"===r&&he(document.body,`[${a}="${n}:child"]`,t=>{i.push(t);const n=me(e,t);n&&u.push(n)})});const f=[];i.forEach(e=>{e.matches(s)&&f.push(e),he(e,s,e=>f.push(e))});let g={};return f.forEach(t=>{g=te(g,le(e,t,"")),c=te(c,le(e,t,o))}),c=te(te(g,c),l),i.forEach(t=>{he(t,`[${ue(e)}]`,t=>{const n=me(e,t);n&&u.push(n)})}),{type:o,data:c,context:d,nested:u}}function ye(e,t){const n=ue(e,L.Link,!1);if(t.matches(`[${n}]`)){const[e,r]=ve(H(t,n));if("child"===r)return document.querySelector(`[${n}="${e}:parent"]`)}return!t.parentElement&&t.getRootNode&&t.getRootNode()instanceof ShadowRoot?t.getRootNode().host:t.parentElement}function be(e,t,n,r){let o={};const i={};let s=e;const a=`[${ue(n,L.Context,!1)}]`;let c=0;for(;s;)s.matches(t)&&(o=te(le(n,s,""),o),o=te(le(n,s,r),o)),s.matches(a)&&(Object.entries(le(n,s,L.Context,!1)).forEach(([e,t])=>{t&&!i[e]&&(i[e]=[t,c])}),++c),s=ye(n,s);return[o,i]}function he(e,t,n){e.querySelectorAll(t).forEach(n)}function we(e,t=";"){if(!e)return[];const n=new RegExp(`(?:[^${t}']+|'[^']*')+`,"ig");return e.match(n)||[]}function ve(e){const[t,n]=e.split(/:(.+)/,2);return[ce(t),ce(n)]}function ke(e){const[t,n]=e.split("(",2);return[t,n?n.slice(0,-1):""]}var Se,_e=new WeakMap,je=new WeakMap;function Oe(e){const t=Date.now();let n=je.get(e);return(!n||t-n.lastChecked>500)&&(n={isVisible:U(e),lastChecked:t},je.set(e,n)),n.isVisible}function xe(e){if(window.IntersectionObserver)return ae(()=>new window.IntersectionObserver(t=>{t.forEach(t=>{!function(e,t){var n,r;const o=t.target,i=e._visibilityState;if(!i)return;const s=i.timers.get(o);if(t.intersectionRatio>0){const r=Date.now();let a=_e.get(o);if((!a||r-a.lastChecked>1e3)&&(a={isLarge:o.offsetHeight>window.innerHeight,lastChecked:r},_e.set(o,a)),t.intersectionRatio>=.5||a.isLarge&&Oe(o)){const t=null==(n=i.elementConfigs)?void 0:n.get(o);if((null==t?void 0:t.multiple)&&t.blocked)return;if(!s){const t=window.setTimeout(async()=>{var t;if(Oe(o)){await Ne(e,o,Re.Visible,"data-elb");const n=null==(t=i.elementConfigs)?void 0:t.get(o);(null==n?void 0:n.multiple)?n.blocked=!0:function(e,t){const n=e._visibilityState;if(!n)return;n.observer&&n.observer.unobserve(t);const r=n.timers.get(t);r&&(clearTimeout(r),n.timers.delete(t)),_e.delete(t),je.delete(t)}(e,o)}},i.duration);i.timers.set(o,t)}return}}s&&(clearTimeout(s),i.timers.delete(o));const a=null==(r=i.elementConfigs)?void 0:r.get(o);(null==a?void 0:a.multiple)&&(a.blocked=!1)}(e,t)})},{rootMargin:"0px",threshold:[0,.5]}),()=>{})()}function Ee(e,t,n={multiple:!1}){var r;const o=e._visibilityState;(null==o?void 0:o.observer)&&t&&(o.elementConfigs||(o.elementConfigs=new WeakMap),o.elementConfigs.set(t,{multiple:null!=(r=n.multiple)&&r,blocked:!1}),o.observer.observe(t))}function Le(e){const t=e._visibilityState;t&&(t.observer&&t.observer.disconnect(),delete e._visibilityState)}function Pe(e,t,n,r,o,i,s){if(oe(t)&&t.startsWith("walker ")){if("walker config"===t)return e.push("walker config",n);if("walker consent"===t)return e.push("walker consent",n);if("walker user"===t)return e.push("walker user",n);if("walker run"===t)return e.push("walker run",n)}if(re(t)){const n=t;return n.source||(n.source=Ce()),e.push(n)}if(oe(t)&&t.length>0){const a={event:t,data:$e(n||{}),context:Ae(o||{}),custom:s,nested:i,source:Ce()};return oe(r)&&(a.trigger=r),e.push(a)}if(!function(e){return void 0!==e}(t))return Promise.resolve({ok:!0,successful:[],queued:[],failed:[]});const a={event:String(t||""),data:$e(n||{}),context:Ae(o||{}),custom:s,nested:i,source:Ce()};return oe(r)&&(a.trigger=r),e.push(a)}function $e(e){return e&&"object"==typeof e?e:{}}function Ae(e){return e?(t=e)===document||t instanceof Element?{}:re(e)&&Object.keys(e).length?e:{}:{};var t}function Ce(){return{type:"browser",id:window.location.href,previous_id:document.referrer}}var qe=[],Re={Click:"click",Custom:"custom",Hover:"hover",Load:"load",Pulse:"pulse",Scroll:"scroll",Submit:"submit",Visible:"visible",Visibles:"visibles",Wait:"wait"};function De(e,t){const{prefix:n,scope:r,pageview:o}=t;if(o){const[t,o]=function(e,t){const n=window.location,r="page",o=t===document?document.body:t,[i,s]=be(o,`[${ue(e,r)}]`,e,r);return i.domain=n.hostname,i.title=document.title,i.referrer=document.referrer,n.search&&(i.search=n.search),n.hash&&(i.hash=n.hash),[i,s]}(n,r);Pe(e,"page view",t,Re.Load,o)}!function(e,t,n){qe=[],Le(e),function(e,t=1e3){e._visibilityState||(e._visibilityState={observer:xe(e),timers:new WeakMap,duration:t})}(e,1e3);const r=ue(t,L.Action,!1),o=n||document;o!==document&&We(e,o,r,t),o.querySelectorAll(`[${r}]`).forEach(n=>We(e,n,r,t)),qe.length&&function(e,t){const n=(e,t)=>e.filter(([e,n])=>{const r=window.scrollY+window.innerHeight,o=e.offsetTop;if(r<o)return!0;const i=e.clientHeight;return!(100*(1-(o+i-r)/(i||1))>=n&&(Ne(t,e,Re.Scroll,"data-elb"),1))});Se||(Se=function(e,t=1e3){let n=null;return function(...r){if(null===n)return n=setTimeout(()=>{n=null},t),e(...r)}}(function(){qe=n.call(t,qe,e)}),t.addEventListener("scroll",Se))}(e,o)}(e,n,r)}function Ie(e,t){t.addEventListener("click",ae(function(t){Xe.call(this,e,t)})),t.addEventListener("submit",ae(function(t){He.call(this,e,t)}))}async function Ne(e,t,n,r){const o=fe(t,n,r);return Promise.all(o.map(t=>Pe(e,{event:`${t.entity} ${t.action}`,...t,trigger:n})))}function We(e,t,n,r){const o=H(t,n);o&&Object.values(pe(o)).forEach(n=>n.forEach(n=>{switch(n.trigger){case Re.Hover:o=e,i=r,t.addEventListener("mouseenter",ae(function(e){e.target instanceof Element&&Ne(o,e.target,Re.Hover,i)}));break;case Re.Load:!function(e,t,n){Ne(e,t,Re.Load,n)}(e,t,r);break;case Re.Pulse:!function(e,t,n="",r){setInterval(()=>{document.hidden||Ne(e,t,Re.Pulse,r)},parseInt(n||"")||15e3)}(e,t,n.triggerParams,r);break;case Re.Scroll:!function(e,t=""){const n=parseInt(t||"")||50;n<0||n>100||qe.push([e,n])}(t,n.triggerParams);break;case Re.Visible:Ee(e,t);break;case Re.Visibles:Ee(e,t,{multiple:!0});break;case Re.Wait:!function(e,t,n="",r){setTimeout(()=>Ne(e,t,Re.Wait,r),parseInt(n||"")||15e3)}(e,t,n.triggerParams,r)}var o,i}))}function Xe(e,t){Ne(e,t.target,Re.Click,"data-elb")}function He(e,t){t.target&&Ne(e,t.target,Re.Submit,"data-elb")}function Me(e,t){null!=t&&""!==t&&"number"!=typeof t&&"string"!=typeof t&&ae(()=>{if(Ue(t)){const n=Array.from(t);if(n.length>=1){const[t,r,o,i]=n;"string"==typeof t&&t.length>0&&Pe(e,t,r,o,i)}}else if("object"==typeof t&&null!==t){if(0===Object.keys(t).length)return;Pe(e,t)}},()=>{})()}function Ue(e){return null!=e&&"object"==typeof e&&"length"in e&&"number"==typeof e.length}var Te=async(e,t)=>{const n=function(e={}){const t=e.scope||document;return{prefix:"data-elb",pageview:!0,session:!0,elb:"elb",name:"walkerjs",elbLayer:"elbLayer",...e,scope:t}}(t.settings),r={...t,settings:n},o=n.scope,i={type:"browser",config:r,collector:e,destroy(){Le(e)}};if(!1!==n.elbLayer&&function(e,t={}){const n=t.name||"elbLayer";window[n]||(window[n]=[]);const r=window[n];Array.isArray(r)&&r.length>0&&function(e,t){const n=[],r=[];t.forEach(e=>{!function(e){if(Ue(e)){const t=Array.from(e);return"string"==typeof t[0]&&t[0].startsWith("walker ")}return!1}(e)?r.push(e):n.push(e)}),n.forEach(t=>{Me(e,t)}),r.forEach(t=>{Me(e,t)}),t.length=0}(e,r)}(e,{name:oe(n.elbLayer)?n.elbLayer:"elbLayer"}),Ie(e,o),n.session){const t="boolean"==typeof n.session?{}:n.session;!function(e,t={}){const n=t.config||{},r=te(e.config.sessionStatic||{},t.data||{});var o,i,s;(o=T,i="SessionStart",s=e.hooks,function(...e){let t;const n="post"+i,r=s["pre"+i],a=s[n];return t=r?r({fn:o},...e):o(...e),a&&(t=a({fn:o,result:t},...e)),t})({...n,cb:(e,t,r)=>{let o;const i=n;return!1!==i.cb&&i.cb?o=i.cb(e,t,r):!1!==i.cb&&(o=r(e,t,r)),t&&(t.session=e,P(t,"session")),o},data:r,collector:e})}(e,{config:t})}await async function(e,t,n){const r=()=>{e(t,n),P(t,"ready")};"loading"!==document.readyState?r():document.addEventListener("DOMContentLoaded",r)}(De,e,n);const s=e._destroy;return e._destroy=()=>{var e;null==(e=i.destroy)||e.call(i),s&&s()},{source:i,elb:(...t)=>{const[n,r,o,i,s,a]=t;return Pe(e,n,r,o,i,s,a)}}},Ge=Object.defineProperty,Ke=(e,t)=>{for(var n in t)Ge(e,n,{get:t[n],enumerable:!0})},Ve=!1;function Be(e,t={},n){if(t.filter&&!0===v(()=>t.filter(n),()=>!1)())return;const r=u(o=n)&&l(o.event)?o:a(o)&&o.length>=2?Fe(o):null!=(i=o)&&"object"==typeof i&&"length"in i&&"number"==typeof i.length&&i.length>0?Fe(Array.from(o)):null;var o,i;if(!r)return;const s={event:`${t.prefix||"dataLayer"} ${r.event}`,data:r,context:{},globals:{},custom:{},consent:{},nested:[],user:{},id:Math.random().toString(36).substring(2,15),trigger:"",entity:"",action:"",timestamp:Date.now(),timing:0,group:"",count:0,version:{source:"1.0.0",tagging:2},source:{type:"dataLayer",id:"",previous_id:""}};v(()=>e.push(s),()=>{})()}function Fe(e){const[t,n,r]=e;if(!l(t))return null;let o,i={};switch(t){case"consent":if(!l(n)||e.length<3)return null;if(!u(r)||null===r)return null;o=`${t} ${n}`,i={...r};break;case"event":if(!l(n))return null;o=n,u(r)&&(i={...r});break;case"config":if(!l(n))return null;o=`${t} ${n}`,u(r)&&(i={...r});break;case"set":if(l(n))o=`${t} ${n}`,u(r)&&(i={...r});else{if(!u(n))return null;o=`${t} custom`,i={...n}}break;default:return null}return{event:o,...i}}function Je(){return["consent","update",{ad_user_data:"granted",ad_personalization:"granted",ad_storage:"denied",analytics_storage:"granted"}]}function ze(){return["consent","default",{ad_storage:"denied",analytics_storage:"denied",ad_user_data:"denied",ad_personalization:"denied"}]}function Ye(){return["event","purchase",{transaction_id:"T_12345",value:25.42,currency:"EUR",items:[{item_id:"SKU_12345",item_name:"Product Name",item_category:"Category",quantity:1,price:25.42}]}]}function Qe(){return["event","add_to_cart",{currency:"EUR",value:15.25,items:[{item_id:"SKU_12345",item_name:"Product Name",item_variant:"red",quantity:1,price:15.25}]}]}function Ze(){return["event","view_item",{currency:"EUR",value:15.25,items:[{item_id:"SKU_12345",item_name:"Product Name",item_category:"Category",price:15.25}]}]}function et(){return["config","G-XXXXXXXXXX",{page_title:"Custom Page Title",page_location:"https://example.com/page",send_page_view:!1}]}function tt(){return["set",{currency:"EUR",country:"DE"}]}function nt(){return{event:"custom_event",custom_parameter:"custom_value",user_id:"user123"}}Ke({},{add_to_cart:()=>Qe,config:()=>et,consentDefault:()=>ze,consentUpdate:()=>Je,directDataLayerEvent:()=>nt,purchase:()=>Ye,setCustom:()=>tt,view_item:()=>Ze});Ke({},{add_to_cart:()=>it,config:()=>ut,configGA4:()=>at,consentOnlyMapping:()=>lt,consentUpdate:()=>rt,customEvent:()=>ct,purchase:()=>ot,view_item:()=>st});var rt={name:"walker consent",settings:{command:{map:{functional:{value:!0},analytics:{key:"analytics_storage",fn:e=>"granted"===e},marketing:{key:"ad_storage",fn:e=>"granted"===e}}}}},ot={name:"order complete",data:{map:{id:"transaction_id",total:"value",currency:"currency",nested:{loop:["items",{map:{type:{value:"product"},data:{map:{id:"item_id",name:"item_name",category:"item_category",quantity:"quantity",price:"price"}}}}]}}}},it={name:"product add",data:{map:{id:"items.0.item_id",name:"items.0.item_name",price:"value",currency:"currency",color:"items.0.item_variant",quantity:"items.0.quantity"}}},st={name:"product view",data:{map:{id:"items.0.item_id",name:"items.0.item_name",category:"items.0.item_category",price:"items.0.price",currency:"currency"}}},at={name:"page view",data:{map:{title:"page_title",url:"page_location"}}},ct={data:{map:{user_id:"user_id",custom_parameter:"custom_parameter"}}},ut={consent:{update:rt},purchase:ot,add_to_cart:it,view_item:st,"config G-XXXXXXXXXX":at,custom_event:ct,"*":{data:{}}},lt={consent:{update:rt}},dt=(e,t)=>{const{settings:n}=t,r={type:"dataLayer",config:t,collector:e,destroy(){const e=n.name||"dataLayer";window[e]&&Array.isArray(window[e])}};return function(e,t){const n=t.settings,r=(null==n?void 0:n.name)||"dataLayer",o=window[r];if(Array.isArray(o)&&!Ve){Ve=!0;try{for(const t of o)Be(e,n,t)}finally{Ve=!1}}}(e,t),function(e,t){const n=t.settings,r=(null==n?void 0:n.name)||"dataLayer";window[r]||(window[r]=[]);const o=window[r];if(!Array.isArray(o))return;const i=o.push.bind(o);o.push=function(...t){if(Ve)return i(...t);Ve=!0;try{for(const r of t)Be(e,n,r)}finally{Ve=!1}return i(...t)}}(e,t),{source:r,elb:(...e)=>{const t=n.name||"dataLayer",r=window[t];return Array.isArray(r)?Promise.resolve(r.push(...e)):Promise.resolve(0)}}};function ft(e={}){const t=(t,n)=>{const r={...n,settings:{name:"dataLayer",prefix:"dataLayer",...e,...n.settings}};return dt(t,r)};return t.init=(e,t)=>dt(e,{type:"dataLayer",settings:t.settings}),t.settings={name:"dataLayer",prefix:"dataLayer",...e},t.type="dataLayer",t}function gt(){window.dataLayer=window.dataLayer||[];const e=e=>{u(e)&&u(e.source)&&String(e.source.type).includes("dataLayer")||window.dataLayer.push(e)};return{type:"dataLayer",config:{},push:(t,n)=>{e(n.data||t)},pushBatch:t=>{e({event:"batch",batched_event:t.key,events:t.data.length?t.data:t.events})}}}var pt={};async function mt(e={}){const t=s({collector:{destinations:{dataLayer:gt()}},browser:{run:!0,session:!0},dataLayer:!1,elb:"elb"},e),n={...t.collector,sources:{browser:{code:Te,config:{settings:t.browser}}}};if(t.dataLayer){const e=u(t.dataLayer)?t.dataLayer:{};n.sources&&(n.sources.dataLayer={code:ft(e),config:{settings:e}})}const{collector:r}=await X(n),o=r.sources.browser;if(!(null==o?void 0:o.elb))throw new Error("Failed to initialize browser source");const i={collector:r,elb:o.elb};return t.elb&&(window[t.elb]=o.elb),t.name&&(window[t.name]=r),i}var yt=mt;export{pt as Walkerjs,mt as createWalkerjs,yt as default,de as getAllEvents,fe as getEvents,ge as getGlobals};//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/destination.ts","../src/types/index.ts","../src/index.ts"],"sourcesContent":["import type { Destination } from '@walkeros/core';\nimport type { DataLayer } from './types';\nimport { isObject } from '@walkeros/core';\n\nexport function dataLayerDestination(): Destination.InitDestination {\n window.dataLayer = window.dataLayer || [];\n const dataLayerPush = (event: unknown) => {\n // Do not process events from dataLayer source\n if (\n isObject(event) &&\n isObject(event.source) &&\n String(event.source.type).includes('dataLayer')\n )\n return;\n\n (window.dataLayer as DataLayer)!.push(event);\n };\n const destination: Destination.Instance = {\n type: 'dataLayer',\n config: {},\n push: (event, context) => {\n dataLayerPush(context.data || event);\n },\n pushBatch: (batch) => {\n dataLayerPush({\n event: 'batch',\n batched_event: batch.key,\n events: batch.data.length ? batch.data : batch.events,\n });\n },\n };\n\n return destination;\n}\n","import type { Collector, Source, WalkerOS } from '@walkeros/core';\nimport type { SourceBrowser } from '@walkeros/web-source-browser';\nimport type { SourceDataLayer } from '@walkeros/web-source-dataLayer';\n\ndeclare global {\n interface Window {\n [key: string]: DataLayer;\n }\n}\n\n// Instance interface\nexport interface Instance {\n collector: Collector.Instance;\n elb: SourceBrowser.BrowserPush;\n}\n\n// Configuration interface\nexport interface Config {\n // Collector configuration\n collector?: Collector.InitConfig;\n\n // Browser source configuration\n browser?: Partial<SourceBrowser.Settings>;\n\n // DataLayer configuration\n dataLayer?: boolean | Partial<SourceDataLayer.Settings>;\n\n // Global configuration\n elb?: string; // Name for the global elb function\n name?: string; // Name for the global instance\n run?: boolean; // Auto-run on initialization (default: true)\n}\n\nexport type DataLayer = undefined | Array<unknown>;\n","import type { Config, Instance } from './types';\nimport { createCollector, type CollectorConfig } from '@walkeros/collector';\nimport { assign, isObject } from '@walkeros/core';\nimport {\n sourceBrowser,\n getAllEvents,\n getEvents,\n getGlobals,\n type SourceBrowser,\n} from '@walkeros/web-source-browser';\nimport { sourceDataLayer } from '@walkeros/web-source-dataLayer';\nimport { dataLayerDestination } from './destination';\n\n// Re-export types\nexport * as Walkerjs from './types';\n\nexport { getAllEvents, getEvents, getGlobals };\n\n// Factory function to create walker.js instance\nexport async function createWalkerjs(config: Config = {}): Promise<Instance> {\n // Default configuration\n const defaultConfig: Config = {\n collector: {\n destinations: {\n dataLayer: dataLayerDestination(),\n },\n },\n browser: {\n run: true,\n session: true,\n },\n dataLayer: false,\n elb: 'elb',\n };\n\n const fullConfig = assign(defaultConfig, config);\n\n // Build collector config with sources\n const collectorConfig: Partial<CollectorConfig> = {\n ...fullConfig.collector,\n sources: {\n browser: {\n code: sourceBrowser,\n config: {\n settings: fullConfig.browser,\n },\n },\n },\n };\n\n // Add dataLayer source if configured\n if (fullConfig.dataLayer) {\n const dataLayerSettings = isObject(fullConfig.dataLayer)\n ? fullConfig.dataLayer\n : {};\n\n if (collectorConfig.sources) {\n collectorConfig.sources.dataLayer = {\n code: sourceDataLayer(dataLayerSettings),\n config: {\n settings: dataLayerSettings,\n },\n };\n }\n }\n\n const { collector } = await createCollector(collectorConfig);\n\n // Get browser elb function\n const browserSource = collector.sources.browser;\n if (!browserSource?.elb) {\n throw new Error('Failed to initialize browser source');\n }\n\n const instance: Instance = {\n collector,\n elb: browserSource.elb as SourceBrowser.BrowserPush,\n };\n\n // Set up global variables if configured\n if (fullConfig.elb) window[fullConfig.elb] = browserSource.elb;\n if (fullConfig.name) window[fullConfig.name] = collector;\n\n return instance;\n}\n\n// Export factory function as default\nexport default createWalkerjs;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,SAAS,uBAAoD;AAClE,SAAO,YAAY,OAAO,aAAa,CAAC;AACxC,QAAM,gBAAgB,CAAC,UAAmB;AAExC,QACE,EAAS,KAAK,KACd,EAAS,MAAM,MAAM,KACrB,OAAO,MAAM,OAAO,IAAI,EAAE,SAAS,WAAW;AAE9C;AAEF,IAAC,OAAO,UAAyB,KAAK,KAAK;AAAA,EAC7C;AACA,QAAM,cAAoC;AAAA,IACxC,MAAM;AAAA,IACN,QAAQ,CAAC;AAAA,IACT,MAAM,CAAC,OAAO,YAAY;AACxB,oBAAc,QAAQ,QAAQ,KAAK;AAAA,IACrC;AAAA,IACA,WAAW,CAAC,UAAU;AACpB,oBAAc;AAAA,QACZ,OAAO;AAAA,QACP,eAAe,MAAM;AAAA,QACrB,QAAQ,MAAM,KAAK,SAAS,MAAM,OAAO,MAAM;AAAA,MACjD,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;;;ACjCA;;;ACmBA,eAAsB,eAAe,SAAiB,CAAC,GAAsB;AAE3E,QAAM,gBAAwB;AAAA,IAC5B,WAAW;AAAA,MACT,cAAc;AAAA,QACZ,WAAW,qBAAqB;AAAA,MAClC;AAAA,IACF;AAAA,IACA,SAAS;AAAA,MACP,KAAK;AAAA,MACL,SAAS;AAAA,IACX;AAAA,IACA,WAAW;AAAA,IACX,KAAK;AAAA,EACP;AAEA,QAAM,aAAa,EAAO,eAAe,MAAM;AAG/C,QAAM,kBAA4C;AAAA,IAChD,GAAG,WAAW;AAAA,IACd,SAAS;AAAA,MACP,SAAS;AAAA,QACP,MAAM;AAAA,QACN,QAAQ;AAAA,UACN,UAAU,WAAW;AAAA,QACvB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAGA,MAAI,WAAW,WAAW;AACxB,UAAM,oBAAoB,EAAS,WAAW,SAAS,IACnD,WAAW,YACX,CAAC;AAEL,QAAI,gBAAgB,SAAS;AAC3B,sBAAgB,QAAQ,YAAY;AAAA,QAClC,MAAMA,GAAgB,iBAAiB;AAAA,QACvC,QAAQ;AAAA,UACN,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,EAAE,UAAU,IAAI,MAAMC,GAAgB,eAAe;AAG3D,QAAM,gBAAgB,UAAU,QAAQ;AACxC,MAAI,EAAC,+CAAe,MAAK;AACvB,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AAEA,QAAM,WAAqB;AAAA,IACzB;AAAA,IACA,KAAK,cAAc;AAAA,EACrB;AAGA,MAAI,WAAW,IAAK,QAAO,WAAW,GAAG,IAAI,cAAc;AAC3D,MAAI,WAAW,KAAM,QAAO,WAAW,IAAI,IAAI;AAE/C,SAAO;AACT;AAGA,IAAO,gBAAQ;","names":["x","J"]}
|
package/dist/walker.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(()=>{var e,t,n=Object.getOwnPropertyNames,r=(e={"package.json"(e,t){t.exports={name:"@walkeros/core",description:"Core types and platform-agnostic utilities for walkerOS",version:"0.0.7",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/core"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","web analytics","product analytics","core","types","utils"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return t||(0,e[n(e)[0]])((t={exports:{}}).exports,t),t.exports}),o={Storage:{Local:"local",Session:"session",Cookie:"cookie"}},i={merge:!0,shallow:!0,extend:!0};function s(e,t={},n={}){n={...i,...n};const r=Object.entries(t).reduce((t,[r,o])=>{const i=e[r];return n.merge&&Array.isArray(i)&&Array.isArray(o)?t[r]=o.reduce((e,t)=>e.includes(t)?e:[...e,t],[...i]):(n.extend||r in e)&&(t[r]=o),t},{});return n.shallow?{...e,...r}:(Object.assign(e,r),e)}function a(e){return Array.isArray(e)}function c(e){return void 0!==e}function u(e){return"object"==typeof e&&null!==e&&!a(e)&&"[object Object]"===Object.prototype.toString.call(e)}function l(e){return"string"==typeof e}function d(e,t=new WeakMap){if("object"!=typeof e||null===e)return e;if(t.has(e))return t.get(e);const n=Object.prototype.toString.call(e);if("[object Object]"===n){const n={};t.set(e,n);for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=d(e[r],t));return n}if("[object Array]"===n){const n=[];return t.set(e,n),e.forEach(e=>{n.push(d(e,t))}),n}if("[object Date]"===n)return new Date(e.getTime());if("[object RegExp]"===n){const t=e;return new RegExp(t.source,t.flags)}return e}function f(e,t="",n){const r=t.split(".");let o=e;for(let e=0;e<r.length;e++){const t=r[e];if("*"===t&&a(o)){const t=r.slice(e+1).join("."),i=[];for(const e of o){const r=f(e,t,n);i.push(r)}return i}if(o=o instanceof Object?o[t]:void 0,!o)break}return c(o)?o:n}function g(e,t={},n={}){const r={...t,...n},o={};let i=void 0===e;return Object.keys(r).forEach(t=>{r[t]&&(o[t]=!0,e&&e[t]&&(i=!0))}),!!i&&o}var{version:p}=r();function m(e=6){let t="";for(let n=36;t.length<e;)t+=(Math.random()*n|0).toString(n);return t}function y(e){return function(e){return"boolean"==typeof e}(e)||l(e)||function(e){return"number"==typeof e&&!Number.isNaN(e)}(e)||!c(e)||a(e)&&e.every(y)||u(e)&&Object.values(e).every(y)}function b(e){return y(e)?e:void 0}function h(e,t,n){return function(...r){try{return e(...r)}catch(e){if(!t)return;return t(e)}finally{null==n||n()}}}function w(e,t,n){return async function(...r){try{return await e(...r)}catch(e){if(!t)return;return await t(e)}finally{await(null==n?void 0:n())}}}async function v(e,t={},n={}){var r;if(!c(e))return;const o=u(e)&&e.consent||n.consent||(null==(r=n.collector)?void 0:r.consent),i=a(t)?t:[t];for(const t of i){const r=await w(k)(e,t,{...n,consent:o});if(c(r))return r}}async function k(e,t,n={}){const{collector:r,consent:o}=n;return(a(t)?t:[t]).reduce(async(t,i)=>{const s=await t;if(s)return s;const u=l(i)?{key:i}:i;if(!Object.keys(u).length)return;const{condition:d,consent:p,fn:m,key:y,loop:h,map:S,set:_,validate:j,value:O}=u;if(d&&!await w(d)(e,i,r))return;if(p&&!g(p,o))return O;let x=c(O)?O:e;if(m&&(x=await w(m)(e,i,n)),y&&(x=f(e,y,O)),h){const[t,r]=h,o="this"===t?[e]:await v(e,t,n);a(o)&&(x=(await Promise.all(o.map(e=>v(e,r,n)))).filter(c))}else S?x=await Object.entries(S).reduce(async(t,[r,o])=>{const i=await t,s=await v(e,o,n);return c(s)&&(i[r]=s),i},Promise.resolve({})):_&&(x=await Promise.all(_.map(t=>k(e,t,n))));j&&!await w(j)(x)&&(x=void 0);const E=b(x);return c(E)?E:b(O)},Promise.resolve(void 0))}function S(e){return e?e.trim().replace(/^'|'$/g,"").trim():""}function _(e,t,n){return function(...r){let o;const i="post"+t,s=n["pre"+t],a=n[i];return o=s?s({fn:e},...r):e(...r),a&&(o=a({fn:e,result:o},...r)),o}}function j(e,t){return(e.getAttribute(t)||"").trim()}function O(e){const t={};return function(e,t=";"){if(!e)return[];const n=new RegExp(`(?:[^${t}']+|'[^']*')+`,"ig");return e.match(n)||[]}(e).forEach(e=>{const[n,r]=function(e){const[t,n]=e.split(/:(.+)/,2);return[S(t||""),S(n||"")]}(e);n&&("true"===r?t[n]=!0:"false"===r?t[n]=!1:r&&/^\d+$/.test(r)?t[n]=parseInt(r,10):r&&/^\d+\.\d+$/.test(r)?t[n]=parseFloat(r):t[n]=r||!0)}),t}var x=function(){const e=window;(e.elbLayer=e.elbLayer||[]).push(arguments)};function E(e){const t=getComputedStyle(e);if("none"===t.display)return!1;if("visible"!==t.visibility)return!1;if(t.opacity&&Number(t.opacity)<.1)return!1;let n;const r=window.innerHeight,o=e.getBoundingClientRect(),i=o.height,s=o.y,a=s+i,c={x:o.x+e.offsetWidth/2,y:o.y+e.offsetHeight/2};if(i<=r){if(e.offsetWidth+o.width===0||e.offsetHeight+o.height===0)return!1;if(c.x<0)return!1;if(c.x>(document.documentElement.clientWidth||window.innerWidth))return!1;if(c.y<0)return!1;if(c.y>(document.documentElement.clientHeight||window.innerHeight))return!1;n=document.elementFromPoint(c.x,c.y)}else{const e=r/2;if(s<0&&a<e)return!1;if(a>r&&s>e)return!1;n=document.elementFromPoint(c.x,r/2)}if(n)do{if(n===e)return!0}while(n=n.parentElement);return!1}function L(e={}){const{cb:t,consent:n,collector:r,storage:o}=e,i=(null==r?void 0:r.push)||x;if(!n)return $((o?D:I)(e),r,t);{const r=function(e,t){let n;return(r,o)=>{if(c(n)&&n===(null==r?void 0:r.group))return;n=null==r?void 0:r.group;let i=()=>I(e);if(e.consent){g((a(e.consent)?e.consent:[e.consent]).reduce((e,t)=>({...e,[t]:!0}),{}),o)&&(i=()=>D(e))}return $(i(),r,t)}}(e,t);i("walker on","consent",(a(n)?n:[n]).reduce((e,t)=>({...e,[t]:r}),{}))}}function $(e,t,n){return!1===n?e:(n||(n=P),n(e,t,P))}var C,A,P=(e,t)=>{const n=(null==t?void 0:t.push)||x,r={};return e.id&&(r.session=e.id),e.storage&&e.device&&(r.device=e.device),n("walker user",r),e.isStart&&n({event:"session start",data:e}),e};function q(e,t=o.Storage.Session){var n;function r(e){try{return JSON.parse(e||"")}catch(t){let n=1,r="";return e&&(n=0,r=e),{e:n,v:r}}}let i,s;switch(t){case o.Storage.Cookie:i=decodeURIComponent((null==(n=document.cookie.split("; ").find(t=>t.startsWith(e+"=")))?void 0:n.split("=")[1])||"");break;case o.Storage.Local:s=r(window.localStorage.getItem(e));break;case o.Storage.Session:s=r(window.sessionStorage.getItem(e))}return s&&(i=s.v,0!=s.e&&s.e<Date.now()&&(function(e,t=o.Storage.Session){switch(t){case o.Storage.Cookie:R(e,"",0,t);break;case o.Storage.Local:window.localStorage.removeItem(e);break;case o.Storage.Session:window.sessionStorage.removeItem(e)}}(e,t),i="")),function(e){if("true"===e)return!0;if("false"===e)return!1;const t=Number(e);return e==t&&""!==e?t:String(e)}(i||"")}function R(e,t,n=30,r=o.Storage.Session,i){const s={e:Date.now()+6e4*n,v:String(t)},a=JSON.stringify(s);switch(r){case o.Storage.Cookie:{t="object"==typeof t?JSON.stringify(t):t;let r=`${e}=${encodeURIComponent(t)}; max-age=${60*n}; path=/; SameSite=Lax; secure`;i&&(r+="; domain="+i),document.cookie=r;break}case o.Storage.Local:window.localStorage.setItem(e,a);break;case o.Storage.Session:window.sessionStorage.setItem(e,a)}return q(e,r)}function D(e={}){const t=Date.now(),{length:n=30,deviceKey:r="elbDeviceId",deviceStorage:o="local",deviceAge:i=30,sessionKey:s="elbSessionId",sessionStorage:a="local",pulse:c=!1}=e,u=I(e);let l=!1;const d=h((e,t,n)=>{let r=q(e,n);return r||(r=m(8),R(e,r,1440*t,n)),String(r)})(r,i,o),f=h((e,r)=>{const o=JSON.parse(String(q(e,r)));return c||(o.isNew=!1,u.marketing&&(Object.assign(o,u),l=!0),l||o.updated+6e4*n<t?(delete o.id,delete o.referrer,o.start=t,o.count++,o.runs=1,l=!0):o.runs++),o},()=>{l=!0})(s,a)||{},g={id:m(12),start:t,isNew:!0,count:1,runs:1},p=Object.assign(g,u,f,{device:d},{isStart:l,storage:!0,updated:t},e.data);return R(s,JSON.stringify(p),2*n,a),p}function I(e={}){let t=e.isStart||!1;const n={isStart:t,storage:!1};if(!1===e.isStart)return n;if(!t){const[e]=performance.getEntriesByType("navigation");if("navigate"!==e.type)return n}const r=new URL(e.url||window.location.href),o=e.referrer||document.referrer,i=o&&new URL(o).hostname,a=function(e,t={}){const n="clickId",r={},o={utm_campaign:"campaign",utm_content:"content",utm_medium:"medium",utm_source:"source",utm_term:"term",dclid:n,fbclid:n,gclid:n,msclkid:n,ttclid:n,twclid:n,igshid:n,sclid:n};return Object.entries(s(o,t)).forEach(([t,o])=>{const i=e.searchParams.get(t);i&&(o===n&&(o=t,r[n]=t),r[o]=i)}),r}(r,e.parameters);if(Object.keys(a).length&&(a.marketing||(a.marketing=!0),t=!0),!t){const n=e.domains||[];n.push(r.hostname),t=!n.includes(i)}return t?Object.assign({isStart:t,storage:!1,start:Date.now(),id:m(12),referrer:i},a,e.data):n}var N,W,X=Object.getOwnPropertyNames,M=(C={"package.json"(e,t){t.exports={name:"@walkeros/collector",description:"Unified platform-agnostic collector for walkerOS",version:"0.0.7",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{"@walkeros/core":"0.0.7"},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/collector"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","collector","event processing"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return A||(0,C[X(C)[0]])((A={exports:{}}).exports,A),A.exports}),H={Action:"action",Config:"config",Consent:"consent",Context:"context",Custom:"custom",Destination:"destination",Elb:"elb",Globals:"globals",Hook:"hook",Init:"init",Link:"link",On:"on",Prefix:"data-elb",Ready:"ready",Run:"run",Session:"session",User:"user",Walker:"walker"},U=H;function T(e,t,n,r){let o=n||[];if(n||(o=e.on[t]||[],Object.values(e.destinations).forEach(e=>{var n;const r=null==(n=e.config.on)?void 0:n[t];r&&(o=o.concat(r))})),o.length)switch(t){case U.Consent:!function(e,t,n){const r=n||e.consent;t.forEach(t=>{Object.keys(r).filter(e=>e in t).forEach(n=>{h(t[n])(e,r)})})}(e,o,r);break;case U.Ready:case U.Run:s=o,(i=e).allowed&&s.forEach(e=>{h(e)(i)});break;case U.Session:!function(e,t){e.session&&t.forEach(t=>{h(t)(e,e.session)})}(e,o)}var i,s}async function G(e,t,n,r){let o;switch(t){case U.Config:u(n)&&s(e.config,n,{shallow:!1});break;case U.Consent:u(n)&&(o=await async function(e,t){const{consent:n}=e;let r=!1;const o={};return Object.entries(t).forEach(([e,t])=>{const n=!!t;o[e]=n,r=r||n}),e.consent=s(n,o),T(e,"consent",void 0,o),r?K(e):J({ok:!0})}(e,n));break;case U.Custom:u(n)&&(e.custom=s(e.custom,n));break;case U.Destination:u(n)&&function(e){return"function"==typeof e}(n.push)&&(o=await async function(e,t,n){const r=n||t.config||{init:!1},o={...t,config:r};let i=r.id;if(!i)do{i=m(4)}while(e.destinations[i]);return e.destinations[i]=o,!1!==r.queue&&(o.queue=[...e.queue]),K(e,void 0,{[i]:o})}(e,n,r));break;case U.Globals:u(n)&&(e.globals=s(e.globals,n));break;case U.On:l(n)&&function(e,t,n){const r=e.on,o=r[t]||[],i=a(n)?n:[n];i.forEach(e=>{o.push(e)}),r[t]=o,T(e,t,i)}(e,n,r);break;case U.Run:o=await async function(e,t){return e.allowed=!0,e.count=0,e.group=m(),e.timing=Date.now(),t&&(t.consent&&(e.consent=s(e.consent,t.consent)),t.user&&(e.user=s(e.user,t.user)),t.globals&&(e.globals=s(e.config.globalsStatic||{},t.globals)),t.custom&&(e.custom=s(e.custom,t.custom))),Object.values(e.destinations).forEach(e=>{e.queue=[]}),e.round++,T(e,"run"),await K(e)}(e,n);break;case U.User:u(n)&&s(e.user,n,{shallow:!1})}return o||{ok:!0,successful:[],queued:[],failed:[]}}function F(e,t,n){return _(async(r,o,i)=>await w(async()=>{if("string"==typeof r&&r.startsWith("walker ")){const n=r.replace("walker ","");return await t(e,n,o,i)}{const s=n("string"==typeof r?{event:r}:r),{event:a,command:c}=function(e,t,n={}){const r=function(e){return typeof e==typeof""}(t)?{event:t,...n}:{...n,...t||{}};if(!r.event)throw new Error("Event name is required");const[o,i]=r.event.split(" ");if(!o||!i)throw new Error("Event name is invalid");if(o===H.Walker)return{command:i};++e.count;const{timestamp:s=Date.now(),group:a=e.group,count:c=e.count}=r,{event:u=`${o} ${i}`,data:l={},context:d={},globals:f=e.globals,custom:g={},user:p=e.user,nested:m=[],consent:y=e.consent,id:b=`${s}-${a}-${c}`,trigger:h="",entity:w=o,action:v=i,timing:k=0,version:S={source:e.version,tagging:e.config.tagging||0},source:_={type:"collector",id:"",previous_id:""}}=r;return{event:{event:u,data:l,context:d,globals:f,custom:g,user:p,nested:m,consent:y,id:b,trigger:h,entity:w,action:v,timestamp:s,timing:k,group:a,count:c,version:S,source:_}}}(e,s.event,s);return c?await t(e,c,o,i):await K(e,a)}},()=>J({ok:!1}))(),"Push",e.hooks)}async function K(e,t,n){const{allowed:r,consent:o,globals:i,user:a}=e;if(!r)return J({ok:!1});t&&e.queue.push(t),n||(n=e.destinations);const c=await Promise.all(Object.entries(n||{}).map(async([n,r])=>{let c=(r.queue||[]).map(e=>({...e,consent:o}));if(r.queue=[],t){let n=d(t);await Promise.all(Object.entries(r.config.policy||[]).map(async([r,o])=>{const i=await v(t,o,{collector:e});n=function(e,t,n){const r=d(e),o=t.split(".");let i=r;for(let e=0;e<o.length;e++){const t=o[e];e===o.length-1?i[t]=n:(t in i&&"object"==typeof i[t]&&null!==i[t]||(i[t]={}),i=i[t])}return r}(n,r,i)})),c.push(n)}if(!c.length)return{id:n,destination:r,skipped:!0};const u=[],l=c.filter(e=>{const t=g(r.config.consent,o,e.consent);return!t||(e.consent=t,u.push(e),!1)});if(r.queue.concat(l),!u.length)return{id:n,destination:r,queue:c};if(!await w(V)(e,r))return{id:n,destination:r,queue:c};let f=!1;return r.dlq||(r.dlq=[]),await Promise.all(u.map(async t=>(t.globals=s(i,t.globals),t.user=s(a,t.user),await w(B,n=>(e.config.onError&&e.config.onError(n,e),f=!0,r.dlq.push([t,n]),!1))(e,r,t),t))),{id:n,destination:r,error:f}})),u=[],l=[],f=[];for(const e of c){if(e.skipped)continue;const t=e.destination,n={id:e.id,destination:t};e.error?f.push(n):e.queue&&e.queue.length?(t.queue=(t.queue||[]).concat(e.queue),l.push(n)):u.push(n)}return J({ok:!f.length,event:t,successful:u,queued:l,failed:f})}async function V(e,t){if(t.init&&!t.config.init){const n={collector:e,config:t.config,wrap:Y(t,e)},r=await _(t.init,"DestinationInit",e.hooks)(n);if(!1===r)return r;t.config={...r||t.config,init:!0}}return!0}async function B(e,t,n){var r;const{config:o}=t,{eventMapping:i,mappingKey:l}=await async function(e,t){var n;const[r,o]=(e.event||"").split(" ");if(!t||!r||!o)return{};let i,s="",c=r,u=o;const l=t=>{if(t)return(t=a(t)?t:[t]).find(t=>!t.condition||t.condition(e))};t[c]||(c="*");const d=t[c];return d&&(d[u]||(u="*"),i=l(d[u])),i||(c="*",u="*",i=l(null==(n=t[c])?void 0:n[u])),i&&(s=`${c} ${u}`),{eventMapping:i,mappingKey:s}}(n,o.mapping);let d=o.data&&await v(n,o.data,{collector:e});if(i){if(i.ignore)return!1;if(i.name&&(n.event=i.name),i.data){const t=i.data&&await v(n,i.data,{collector:e});d=u(d)&&u(t)?s(d,t):t}}const f={collector:e,config:o,data:d,mapping:i,wrap:Y(t,e)};if((null==i?void 0:i.batch)&&t.pushBatch){const s=i.batched||{key:l||"",events:[],data:[]};s.events.push(n),c(d)&&s.data.push(d),i.batchFn=i.batchFn||function(e,t=1e3,n=!1){let r,o=null,i=!1;return(...s)=>new Promise(a=>{const c=n&&!i;o&&clearTimeout(o),o=setTimeout(()=>{o=null,n&&!i||(r=e(...s),a(r))},t),c&&(i=!0,r=e(...s),a(r))})}((e,t)=>{const n={collector:t,config:o,data:d,mapping:i,wrap:Y(e,t)};_(e.pushBatch,"DestinationPushBatch",t.hooks)(s,n),s.events=[],s.data=[]},i.batch),i.batched=s,null==(r=i.batchFn)||r.call(i,t,e)}else await _(t.push,"DestinationPush",e.hooks)(n,f);return!0}function J(e){var t;return s({ok:!(null==(t=null==e?void 0:e.failed)?void 0:t.length),successful:[],queued:[],failed:[]},e)}function z(e){return Object.entries(e).reduce((e,[t,n])=>(e[t]={...n,config:u(n.config)?n.config:{}},e),{})}function Y(e,t){var n;const r=e.config.wrapper||{},o=null!=(n=e.config.dryRun)?n:null==t?void 0:t.config.dryRun;return function(e="unknown",{dryRun:t=!1,mockReturn:n,onCall:r}={}){return function(o,i){return"function"!=typeof i?i:(...s)=>(r&&r({name:o,type:e},s),t?n:i(...s))}}(e.type||"unknown",{...r,...c(o)&&{dryRun:o}})}async function Q(e,t,n){var r,o;const i={disabled:null!=(r=n.disabled)&&r,settings:null!=(o=n.settings)?o:{},onError:n.onError};if(i.disabled)return{};const s=await w(t)(e,i);if(!s||!s.source)return{};const a=i.type||s.source.type||"",c=n.id||`${a}_${m(5)}`;return s.source&&s.elb&&(s.source.elb=s.elb),e.sources[c]={type:a,settings:i.settings,mapping:void 0,elb:s.elb},s}async function Z(e={}){const t=function(e){const{version:t}=M(),n=s({dryRun:!1,globalsStatic:{},sessionStatic:{},tagging:0,verbose:!1,onLog:r,run:!0,destinations:{},consent:{},user:{},globals:{},custom:{}},e,{merge:!1,extend:!1});function r(e,t){!function(e,t=!1){t&&console.dir(e,{depth:4})}({message:e},t||n.verbose)}n.onLog=r;const o={...n.globalsStatic,...n.globals},i={allowed:!1,config:n,consent:n.consent||{},count:0,custom:n.custom||{},destinations:z(n.destinations||{}),globals:o,group:"",hooks:{},on:{},queue:[],round:0,session:void 0,timing:Date.now(),user:n.user||{},version:t,sources:{},push:void 0};return i.push=F(i,G,e=>({timing:Math.round((Date.now()-i.timing)/10)/100,source:{type:"collector",id:"",previous_id:""},...e})),i}(e),{consent:n,user:r,globals:o,custom:i,sources:a}=e;return n&&await t.push("walker consent",n),r&&await t.push("walker user",r),o&&Object.assign(t.globals,o),i&&Object.assign(t.custom,i),a&&await async function(e,t={}){for(const[n,r]of Object.entries(t)){const{code:t,config:o={}}=r,i={id:n,...o},s=await Q(e,t,i);s.source&&(s.elb&&(s.source.elb=s.elb),e.sources[n]={type:s.source.type,settings:s.source.config.settings,mapping:void 0,elb:s.elb})}}(t,a),t.config.run&&await t.push("walker run"),{collector:t,elb:t.push}}var ee=Object.getOwnPropertyNames,te=(N={"package.json"(e,t){t.exports={name:"@walkeros/core",description:"Core types and platform-agnostic utilities for walkerOS",version:"0.0.7",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/core"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","web analytics","product analytics","core","types","utils"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return W||(0,N[ee(N)[0]])((W={exports:{}}).exports,W),W.exports}),ne={merge:!0,shallow:!0,extend:!0};function re(e,t={},n={}){n={...ne,...n};const r=Object.entries(t).reduce((t,[r,o])=>{const i=e[r];return n.merge&&Array.isArray(i)&&Array.isArray(o)?t[r]=o.reduce((e,t)=>e.includes(t)?e:[...e,t],[...i]):(n.extend||r in e)&&(t[r]=o),t},{});return n.shallow?{...e,...r}:(Object.assign(e,r),e)}function oe(e){return Array.isArray(e)}function ie(e){return"object"==typeof e&&null!==e&&!oe(e)&&"[object Object]"===Object.prototype.toString.call(e)}function se(e){return"string"==typeof e}function ae(e){if("true"===e)return!0;if("false"===e)return!1;const t=Number(e);return e==t&&""!==e?t:String(e)}var{version:ce}=te();function ue(e,t,n){return function(...r){try{return e(...r)}catch(e){if(!t)return;return t(e)}finally{null==n||n()}}}function le(e){return e?e.trim().replace(/^'|'$/g,"").trim():""}function de(e,t,n=!0){return e+(null!=t?(n?"-":"")+t:"")}function fe(e,t,n,r=!0){return he(j(t,de(e,n,r))||"").reduce((e,n)=>{let[r,o]=we(n);if(!r)return e;if(o||(r.endsWith(":")&&(r=r.slice(0,-1)),o=""),o.startsWith("#")){o=o.slice(1);try{let e=t[o];e||"selected"!==o||(e=t.options[t.selectedIndex].text),o=String(e)}catch(e){o=""}}return r.endsWith("[]")?(r=r.slice(0,-2),oe(e[r])||(e[r]=[]),e[r].push(ae(o))):e[r]=ae(o),e},{})}function ge(e){const t={};return he(e).forEach(e=>{const[n,r]=we(e),[o,i]=ve(n);if(!o)return;let[s,a]=ve(r||"");s=s||o,t[o]||(t[o]=[]),t[o].push({trigger:o,triggerParams:i,action:s,actionParams:a})}),t}function pe(e,t,n,r){const o=j(t,de(e));if(!o||r&&!r[o])return null;const i=[t],s=`[${de(e,o)}],[${de(e,"")}]`,a=de(e,U.Link,!1);let c={};const u=[],[l,d]=ye(n||t,s,e,o);be(t,`[${a}]`,t=>{const[n,r]=we(j(t,a));"parent"===r&&be(document.body,`[${a}="${n}:child"]`,t=>{i.push(t);const n=pe(e,t);n&&u.push(n)})});const f=[];i.forEach(e=>{e.matches(s)&&f.push(e),be(e,s,e=>f.push(e))});let g={};return f.forEach(t=>{g=re(g,fe(e,t,"")),c=re(c,fe(e,t,o))}),c=re(re(g,c),l),i.forEach(t=>{be(t,`[${de(e)}]`,t=>{const n=pe(e,t);n&&u.push(n)})}),{type:o,data:c,context:d,nested:u}}function me(e,t){const n=de(e,U.Link,!1);if(t.matches(`[${n}]`)){const[e,r]=we(j(t,n));if("child"===r)return document.querySelector(`[${n}="${e}:parent"]`)}return!t.parentElement&&t.getRootNode&&t.getRootNode()instanceof ShadowRoot?t.getRootNode().host:t.parentElement}function ye(e,t,n,r){let o={};const i={};let s=e;const a=`[${de(n,U.Context,!1)}]`;let c=0;for(;s;)s.matches(t)&&(o=re(fe(n,s,""),o),o=re(fe(n,s,r),o)),s.matches(a)&&(Object.entries(fe(n,s,U.Context,!1)).forEach(([e,t])=>{t&&!i[e]&&(i[e]=[t,c])}),++c),s=me(n,s);return[o,i]}function be(e,t,n){e.querySelectorAll(t).forEach(n)}function he(e,t=";"){if(!e)return[];const n=new RegExp(`(?:[^${t}']+|'[^']*')+`,"ig");return e.match(n)||[]}function we(e){const[t,n]=e.split(/:(.+)/,2);return[le(t),le(n)]}function ve(e){const[t,n]=e.split("(",2);return[t,n?n.slice(0,-1):""]}var ke,Se=new WeakMap,_e=new WeakMap;function je(e){const t=Date.now();let n=_e.get(e);return(!n||t-n.lastChecked>500)&&(n={isVisible:E(e),lastChecked:t},_e.set(e,n)),n.isVisible}function Oe(e){if(window.IntersectionObserver)return ue(()=>new window.IntersectionObserver(t=>{t.forEach(t=>{!function(e,t){var n,r;const o=t.target,i=e._visibilityState;if(!i)return;const s=i.timers.get(o);if(t.intersectionRatio>0){const r=Date.now();let a=Se.get(o);if((!a||r-a.lastChecked>1e3)&&(a={isLarge:o.offsetHeight>window.innerHeight,lastChecked:r},Se.set(o,a)),t.intersectionRatio>=.5||a.isLarge&&je(o)){const t=null==(n=i.elementConfigs)?void 0:n.get(o);if((null==t?void 0:t.multiple)&&t.blocked)return;if(!s){const t=window.setTimeout(async()=>{var t;if(je(o)){await Ie(e,o,qe.Visible,"data-elb");const n=null==(t=i.elementConfigs)?void 0:t.get(o);(null==n?void 0:n.multiple)?n.blocked=!0:function(e,t){const n=e._visibilityState;if(!n)return;n.observer&&n.observer.unobserve(t);const r=n.timers.get(t);r&&(clearTimeout(r),n.timers.delete(t)),Se.delete(t),_e.delete(t)}(e,o)}},i.duration);i.timers.set(o,t)}return}}s&&(clearTimeout(s),i.timers.delete(o));const a=null==(r=i.elementConfigs)?void 0:r.get(o);(null==a?void 0:a.multiple)&&(a.blocked=!1)}(e,t)})},{rootMargin:"0px",threshold:[0,.5]}),()=>{})()}function xe(e,t,n={multiple:!1}){var r;const o=e._visibilityState;(null==o?void 0:o.observer)&&t&&(o.elementConfigs||(o.elementConfigs=new WeakMap),o.elementConfigs.set(t,{multiple:null!=(r=n.multiple)&&r,blocked:!1}),o.observer.observe(t))}function Ee(e){const t=e._visibilityState;t&&(t.observer&&t.observer.disconnect(),delete e._visibilityState)}function Le(e,t,n,r,o,i,s){if(se(t)&&t.startsWith("walker ")){if("walker config"===t)return e.push("walker config",n);if("walker consent"===t)return e.push("walker consent",n);if("walker user"===t)return e.push("walker user",n);if("walker run"===t)return e.push("walker run",n)}if(ie(t)){const n=t;return n.source||(n.source=Ae()),e.push(n)}if(se(t)&&t.length>0){const a={event:t,data:$e(n||{}),context:Ce(o||{}),custom:s,nested:i,source:Ae()};return se(r)&&(a.trigger=r),e.push(a)}if(!function(e){return void 0!==e}(t))return Promise.resolve({ok:!0,successful:[],queued:[],failed:[]});const a={event:String(t||""),data:$e(n||{}),context:Ce(o||{}),custom:s,nested:i,source:Ae()};return se(r)&&(a.trigger=r),e.push(a)}function $e(e){return e&&"object"==typeof e?e:{}}function Ce(e){return e?(t=e)===document||t instanceof Element?{}:ie(e)&&Object.keys(e).length?e:{}:{};var t}function Ae(){return{type:"browser",id:window.location.href,previous_id:document.referrer}}var Pe=[],qe={Click:"click",Custom:"custom",Hover:"hover",Load:"load",Pulse:"pulse",Scroll:"scroll",Submit:"submit",Visible:"visible",Visibles:"visibles",Wait:"wait"};function Re(e,t){const{prefix:n,scope:r,pageview:o}=t;if(o){const[t,o]=function(e,t){const n=window.location,r="page",o=t===document?document.body:t,[i,s]=ye(o,`[${de(e,r)}]`,e,r);return i.domain=n.hostname,i.title=document.title,i.referrer=document.referrer,n.search&&(i.search=n.search),n.hash&&(i.hash=n.hash),[i,s]}(n,r);Le(e,"page view",t,qe.Load,o)}!function(e,t,n){Pe=[],Ee(e),function(e,t=1e3){e._visibilityState||(e._visibilityState={observer:Oe(e),timers:new WeakMap,duration:t})}(e,1e3);const r=de(t,U.Action,!1),o=n||document;o!==document&&Ne(e,o,r,t),o.querySelectorAll(`[${r}]`).forEach(n=>Ne(e,n,r,t)),Pe.length&&function(e,t){const n=(e,t)=>e.filter(([e,n])=>{const r=window.scrollY+window.innerHeight,o=e.offsetTop;if(r<o)return!0;const i=e.clientHeight;return!(100*(1-(o+i-r)/(i||1))>=n&&(Ie(t,e,qe.Scroll,"data-elb"),1))});ke||(ke=function(e,t=1e3){let n=null;return function(...r){if(null===n)return n=setTimeout(()=>{n=null},t),e(...r)}}(function(){Pe=n.call(t,Pe,e)}),t.addEventListener("scroll",ke))}(e,o)}(e,n,r)}function De(e,t){t.addEventListener("click",ue(function(t){We.call(this,e,t)})),t.addEventListener("submit",ue(function(t){Xe.call(this,e,t)}))}async function Ie(e,t,n,r){const o=function(e,t,n=U.Prefix){const r=[],o=function(e,t,n){let r=t;for(;r;){const t=ge(j(r,de(e,U.Action,!1)));if(t[n]||"click"!==n)return t[n];r=me(e,r)}return[]}(n,e,t);return o?(o.forEach(o=>{const i=he(o.actionParams||"",",").reduce((e,t)=>(e[le(t)]=!0,e),{}),s=function(e,t,n){const r=[];let o=t;for(n=0!==Object.keys(n||{}).length?n:void 0;o;){const i=pe(e,o,t,n);i&&r.push(i),o=me(e,o)}return r}(n,e,i);if(!s.length){const t="page",r=`[${de(n,t)}]`,[o,i]=ye(e,r,n,t);s.push({type:t,data:o,nested:[],context:i})}s.forEach(e=>{r.push({entity:e.type,action:o.action,data:e.data,trigger:t,context:e.context,nested:e.nested})})}),r):r}(t,n,r);return Promise.all(o.map(t=>Le(e,{event:`${t.entity} ${t.action}`,...t,trigger:n})))}function Ne(e,t,n,r){const o=j(t,n);o&&Object.values(ge(o)).forEach(n=>n.forEach(n=>{switch(n.trigger){case qe.Hover:o=e,i=r,t.addEventListener("mouseenter",ue(function(e){e.target instanceof Element&&Ie(o,e.target,qe.Hover,i)}));break;case qe.Load:!function(e,t,n){Ie(e,t,qe.Load,n)}(e,t,r);break;case qe.Pulse:!function(e,t,n="",r){setInterval(()=>{document.hidden||Ie(e,t,qe.Pulse,r)},parseInt(n||"")||15e3)}(e,t,n.triggerParams,r);break;case qe.Scroll:!function(e,t=""){const n=parseInt(t||"")||50;n<0||n>100||Pe.push([e,n])}(t,n.triggerParams);break;case qe.Visible:xe(e,t);break;case qe.Visibles:xe(e,t,{multiple:!0});break;case qe.Wait:!function(e,t,n="",r){setTimeout(()=>Ie(e,t,qe.Wait,r),parseInt(n||"")||15e3)}(e,t,n.triggerParams,r)}var o,i}))}function We(e,t){Ie(e,t.target,qe.Click,"data-elb")}function Xe(e,t){t.target&&Ie(e,t.target,qe.Submit,"data-elb")}function Me(e,t){null!=t&&""!==t&&"number"!=typeof t&&"string"!=typeof t&&ue(()=>{if(He(t)){const n=Array.from(t);if(n.length>=1){const[t,r,o,i]=n;"string"==typeof t&&t.length>0&&Le(e,t,r,o,i)}}else if("object"==typeof t&&null!==t){if(0===Object.keys(t).length)return;Le(e,t)}},()=>{})()}function He(e){return null!=e&&"object"==typeof e&&"length"in e&&"number"==typeof e.length}var Ue=async(e,t)=>{const n=function(e={}){const t=e.scope||document;return{prefix:"data-elb",pageview:!0,session:!0,elb:"elb",name:"walkerjs",elbLayer:"elbLayer",...e,scope:t}}(t.settings),r={...t,settings:n},o=n.scope,i={type:"browser",config:r,collector:e,destroy(){Ee(e)}};if(!1!==n.elbLayer&&function(e,t={}){const n=t.name||"elbLayer";window[n]||(window[n]=[]);const r=window[n];Array.isArray(r)&&r.length>0&&function(e,t){const n=[],r=[];t.forEach(e=>{!function(e){if(He(e)){const t=Array.from(e);return"string"==typeof t[0]&&t[0].startsWith("walker ")}return!1}(e)?r.push(e):n.push(e)}),n.forEach(t=>{Me(e,t)}),r.forEach(t=>{Me(e,t)}),t.length=0}(e,r)}(e,{name:se(n.elbLayer)?n.elbLayer:"elbLayer"}),De(e,o),n.session){const t="boolean"==typeof n.session?{}:n.session;!function(e,t={}){const n=t.config||{},r=re(e.config.sessionStatic||{},t.data||{});var o,i,s;(o=L,i="SessionStart",s=e.hooks,function(...e){let t;const n="post"+i,r=s["pre"+i],a=s[n];return t=r?r({fn:o},...e):o(...e),a&&(t=a({fn:o,result:t},...e)),t})({...n,cb:(e,t,r)=>{let o;const i=n;return!1!==i.cb&&i.cb?o=i.cb(e,t,r):!1!==i.cb&&(o=r(e,t,r)),t&&(t.session=e,T(t,"session")),o},data:r,collector:e})}(e,{config:t})}await async function(e,t,n){const r=()=>{e(t,n),T(t,"ready")};"loading"!==document.readyState?r():document.addEventListener("DOMContentLoaded",r)}(Re,e,n);const s=e._destroy;return e._destroy=()=>{var e;null==(e=i.destroy)||e.call(i),s&&s()},{source:i,elb:(...t)=>{const[n,r,o,i,s,a]=t;return Le(e,n,r,o,i,s,a)}}},Te=Object.defineProperty,Ge=(e,t)=>{for(var n in t)Te(e,n,{get:t[n],enumerable:!0})},Fe=!1;function Ke(e,t={},n){if(t.filter&&!0===h(()=>t.filter(n),()=>!1)())return;const r=u(o=n)&&l(o.event)?o:a(o)&&o.length>=2?Ve(o):null!=(i=o)&&"object"==typeof i&&"length"in i&&"number"==typeof i.length&&i.length>0?Ve(Array.from(o)):null;var o,i;if(!r)return;const s={event:`${t.prefix||"dataLayer"} ${r.event}`,data:r,context:{},globals:{},custom:{},consent:{},nested:[],user:{},id:Math.random().toString(36).substring(2,15),trigger:"",entity:"",action:"",timestamp:Date.now(),timing:0,group:"",count:0,version:{source:"1.0.0",tagging:2},source:{type:"dataLayer",id:"",previous_id:""}};h(()=>e.push(s),()=>{})()}function Ve(e){const[t,n,r]=e;if(!l(t))return null;let o,i={};switch(t){case"consent":if(!l(n)||e.length<3)return null;if(!u(r)||null===r)return null;o=`${t} ${n}`,i={...r};break;case"event":if(!l(n))return null;o=n,u(r)&&(i={...r});break;case"config":if(!l(n))return null;o=`${t} ${n}`,u(r)&&(i={...r});break;case"set":if(l(n))o=`${t} ${n}`,u(r)&&(i={...r});else{if(!u(n))return null;o=`${t} custom`,i={...n}}break;default:return null}return{event:o,...i}}function Be(){return["consent","update",{ad_user_data:"granted",ad_personalization:"granted",ad_storage:"denied",analytics_storage:"granted"}]}function Je(){return["consent","default",{ad_storage:"denied",analytics_storage:"denied",ad_user_data:"denied",ad_personalization:"denied"}]}function ze(){return["event","purchase",{transaction_id:"T_12345",value:25.42,currency:"EUR",items:[{item_id:"SKU_12345",item_name:"Product Name",item_category:"Category",quantity:1,price:25.42}]}]}function Ye(){return["event","add_to_cart",{currency:"EUR",value:15.25,items:[{item_id:"SKU_12345",item_name:"Product Name",item_variant:"red",quantity:1,price:15.25}]}]}function Qe(){return["event","view_item",{currency:"EUR",value:15.25,items:[{item_id:"SKU_12345",item_name:"Product Name",item_category:"Category",price:15.25}]}]}function Ze(){return["config","G-XXXXXXXXXX",{page_title:"Custom Page Title",page_location:"https://example.com/page",send_page_view:!1}]}function et(){return["set",{currency:"EUR",country:"DE"}]}function tt(){return{event:"custom_event",custom_parameter:"custom_value",user_id:"user123"}}Ge({},{add_to_cart:()=>Ye,config:()=>Ze,consentDefault:()=>Je,consentUpdate:()=>Be,directDataLayerEvent:()=>tt,purchase:()=>ze,setCustom:()=>et,view_item:()=>Qe});Ge({},{add_to_cart:()=>ot,config:()=>ct,configGA4:()=>st,consentOnlyMapping:()=>ut,consentUpdate:()=>nt,customEvent:()=>at,purchase:()=>rt,view_item:()=>it});var nt={name:"walker consent",settings:{command:{map:{functional:{value:!0},analytics:{key:"analytics_storage",fn:e=>"granted"===e},marketing:{key:"ad_storage",fn:e=>"granted"===e}}}}},rt={name:"order complete",data:{map:{id:"transaction_id",total:"value",currency:"currency",nested:{loop:["items",{map:{type:{value:"product"},data:{map:{id:"item_id",name:"item_name",category:"item_category",quantity:"quantity",price:"price"}}}}]}}}},ot={name:"product add",data:{map:{id:"items.0.item_id",name:"items.0.item_name",price:"value",currency:"currency",color:"items.0.item_variant",quantity:"items.0.quantity"}}},it={name:"product view",data:{map:{id:"items.0.item_id",name:"items.0.item_name",category:"items.0.item_category",price:"items.0.price",currency:"currency"}}},st={name:"page view",data:{map:{title:"page_title",url:"page_location"}}},at={data:{map:{user_id:"user_id",custom_parameter:"custom_parameter"}}},ct={consent:{update:nt},purchase:rt,add_to_cart:ot,view_item:it,"config G-XXXXXXXXXX":st,custom_event:at,"*":{data:{}}},ut={consent:{update:nt}},lt=(e,t)=>{const{settings:n}=t,r={type:"dataLayer",config:t,collector:e,destroy(){const e=n.name||"dataLayer";window[e]&&Array.isArray(window[e])}};return function(e,t){const n=t.settings,r=(null==n?void 0:n.name)||"dataLayer",o=window[r];if(Array.isArray(o)&&!Fe){Fe=!0;try{for(const t of o)Ke(e,n,t)}finally{Fe=!1}}}(e,t),function(e,t){const n=t.settings,r=(null==n?void 0:n.name)||"dataLayer";window[r]||(window[r]=[]);const o=window[r];if(!Array.isArray(o))return;const i=o.push.bind(o);o.push=function(...t){if(Fe)return i(...t);Fe=!0;try{for(const r of t)Ke(e,n,r)}finally{Fe=!1}return i(...t)}}(e,t),{source:r,elb:(...e)=>{const t=n.name||"dataLayer",r=window[t];return Array.isArray(r)?Promise.resolve(r.push(...e)):Promise.resolve(0)}}};function dt(e={}){const t=(t,n)=>{const r={...n,settings:{name:"dataLayer",prefix:"dataLayer",...e,...n.settings}};return lt(t,r)};return t.init=(e,t)=>lt(e,{type:"dataLayer",settings:t.settings}),t.settings={name:"dataLayer",prefix:"dataLayer",...e},t.type="dataLayer",t}function ft(){window.dataLayer=window.dataLayer||[];const e=e=>{u(e)&&u(e.source)&&String(e.source.type).includes("dataLayer")||window.dataLayer.push(e)};return{type:"dataLayer",config:{},push:(t,n)=>{e(n.data||t)},pushBatch:t=>{e({event:"batch",batched_event:t.key,events:t.data.length?t.data:t.events})}}}if(window&&document){const e=async()=>{let e;const t=document.querySelector("script[data-elbconfig]");if(t){const n=t.getAttribute("data-elbconfig")||"";n.includes(":")?e=O(n):n&&(e=window[n])}e||(e=window.elbConfig),e&&await async function(e={}){const t=s({collector:{destinations:{dataLayer:ft()}},browser:{run:!0,session:!0},dataLayer:!1,elb:"elb"},e),n={...t.collector,sources:{browser:{code:Ue,config:{settings:t.browser}}}};if(t.dataLayer){const e=u(t.dataLayer)?t.dataLayer:{};n.sources&&(n.sources.dataLayer={code:dt(e),config:{settings:e}})}const{collector:r}=await Z(n),o=r.sources.browser;if(!(null==o?void 0:o.elb))throw new Error("Failed to initialize browser source");const i={collector:r,elb:o.elb};return t.elb&&(window[t.elb]=o.elb),t.name&&(window[t.name]=r),i}(e)};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",e):e()}})();
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@walkeros/walker.js",
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"description": "Ready-to-use walkerOS bundle with browser source, collector, and dataLayer support",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"browser": "./dist/walker.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"browser": "./dist/walker.js",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.js",
|
|
16
|
+
"default": "./dist/walker.js"
|
|
17
|
+
},
|
|
18
|
+
"./es5": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.es5.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist/**",
|
|
25
|
+
"README.md",
|
|
26
|
+
"CHANGELOG.md"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"test": "jest --colors --coverage",
|
|
31
|
+
"dev": "jest --watchAll --colors",
|
|
32
|
+
"lint": "tsc && eslint \"**/*.ts*\"",
|
|
33
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf coverage",
|
|
34
|
+
"preview": "npm run build && npx serve -l 3333 examples"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@walkeros/core": "0.0.7",
|
|
38
|
+
"@walkeros/collector": "0.0.7",
|
|
39
|
+
"@walkeros/web-core": "0.0.7",
|
|
40
|
+
"@walkeros/web-source-browser": "0.0.7",
|
|
41
|
+
"@walkeros/web-source-dataLayer": "0.0.7"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@swc/jest": "^0.2.36",
|
|
45
|
+
"@types/jest": "^29.5.12",
|
|
46
|
+
"jest": "^29.7.0",
|
|
47
|
+
"jest-environment-jsdom": "^29.7.0"
|
|
48
|
+
},
|
|
49
|
+
"repository": {
|
|
50
|
+
"url": "git+https://github.com/elbwalker/walkerOS.git",
|
|
51
|
+
"directory": "apps/walkerjs"
|
|
52
|
+
},
|
|
53
|
+
"author": "elbwalker <hello@elbwalker.com>",
|
|
54
|
+
"homepage": "https://github.com/elbwalker/walkerOS#readme",
|
|
55
|
+
"bugs": {
|
|
56
|
+
"url": "https://github.com/elbwalker/walkerOS/issues"
|
|
57
|
+
},
|
|
58
|
+
"keywords": [
|
|
59
|
+
"walker",
|
|
60
|
+
"walkerOS",
|
|
61
|
+
"analytics",
|
|
62
|
+
"tracking",
|
|
63
|
+
"data collection",
|
|
64
|
+
"measurement",
|
|
65
|
+
"privacy friendly",
|
|
66
|
+
"web analytics",
|
|
67
|
+
"walker.js"
|
|
68
|
+
]
|
|
69
|
+
}
|