@blotoutio/edgetag-sdk-browser 1.29.0 → 1.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +209 -60
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
(function () {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var api
|
|
4
|
+
var api = /*#__PURE__*/Object.freeze({
|
|
5
5
|
__proto__: null,
|
|
6
6
|
get consent () { return consent; },
|
|
7
7
|
get data () { return data; },
|
|
@@ -510,12 +510,17 @@
|
|
|
510
510
|
};
|
|
511
511
|
|
|
512
512
|
// eslint-disable-next-line @nx/enforce-module-boundaries
|
|
513
|
-
|
|
513
|
+
const getGlobalSettings = () => {
|
|
514
|
+
var _a;
|
|
515
|
+
// settings must be globally shared in order for each tag to be able to
|
|
516
|
+
// process the correct destinations when receiving stubs/calls to process
|
|
517
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
518
|
+
// @ts-ignore extending globalThis is a pain, ignore.
|
|
519
|
+
return ((_a = globalThis.edgeTagSettings) !== null && _a !== void 0 ? _a : (globalThis.edgeTagSettings = {}));
|
|
520
|
+
};
|
|
514
521
|
const initSettings = (destination, options) => {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
}
|
|
518
|
-
edgeTagSettings[destination] = {
|
|
522
|
+
const settings = getGlobalSettings();
|
|
523
|
+
settings[destination] = {
|
|
519
524
|
destination,
|
|
520
525
|
initialized: false,
|
|
521
526
|
stubs: [],
|
|
@@ -532,29 +537,27 @@
|
|
|
532
537
|
};
|
|
533
538
|
};
|
|
534
539
|
const setSetting = (destination, options) => {
|
|
535
|
-
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
540
|
+
const settings = getGlobalSettings();
|
|
538
541
|
if (!destination) {
|
|
539
|
-
Object.keys(
|
|
540
|
-
|
|
541
|
-
...
|
|
542
|
+
Object.keys(settings).forEach((key) => {
|
|
543
|
+
settings[key] = {
|
|
544
|
+
...settings[key],
|
|
542
545
|
...options,
|
|
543
546
|
};
|
|
544
547
|
});
|
|
545
548
|
return;
|
|
546
549
|
}
|
|
547
|
-
|
|
548
|
-
...
|
|
550
|
+
settings[destination] = {
|
|
551
|
+
...settings[destination],
|
|
549
552
|
...options,
|
|
550
553
|
};
|
|
551
554
|
};
|
|
552
555
|
const getSetting = (destination, key) => {
|
|
553
556
|
var _a;
|
|
554
|
-
return (_a =
|
|
557
|
+
return (_a = getGlobalSettings()[destination]) === null || _a === void 0 ? void 0 : _a[key];
|
|
555
558
|
};
|
|
556
559
|
const getInstances = () => {
|
|
557
|
-
return Object.keys(
|
|
560
|
+
return Object.keys(getGlobalSettings());
|
|
558
561
|
};
|
|
559
562
|
const addChannel = (destination, pkg, tagName) => upsert(getSetting(destination, 'channels'), pkg, (names) => names.add(tagName), () => new Set());
|
|
560
563
|
const getProviderVariables = (destination, packageId) => {
|
|
@@ -953,7 +956,7 @@
|
|
|
953
956
|
referrer: getReferrer(destination),
|
|
954
957
|
search: getSearch(destination),
|
|
955
958
|
locale: getLocale(),
|
|
956
|
-
sdkVersion: "1.
|
|
959
|
+
sdkVersion: "1.30.1" ,
|
|
957
960
|
...(payload || {}),
|
|
958
961
|
};
|
|
959
962
|
let storage = {};
|
|
@@ -1059,7 +1062,7 @@
|
|
|
1059
1062
|
const stubs = getSetting(destination, 'stubs');
|
|
1060
1063
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1061
1064
|
// @ts-ignore
|
|
1062
|
-
stubs.forEach((stub) => api
|
|
1065
|
+
stubs.forEach((stub) => api[stub.name](...(stub.arguments || [])));
|
|
1063
1066
|
setSetting(destination, {
|
|
1064
1067
|
stubs: [],
|
|
1065
1068
|
});
|
|
@@ -2017,81 +2020,227 @@
|
|
|
2017
2020
|
}
|
|
2018
2021
|
}
|
|
2019
2022
|
|
|
2020
|
-
var
|
|
2023
|
+
var library = new API();
|
|
2021
2024
|
|
|
2022
2025
|
(function () {
|
|
2023
|
-
const
|
|
2026
|
+
const getTagDestination = (args) => {
|
|
2027
|
+
if (args?.length < 4) {
|
|
2028
|
+
return
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
return args[3].destination
|
|
2032
|
+
};
|
|
2033
|
+
|
|
2034
|
+
const getInitUrl = (args) => {
|
|
2035
|
+
if (args?.length < 1) {
|
|
2036
|
+
return
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
return args[0].edgeURL
|
|
2040
|
+
};
|
|
2041
|
+
|
|
2042
|
+
const addTagToDestination = (destination, tag) => {
|
|
2043
|
+
if (!window.edgetag.destinations[destination]) {
|
|
2044
|
+
window.edgetag.destinations[destination] = {};
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
if (!window.edgetag.destinations[destination].tags) {
|
|
2048
|
+
window.edgetag.destinations[destination].tags = [];
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
window.edgetag.destinations[destination].tags.push({
|
|
2052
|
+
name: 'tag',
|
|
2053
|
+
arguments: tag,
|
|
2054
|
+
});
|
|
2055
|
+
};
|
|
2056
|
+
|
|
2057
|
+
const handleInit = (args) => {
|
|
2058
|
+
if (!args?.length) {
|
|
2059
|
+
console.error('EdgeTag SDK: Init event is missing arguments');
|
|
2060
|
+
return
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
const destination = args[0]?.edgeURL;
|
|
2064
|
+
if (!destination) {
|
|
2065
|
+
console.error('EdgeTag SDK: edgeURL is required for initialization');
|
|
2066
|
+
return
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
if (!window.edgetag.destinations?.[destination]?.initialized) {
|
|
2070
|
+
window.edgetag.stubs.push(['init', ...args]);
|
|
2071
|
+
return
|
|
2072
|
+
}
|
|
2073
|
+
|
|
2074
|
+
const tags = [];
|
|
2075
|
+
|
|
2076
|
+
if (
|
|
2077
|
+
window.edgetag.destinations?.['all']?.tags &&
|
|
2078
|
+
!window.edgetag.destinations['all']?.resolvedInits?.has(destination)
|
|
2079
|
+
) {
|
|
2080
|
+
const destinationTags = window.edgetag.destinations['all'].tags.map(
|
|
2081
|
+
(tag) => {
|
|
2082
|
+
const newTag = structuredClone(tag);
|
|
2083
|
+
newTag['arguments'][3] = {
|
|
2084
|
+
...newTag['arguments'][3],
|
|
2085
|
+
destination,
|
|
2086
|
+
};
|
|
2087
|
+
|
|
2088
|
+
return newTag
|
|
2089
|
+
}
|
|
2090
|
+
);
|
|
2091
|
+
tags.push(...destinationTags);
|
|
2092
|
+
if (!window.edgetag.destinations['all'].resolvedInits) {
|
|
2093
|
+
window.edgetag.destinations['all'].resolvedInits = new Set();
|
|
2094
|
+
}
|
|
2095
|
+
window.edgetag.destinations['all'].resolvedInits.add(destination);
|
|
2096
|
+
}
|
|
2097
|
+
|
|
2098
|
+
if (window.edgetag.destinations[destination].tags) {
|
|
2099
|
+
tags.push(...window.edgetag.destinations[destination].tags);
|
|
2100
|
+
window.edgetag.destinations[destination].tags = [];
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
if (tags.length) {
|
|
2104
|
+
args[0]['afterManifestEvents'] = tags;
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
library.init(...args);
|
|
2108
|
+
};
|
|
2109
|
+
|
|
2110
|
+
const handleTag = (args) => {
|
|
2111
|
+
const destination = getTagDestination(args);
|
|
2112
|
+
|
|
2113
|
+
if (destination && !window.edgetag.destinations[destination]?.initialized) {
|
|
2114
|
+
addTagToDestination(destination, args);
|
|
2115
|
+
return
|
|
2116
|
+
}
|
|
2117
|
+
|
|
2118
|
+
library.tag(...args);
|
|
2119
|
+
};
|
|
2120
|
+
|
|
2121
|
+
const processStub = (name, args) => {
|
|
2024
2122
|
try {
|
|
2025
|
-
|
|
2123
|
+
if (name === 'init') {
|
|
2124
|
+
handleInit(args);
|
|
2125
|
+
return
|
|
2126
|
+
}
|
|
2127
|
+
|
|
2128
|
+
if (name === 'tag') {
|
|
2129
|
+
handleTag(args);
|
|
2130
|
+
return
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
return library[name](...args)
|
|
2026
2134
|
} catch (e) {
|
|
2027
2135
|
console.error(e);
|
|
2028
2136
|
}
|
|
2029
2137
|
};
|
|
2030
2138
|
|
|
2031
|
-
const
|
|
2032
|
-
|
|
2139
|
+
const handleEvent = (args) => {
|
|
2140
|
+
const sliced = [].slice.call(args);
|
|
2141
|
+
if (!Array.isArray(sliced) || !sliced.length) {
|
|
2142
|
+
return
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
return processStub(sliced[0], sliced.slice(1))
|
|
2146
|
+
};
|
|
2147
|
+
|
|
2148
|
+
let stubs = window.edgetag?.stubs;
|
|
2149
|
+
if (!stubs) {
|
|
2150
|
+
stubs = [];
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2033
2153
|
if (!window.edgetag?.live) {
|
|
2034
|
-
|
|
2154
|
+
const destinations = window.edgetag?.destinations;
|
|
2035
2155
|
|
|
2036
2156
|
// this needs to be regular function for arguments to work
|
|
2037
2157
|
window.edgetag = function () {
|
|
2038
|
-
|
|
2039
|
-
if (!Array.isArray(sliced)) {
|
|
2040
|
-
return
|
|
2041
|
-
}
|
|
2042
|
-
|
|
2043
|
-
try {
|
|
2044
|
-
return library[sliced[0]](...sliced.slice(1))
|
|
2045
|
-
} catch (e) {
|
|
2046
|
-
console.error(e);
|
|
2047
|
-
}
|
|
2158
|
+
return handleEvent(arguments)
|
|
2048
2159
|
};
|
|
2049
2160
|
|
|
2050
2161
|
window.edgetag.live = true;
|
|
2162
|
+
window.edgetag.destinations = destinations || {};
|
|
2051
2163
|
}
|
|
2052
2164
|
|
|
2053
|
-
|
|
2054
|
-
const afterManifestEvents = [];
|
|
2055
|
-
const initCalls = [];
|
|
2165
|
+
window.edgetag.stubs = [];
|
|
2056
2166
|
|
|
2057
|
-
|
|
2058
|
-
|
|
2167
|
+
window.edgetag.handleStubs = () => {
|
|
2168
|
+
if (!window.edgetag.stubs || !Array.isArray(window.edgetag.stubs)) {
|
|
2169
|
+
console.error('EdgeTag SDK: Invalid stubs array');
|
|
2170
|
+
return
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
stubs = window.edgetag.stubs;
|
|
2174
|
+
window.edgetag.stubs = [];
|
|
2175
|
+
|
|
2176
|
+
stubs.forEach((stub) => {
|
|
2177
|
+
handleEvent(stub);
|
|
2178
|
+
});
|
|
2179
|
+
};
|
|
2180
|
+
|
|
2181
|
+
if (!window.edgetag.destinations) {
|
|
2182
|
+
window.edgetag.destinations = {};
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
if (!stubs.length) {
|
|
2186
|
+
return
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
const inits = [];
|
|
2190
|
+
const tags = [];
|
|
2191
|
+
|
|
2192
|
+
stubs.forEach((stub) => {
|
|
2193
|
+
const sliced = [].slice.call(stub);
|
|
2059
2194
|
if (!Array.isArray(sliced)) {
|
|
2060
2195
|
return
|
|
2061
2196
|
}
|
|
2062
2197
|
|
|
2063
|
-
|
|
2064
|
-
|
|
2198
|
+
const name = sliced[0];
|
|
2199
|
+
const args = sliced.slice(1);
|
|
2200
|
+
|
|
2201
|
+
if (name === 'init') {
|
|
2202
|
+
const destination = getInitUrl(args);
|
|
2203
|
+
if (!window.edgetag.destinations[destination]) {
|
|
2204
|
+
window.edgetag.destinations[destination] = {
|
|
2205
|
+
tags: [],
|
|
2206
|
+
};
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
inits.push(args);
|
|
2065
2210
|
return
|
|
2066
2211
|
}
|
|
2067
2212
|
|
|
2068
|
-
if (
|
|
2069
|
-
|
|
2070
|
-
name: sliced[0],
|
|
2071
|
-
arguments: sliced.slice(1),
|
|
2072
|
-
});
|
|
2213
|
+
if (name === 'tag') {
|
|
2214
|
+
tags.push(args);
|
|
2073
2215
|
return
|
|
2074
2216
|
}
|
|
2075
2217
|
|
|
2076
|
-
|
|
2077
|
-
name: sliced[0],
|
|
2078
|
-
arguments: sliced.slice(1),
|
|
2079
|
-
});
|
|
2218
|
+
processStub(name, args);
|
|
2080
2219
|
});
|
|
2081
2220
|
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2221
|
+
tags.forEach((tag) => {
|
|
2222
|
+
const destination = getTagDestination(tag);
|
|
2223
|
+
if (destination) {
|
|
2224
|
+
addTagToDestination(destination, tag);
|
|
2225
|
+
return
|
|
2226
|
+
}
|
|
2085
2227
|
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
}
|
|
2228
|
+
if (!window.edgetag.destinations['all']) {
|
|
2229
|
+
window.edgetag.destinations['all'] = {
|
|
2230
|
+
tags: [],
|
|
2231
|
+
resolvedInits: new Set(),
|
|
2232
|
+
};
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
window.edgetag.destinations['all'].tags.push({
|
|
2236
|
+
name: 'tag',
|
|
2237
|
+
arguments: tag,
|
|
2091
2238
|
});
|
|
2092
|
-
}
|
|
2239
|
+
});
|
|
2093
2240
|
|
|
2094
|
-
|
|
2241
|
+
inits.forEach((init) => {
|
|
2242
|
+
window.edgetag.stubs.push(['init', ...init]);
|
|
2243
|
+
});
|
|
2095
2244
|
})();
|
|
2096
2245
|
|
|
2097
2246
|
})();
|