@snowplow/tracker-core
Advanced tools
Comparing version 3.0.0-alpha.4 to 3.0.0-beta.1
@@ -6,13 +6,17 @@ /** | ||
/** | ||
* An array of tuples which represented the unprocessed JSON to be added to the Payload | ||
* A tuple which represents the unprocessed JSON to be added to the Payload | ||
*/ | ||
type JsonForProcessing = Array<[ | ||
type EventJsonWithKeys = [ | ||
keyIfEncoded: string, | ||
keyIfNotEncoded: string, | ||
json: Record<string, unknown> | ||
]>; | ||
]; | ||
/** | ||
* An array of tuples which represents the unprocessed JSON to be added to the Payload | ||
*/ | ||
type EventJson = Array<EventJsonWithKeys>; | ||
/** | ||
* A function which will processor the Json onto the injected PayloadBuilder | ||
*/ | ||
type JsonProcessor = (payloadBuilder: PayloadBuilder, jsonForProcessing: JsonForProcessing) => void; | ||
type JsonProcessor = (payloadBuilder: PayloadBuilder, jsonForProcessing: EventJson) => void; | ||
/** | ||
@@ -41,2 +45,10 @@ * Interface for mutable object encapsulating tracker payload | ||
/** | ||
* Gets the current payload, before cached JSON is processed | ||
*/ | ||
getPayload: () => Payload; | ||
/** | ||
* Gets all JSON objects added to payload | ||
*/ | ||
getJson: () => EventJson; | ||
/** | ||
* Adds a function which will be executed when building | ||
@@ -49,3 +61,3 @@ * the payload to process the JSON which has been added to this payload | ||
* Builds and returns the Payload | ||
* @param base64Encode configures if cached json should be encoded | ||
* @param base64Encode configures if unprocessed, cached json should be encoded | ||
*/ | ||
@@ -72,2 +84,17 @@ build: () => Payload; | ||
declare function isJson(property?: Record<string, unknown>): boolean; | ||
declare enum LOG_LEVEL { | ||
none = 0, | ||
error = 1, | ||
warn = 2, | ||
debug = 3, | ||
info = 4 | ||
} | ||
interface Logger { | ||
setLogLevel: (level: LOG_LEVEL) => void; | ||
info: (message: string, ...extraParams: unknown[]) => void; | ||
debug: (message: string, ...extraParams: unknown[]) => void; | ||
warn: (message: string, error?: Error, ...extraParams: unknown[]) => void; | ||
error: (message: string, error?: Error, ...extraParams: unknown[]) => void; | ||
} | ||
declare const LOG: Logger; | ||
/** | ||
@@ -99,2 +126,7 @@ * Interface which defines Core Plugins | ||
contexts?: () => SelfDescribingJson[]; | ||
/** | ||
* Passed a logger instance which can be used to send log information | ||
* to the active logger | ||
*/ | ||
logger?: (logger: Logger) => void; | ||
} | ||
@@ -291,2 +323,6 @@ /** | ||
removeGlobalContexts(contexts: Array<ConditionalContextProvider | ContextPrimitive>): void; | ||
/** | ||
* Add a plugin into the plugin collection after Core has already been initialised | ||
* @param plugin The plugin to add | ||
*/ | ||
addPlugin(plugin: CorePlugin): void; | ||
@@ -1009,8 +1045,2 @@ } | ||
/** | ||
* Check if a variable to is a valid, non-empty Payload event by looking for the 'e' parameter of a Payload | ||
* @param input The variable to validate | ||
* @returns True if a valid Payload | ||
*/ | ||
declare function isEventJson(input: unknown): input is Payload; | ||
/** | ||
* Validates if the input object contains the expected properties of a ruleset | ||
@@ -1060,2 +1090,2 @@ * @param input The object containing a rule set | ||
declare function matchSchemaAgainstRule(rule: string, schema: string): boolean; | ||
export { ContextEvent, ContextGenerator, ContextFilter, ContextPrimitive, FilterProvider, RuleSet, RuleSetProvider, ConditionalContextProvider, DynamicContext, GlobalContexts, globalContexts, PluginContexts, pluginContexts, resolveDynamicContext, getSchemaParts, validateVendorParts, validateVendor, getRuleParts, isValidRule, isStringArray, isValidRuleSetArg, isSelfDescribingJson, isEventJson, isRuleSet, isContextCallbackFunction, isContextPrimitive, isFilterProvider, isRuleSetProvider, isConditionalContextProvider, matchSchemaAgainstRuleSet, matchSchemaAgainstRule, CorePlugin, Payload, JsonForProcessing, JsonProcessor, PayloadBuilder, payloadBuilder, payloadJsonProcessor, isNonEmptyJson, isJson, SelfDescribingJson, SelfDescribingJsonArray, Timestamp, TrueTimestamp, DeviceTimestamp, CommonEventProperties, TrackerCore, CoreConfiguration, trackerCore, SelfDescribingEvent, buildSelfDescribingEvent, PageViewEvent, buildPageView, PagePingEvent, buildPagePing, StructuredEvent, buildStructEvent, EcommerceTransactionEvent, buildEcommerceTransaction, EcommerceTransactionItemEvent, buildEcommerceTransactionItem, ScreenViewEvent, buildScreenView, LinkClickEvent, buildLinkClick, AdImpressionEvent, buildAdImpression, AdClickEvent, buildAdClick, AdConversionEvent, buildAdConversion, SocialInteractionEvent, buildSocialInteraction, AddToCartEvent, buildAddToCart, RemoveFromCartEvent, buildRemoveFromCart, FormFocusOrChangeEvent, buildFormFocusOrChange, FormElement, FormSubmissionEvent, buildFormSubmission, SiteSearchEvent, buildSiteSearch, ConsentWithdrawnEvent, buildConsentWithdrawn, ConsentGrantedEvent, buildConsentGranted }; | ||
export { ContextEvent, ContextGenerator, ContextFilter, ContextPrimitive, FilterProvider, RuleSet, RuleSetProvider, ConditionalContextProvider, DynamicContext, GlobalContexts, globalContexts, PluginContexts, pluginContexts, resolveDynamicContext, getSchemaParts, validateVendorParts, validateVendor, getRuleParts, isValidRule, isStringArray, isValidRuleSetArg, isSelfDescribingJson, isRuleSet, isContextCallbackFunction, isContextPrimitive, isFilterProvider, isRuleSetProvider, isConditionalContextProvider, matchSchemaAgainstRuleSet, matchSchemaAgainstRule, CorePlugin, Payload, EventJsonWithKeys, EventJson, JsonProcessor, PayloadBuilder, payloadBuilder, payloadJsonProcessor, isNonEmptyJson, isJson, SelfDescribingJson, SelfDescribingJsonArray, Timestamp, TrueTimestamp, DeviceTimestamp, CommonEventProperties, TrackerCore, CoreConfiguration, trackerCore, SelfDescribingEvent, buildSelfDescribingEvent, PageViewEvent, buildPageView, PagePingEvent, buildPagePing, StructuredEvent, buildStructEvent, EcommerceTransactionEvent, buildEcommerceTransaction, EcommerceTransactionItemEvent, buildEcommerceTransactionItem, ScreenViewEvent, buildScreenView, LinkClickEvent, buildLinkClick, AdImpressionEvent, buildAdImpression, AdClickEvent, buildAdClick, AdConversionEvent, buildAdConversion, SocialInteractionEvent, buildSocialInteraction, AddToCartEvent, buildAddToCart, RemoveFromCartEvent, buildRemoveFromCart, FormFocusOrChangeEvent, buildFormFocusOrChange, FormElement, FormSubmissionEvent, buildFormSubmission, SiteSearchEvent, buildSiteSearch, ConsentWithdrawnEvent, buildConsentWithdrawn, ConsentGrantedEvent, buildConsentGranted, LOG, LOG_LEVEL, Logger }; |
/*! | ||
* Core functionality for Snowplow JavaScript trackers v3.0.0-alpha.4 (http://bit.ly/sp-js) | ||
* Core functionality for Snowplow JavaScript trackers v3.0.0-beta.1 (http://bit.ly/sp-js) | ||
* Copyright 2021 Snowplow Analytics Ltd, 2010 Anthon Pang | ||
@@ -37,24 +37,2 @@ * Licensed under BSD-3-Clause | ||
/** | ||
* Decodes a url safe Base 64 encoded string | ||
* @remark See: {@link http://tools.ietf.org/html/rfc4648#page-7} | ||
* @param data String to decode | ||
* @returns The decoded string | ||
*/ | ||
function base64urldecode(data) { | ||
if (!data) { | ||
return data; | ||
} | ||
var padding = 4 - (data.length % 4); | ||
switch (padding) { | ||
case 2: | ||
data += '=='; | ||
break; | ||
case 3: | ||
data += '='; | ||
break; | ||
} | ||
var b64Data = data.replace(/-/g, '+').replace(/_/g, '/'); | ||
return base64decode(b64Data); | ||
} | ||
/** | ||
* Encodes a string into a url safe Base 64 encoded string | ||
@@ -118,67 +96,2 @@ * @remark See: {@link http://tools.ietf.org/html/rfc4648#page-7} | ||
} | ||
/** | ||
* Decode base64 to string | ||
* | ||
* @param data base64 to string | ||
* @returns decoded string | ||
*/ | ||
function base64decode(encodedData) { | ||
// discuss at: http://locutus.io/php/base64_decode/ | ||
// original by: Tyler Akins (http://rumkin.com) | ||
// improved by: Thunder.m | ||
// improved by: Kevin van Zonneveld (http://kvz.io) | ||
// improved by: Kevin van Zonneveld (http://kvz.io) | ||
// input by: Aman Gupta | ||
// input by: Brett Zamir (http://brett-zamir.me) | ||
// bugfixed by: Onno Marsman (https://twitter.com/onnomarsman) | ||
// bugfixed by: Pellentesque Malesuada | ||
// bugfixed by: Kevin van Zonneveld (http://kvz.io) | ||
// improved by: Indigo744 | ||
// example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==') | ||
// returns 1: 'Kevin van Zonneveld' | ||
// example 2: base64_decode('YQ==') | ||
// returns 2: 'a' | ||
// example 3: base64_decode('4pyTIMOgIGxhIG1vZGU=') | ||
// returns 3: '✓ à la mode' | ||
// decodeUTF8string() | ||
// Internal function to decode properly UTF8 string | ||
// Adapted from Solution #1 at https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding | ||
var decodeUTF8string = function (str) { | ||
// Going backwards: from bytestream, to percent-encoding, to original string. | ||
return decodeURIComponent(str | ||
.split('') | ||
.map(function (c) { | ||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); | ||
}) | ||
.join('')); | ||
}; | ||
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = ''; | ||
var tmpArr = []; | ||
if (!encodedData) { | ||
return encodedData; | ||
} | ||
encodedData += ''; | ||
do { | ||
// unpack four hexets into three octets using index points in b64 | ||
h1 = b64.indexOf(encodedData.charAt(i++)); | ||
h2 = b64.indexOf(encodedData.charAt(i++)); | ||
h3 = b64.indexOf(encodedData.charAt(i++)); | ||
h4 = b64.indexOf(encodedData.charAt(i++)); | ||
bits = (h1 << 18) | (h2 << 12) | (h3 << 6) | h4; | ||
o1 = (bits >> 16) & 0xff; | ||
o2 = (bits >> 8) & 0xff; | ||
o3 = bits & 0xff; | ||
if (h3 === 64) { | ||
tmpArr[ac++] = String.fromCharCode(o1); | ||
} | ||
else if (h4 === 64) { | ||
tmpArr[ac++] = String.fromCharCode(o1, o2); | ||
} | ||
else { | ||
tmpArr[ac++] = String.fromCharCode(o1, o2, o3); | ||
} | ||
} while (i < encodedData.length); | ||
dec = tmpArr.join(''); | ||
return decodeUTF8string(dec.replace(/\0+$/, '')); | ||
} | ||
@@ -215,3 +128,3 @@ /* | ||
function payloadBuilder() { | ||
var dict = {}, jsonForProcessing = []; | ||
var dict = {}, allJson = [], jsonForProcessing = []; | ||
var processor; | ||
@@ -233,3 +146,5 @@ var add = function (key, value) { | ||
if (json && isNonEmptyJson(json)) { | ||
jsonForProcessing.push([keyIfEncoded, keyIfNotEncoded, json]); | ||
var jsonWithKeys = [keyIfEncoded, keyIfNotEncoded, json]; | ||
jsonForProcessing.push(jsonWithKeys); | ||
allJson.push(jsonWithKeys); | ||
} | ||
@@ -241,2 +156,4 @@ }; | ||
addJson: addJson, | ||
getPayload: function () { return dict; }, | ||
getJson: function () { return allJson; }, | ||
withJsonProcessor: function (jsonProcessor) { | ||
@@ -326,2 +243,120 @@ processor = jsonProcessor; | ||
*/ | ||
var label = 'Snowplow: '; | ||
exports.LOG_LEVEL = void 0; | ||
(function (LOG_LEVEL) { | ||
LOG_LEVEL[LOG_LEVEL["none"] = 0] = "none"; | ||
LOG_LEVEL[LOG_LEVEL["error"] = 1] = "error"; | ||
LOG_LEVEL[LOG_LEVEL["warn"] = 2] = "warn"; | ||
LOG_LEVEL[LOG_LEVEL["debug"] = 3] = "debug"; | ||
LOG_LEVEL[LOG_LEVEL["info"] = 4] = "info"; | ||
})(exports.LOG_LEVEL || (exports.LOG_LEVEL = {})); | ||
var LOG = logger(); | ||
function logger(logLevel) { | ||
if (logLevel === void 0) { logLevel = exports.LOG_LEVEL.warn; } | ||
function setLogLevel(level) { | ||
if (exports.LOG_LEVEL[level]) { | ||
logLevel = level; | ||
} | ||
else { | ||
logLevel = exports.LOG_LEVEL.warn; | ||
} | ||
} | ||
/** | ||
* Log errors, with or without error object | ||
*/ | ||
function error(message, error) { | ||
var extraParams = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
extraParams[_i - 2] = arguments[_i]; | ||
} | ||
if (logLevel >= exports.LOG_LEVEL.error && typeof console !== 'undefined') { | ||
var logMsg = label + message + '\n'; | ||
if (error) { | ||
console.error.apply(console, tslib.__spreadArray([logMsg + '\n', error], extraParams)); | ||
} | ||
else { | ||
console.error.apply(console, tslib.__spreadArray([logMsg], extraParams)); | ||
} | ||
} | ||
} | ||
/** | ||
* Log warnings, with or without error object | ||
*/ | ||
function warn(message, error) { | ||
var extraParams = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
extraParams[_i - 2] = arguments[_i]; | ||
} | ||
if (logLevel >= exports.LOG_LEVEL.warn && typeof console !== 'undefined') { | ||
if (typeof console !== 'undefined') { | ||
var logMsg = label + message; | ||
if (error) { | ||
console.warn.apply(console, tslib.__spreadArray([logMsg + '\n', error], extraParams)); | ||
} | ||
else { | ||
console.warn.apply(console, tslib.__spreadArray([logMsg], extraParams)); | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* Log debug messages | ||
*/ | ||
function debug(message) { | ||
var extraParams = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
extraParams[_i - 1] = arguments[_i]; | ||
} | ||
if (logLevel >= exports.LOG_LEVEL.debug && typeof console !== 'undefined') { | ||
if (typeof console !== 'undefined') { | ||
console.warn.apply(console, tslib.__spreadArray([label + message], extraParams)); | ||
} | ||
} | ||
} | ||
/** | ||
* Log info messages | ||
*/ | ||
function info(message) { | ||
var extraParams = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
extraParams[_i - 1] = arguments[_i]; | ||
} | ||
if (logLevel >= exports.LOG_LEVEL.info && typeof console !== 'undefined') { | ||
if (typeof console !== 'undefined') { | ||
console.info.apply(console, tslib.__spreadArray([label + message], extraParams)); | ||
} | ||
} | ||
} | ||
return { setLogLevel: setLogLevel, warn: warn, error: error, debug: debug, info: info }; | ||
} | ||
/* | ||
* Copyright (c) 2021 Snowplow Analytics Ltd, 2010 Anthon Pang | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
/** | ||
@@ -389,10 +424,3 @@ * Contains helper functions to aid in the addition and removal of Global Contexts | ||
getApplicableContexts: function (event) { | ||
var builtEvent = event.build(); | ||
if (isEventJson(builtEvent)) { | ||
var decodedEvent = getDecodedEvent(builtEvent); | ||
return assembleAllContexts(decodedEvent); | ||
} | ||
else { | ||
return []; | ||
} | ||
return assembleAllContexts(event); | ||
} | ||
@@ -418,3 +446,3 @@ }; | ||
catch (ex) { | ||
console.warn('Snowplow: error with plugin context', ex); | ||
LOG.error('Error adding plugin contexts', ex); | ||
} | ||
@@ -567,13 +595,2 @@ }); | ||
/** | ||
* Check if a variable to is a valid, non-empty Payload event by looking for the 'e' parameter of a Payload | ||
* @param input The variable to validate | ||
* @returns True if a valid Payload | ||
*/ | ||
function isEventJson(input) { | ||
var payload = input; | ||
if (isNonEmptyJson(payload) && 'e' in payload) | ||
return typeof payload.e === 'string'; | ||
return false; | ||
} | ||
/** | ||
* Validates if the input object contains the expected properties of a ruleset | ||
@@ -740,31 +757,20 @@ * @param input The object containing a rule set | ||
// Returns the "useful" schema, i.e. what would someone want to use to identify events. | ||
// The idea being that you can determine the event type from 'e', so getting the schema from | ||
// 'ue_px.schema'/'ue_pr.schema' would be redundant - it'll return the unstruct_event schema. | ||
// Instead the schema nested inside the unstruct_event is more useful! | ||
// This doesn't decode ue_px, it works because it's called by code that has already decoded it | ||
// For some events this is the 'e' property but for unstructured events, this is the | ||
// 'schema' from the 'ue_px' field. | ||
function getUsefulSchema(sb) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; | ||
if (typeof ((_b = (_a = sb['ue_px']) === null || _a === void 0 ? void 0 : _a['data']) === null || _b === void 0 ? void 0 : _b['schema']) === 'string') | ||
return (_d = (_c = sb['ue_px']) === null || _c === void 0 ? void 0 : _c['data']) === null || _d === void 0 ? void 0 : _d['schema']; | ||
else if (typeof ((_f = (_e = sb['ue_pr']) === null || _e === void 0 ? void 0 : _e['data']) === null || _f === void 0 ? void 0 : _f['schema']) === 'string') | ||
return (_h = (_g = sb['ue_pr']) === null || _g === void 0 ? void 0 : _g['data']) === null || _h === void 0 ? void 0 : _h['schema']; | ||
else if (typeof ((_j = sb) === null || _j === void 0 ? void 0 : _j['schema']) === 'string') | ||
return (_k = sb) === null || _k === void 0 ? void 0 : _k['schema']; | ||
return ''; | ||
} | ||
function getDecodedEvent(sb) { | ||
var decodedEvent = tslib.__assign({}, sb); // spread operator, instantiates new object | ||
try { | ||
if (Object.prototype.hasOwnProperty.call(decodedEvent, 'ue_px')) { | ||
decodedEvent['ue_px'] = JSON.parse(base64urldecode(decodedEvent['ue_px'])); | ||
var eventJson = sb.getJson(); | ||
for (var _i = 0, eventJson_1 = eventJson; _i < eventJson_1.length; _i++) { | ||
var json = eventJson_1[_i]; | ||
if (json.length === 3 && json[0] === 'ue_px' && typeof json[2]['data'] === 'object') { | ||
var schema = json[2]['data']['schema']; | ||
if (typeof schema == 'string') { | ||
return schema; | ||
} | ||
} | ||
return decodedEvent; | ||
} | ||
catch (e) { | ||
return decodedEvent; | ||
} | ||
return ''; | ||
} | ||
function getEventType(sb) { | ||
var _a; | ||
return ((_a = sb === null || sb === void 0 ? void 0 : sb['e']) !== null && _a !== void 0 ? _a : ''); | ||
function getEventType(payloadBuilder) { | ||
var eventType = payloadBuilder.getPayload()['e']; | ||
return typeof eventType === 'string' ? eventType : ''; | ||
} | ||
@@ -776,3 +782,3 @@ function buildGenerator(generator, event, eventType, eventSchema) { | ||
var args = { | ||
event: event, | ||
event: event.getPayload(), | ||
eventType: eventType, | ||
@@ -838,3 +844,3 @@ eventSchema: eventSchema | ||
var args = { | ||
event: event, | ||
event: event.getPayload(), | ||
eventType: eventType, | ||
@@ -996,3 +1002,3 @@ eventSchema: eventSchema | ||
catch (ex) { | ||
console.warn('Snowplow: error with plugin beforeTrack', ex); | ||
LOG.error('Plugin beforeTrack', ex); | ||
} | ||
@@ -1011,3 +1017,3 @@ }); | ||
catch (ex) { | ||
console.warn('Snowplow: error with plugin ', ex); | ||
LOG.error('Plugin afterTrack', ex); | ||
} | ||
@@ -1099,4 +1105,5 @@ }); | ||
plugins === null || plugins === void 0 ? void 0 : plugins.forEach(function (plugin) { | ||
var _a; | ||
(_a = plugin.activateCorePlugin) === null || _a === void 0 ? void 0 : _a.call(plugin, core); | ||
var _a, _b; | ||
(_a = plugin.logger) === null || _a === void 0 ? void 0 : _a.call(plugin, LOG); | ||
(_b = plugin.activateCorePlugin) === null || _b === void 0 ? void 0 : _b.call(plugin, core); | ||
}); | ||
@@ -1534,2 +1541,3 @@ return core; | ||
exports.LOG = LOG; | ||
exports.buildAdClick = buildAdClick; | ||
@@ -1560,3 +1568,2 @@ exports.buildAdConversion = buildAdConversion; | ||
exports.isContextPrimitive = isContextPrimitive; | ||
exports.isEventJson = isEventJson; | ||
exports.isFilterProvider = isFilterProvider; | ||
@@ -1563,0 +1570,0 @@ exports.isJson = isJson; |
@@ -6,13 +6,17 @@ /** | ||
/** | ||
* An array of tuples which represented the unprocessed JSON to be added to the Payload | ||
* A tuple which represents the unprocessed JSON to be added to the Payload | ||
*/ | ||
type JsonForProcessing = Array<[ | ||
type EventJsonWithKeys = [ | ||
keyIfEncoded: string, | ||
keyIfNotEncoded: string, | ||
json: Record<string, unknown> | ||
]>; | ||
]; | ||
/** | ||
* An array of tuples which represents the unprocessed JSON to be added to the Payload | ||
*/ | ||
type EventJson = Array<EventJsonWithKeys>; | ||
/** | ||
* A function which will processor the Json onto the injected PayloadBuilder | ||
*/ | ||
type JsonProcessor = (payloadBuilder: PayloadBuilder, jsonForProcessing: JsonForProcessing) => void; | ||
type JsonProcessor = (payloadBuilder: PayloadBuilder, jsonForProcessing: EventJson) => void; | ||
/** | ||
@@ -41,2 +45,10 @@ * Interface for mutable object encapsulating tracker payload | ||
/** | ||
* Gets the current payload, before cached JSON is processed | ||
*/ | ||
getPayload: () => Payload; | ||
/** | ||
* Gets all JSON objects added to payload | ||
*/ | ||
getJson: () => EventJson; | ||
/** | ||
* Adds a function which will be executed when building | ||
@@ -49,3 +61,3 @@ * the payload to process the JSON which has been added to this payload | ||
* Builds and returns the Payload | ||
* @param base64Encode configures if cached json should be encoded | ||
* @param base64Encode configures if unprocessed, cached json should be encoded | ||
*/ | ||
@@ -72,2 +84,17 @@ build: () => Payload; | ||
declare function isJson(property?: Record<string, unknown>): boolean; | ||
declare enum LOG_LEVEL { | ||
none = 0, | ||
error = 1, | ||
warn = 2, | ||
debug = 3, | ||
info = 4 | ||
} | ||
interface Logger { | ||
setLogLevel: (level: LOG_LEVEL) => void; | ||
info: (message: string, ...extraParams: unknown[]) => void; | ||
debug: (message: string, ...extraParams: unknown[]) => void; | ||
warn: (message: string, error?: Error, ...extraParams: unknown[]) => void; | ||
error: (message: string, error?: Error, ...extraParams: unknown[]) => void; | ||
} | ||
declare const LOG: Logger; | ||
/** | ||
@@ -99,2 +126,7 @@ * Interface which defines Core Plugins | ||
contexts?: () => SelfDescribingJson[]; | ||
/** | ||
* Passed a logger instance which can be used to send log information | ||
* to the active logger | ||
*/ | ||
logger?: (logger: Logger) => void; | ||
} | ||
@@ -291,2 +323,6 @@ /** | ||
removeGlobalContexts(contexts: Array<ConditionalContextProvider | ContextPrimitive>): void; | ||
/** | ||
* Add a plugin into the plugin collection after Core has already been initialised | ||
* @param plugin The plugin to add | ||
*/ | ||
addPlugin(plugin: CorePlugin): void; | ||
@@ -1009,8 +1045,2 @@ } | ||
/** | ||
* Check if a variable to is a valid, non-empty Payload event by looking for the 'e' parameter of a Payload | ||
* @param input The variable to validate | ||
* @returns True if a valid Payload | ||
*/ | ||
declare function isEventJson(input: unknown): input is Payload; | ||
/** | ||
* Validates if the input object contains the expected properties of a ruleset | ||
@@ -1060,2 +1090,2 @@ * @param input The object containing a rule set | ||
declare function matchSchemaAgainstRule(rule: string, schema: string): boolean; | ||
export { ContextEvent, ContextGenerator, ContextFilter, ContextPrimitive, FilterProvider, RuleSet, RuleSetProvider, ConditionalContextProvider, DynamicContext, GlobalContexts, globalContexts, PluginContexts, pluginContexts, resolveDynamicContext, getSchemaParts, validateVendorParts, validateVendor, getRuleParts, isValidRule, isStringArray, isValidRuleSetArg, isSelfDescribingJson, isEventJson, isRuleSet, isContextCallbackFunction, isContextPrimitive, isFilterProvider, isRuleSetProvider, isConditionalContextProvider, matchSchemaAgainstRuleSet, matchSchemaAgainstRule, CorePlugin, Payload, JsonForProcessing, JsonProcessor, PayloadBuilder, payloadBuilder, payloadJsonProcessor, isNonEmptyJson, isJson, SelfDescribingJson, SelfDescribingJsonArray, Timestamp, TrueTimestamp, DeviceTimestamp, CommonEventProperties, TrackerCore, CoreConfiguration, trackerCore, SelfDescribingEvent, buildSelfDescribingEvent, PageViewEvent, buildPageView, PagePingEvent, buildPagePing, StructuredEvent, buildStructEvent, EcommerceTransactionEvent, buildEcommerceTransaction, EcommerceTransactionItemEvent, buildEcommerceTransactionItem, ScreenViewEvent, buildScreenView, LinkClickEvent, buildLinkClick, AdImpressionEvent, buildAdImpression, AdClickEvent, buildAdClick, AdConversionEvent, buildAdConversion, SocialInteractionEvent, buildSocialInteraction, AddToCartEvent, buildAddToCart, RemoveFromCartEvent, buildRemoveFromCart, FormFocusOrChangeEvent, buildFormFocusOrChange, FormElement, FormSubmissionEvent, buildFormSubmission, SiteSearchEvent, buildSiteSearch, ConsentWithdrawnEvent, buildConsentWithdrawn, ConsentGrantedEvent, buildConsentGranted }; | ||
export { ContextEvent, ContextGenerator, ContextFilter, ContextPrimitive, FilterProvider, RuleSet, RuleSetProvider, ConditionalContextProvider, DynamicContext, GlobalContexts, globalContexts, PluginContexts, pluginContexts, resolveDynamicContext, getSchemaParts, validateVendorParts, validateVendor, getRuleParts, isValidRule, isStringArray, isValidRuleSetArg, isSelfDescribingJson, isRuleSet, isContextCallbackFunction, isContextPrimitive, isFilterProvider, isRuleSetProvider, isConditionalContextProvider, matchSchemaAgainstRuleSet, matchSchemaAgainstRule, CorePlugin, Payload, EventJsonWithKeys, EventJson, JsonProcessor, PayloadBuilder, payloadBuilder, payloadJsonProcessor, isNonEmptyJson, isJson, SelfDescribingJson, SelfDescribingJsonArray, Timestamp, TrueTimestamp, DeviceTimestamp, CommonEventProperties, TrackerCore, CoreConfiguration, trackerCore, SelfDescribingEvent, buildSelfDescribingEvent, PageViewEvent, buildPageView, PagePingEvent, buildPagePing, StructuredEvent, buildStructEvent, EcommerceTransactionEvent, buildEcommerceTransaction, EcommerceTransactionItemEvent, buildEcommerceTransactionItem, ScreenViewEvent, buildScreenView, LinkClickEvent, buildLinkClick, AdImpressionEvent, buildAdImpression, AdClickEvent, buildAdClick, AdConversionEvent, buildAdConversion, SocialInteractionEvent, buildSocialInteraction, AddToCartEvent, buildAddToCart, RemoveFromCartEvent, buildRemoveFromCart, FormFocusOrChangeEvent, buildFormFocusOrChange, FormElement, FormSubmissionEvent, buildFormSubmission, SiteSearchEvent, buildSiteSearch, ConsentWithdrawnEvent, buildConsentWithdrawn, ConsentGrantedEvent, buildConsentGranted, LOG, LOG_LEVEL, Logger }; |
/*! | ||
* Core functionality for Snowplow JavaScript trackers v3.0.0-alpha.4 (http://bit.ly/sp-js) | ||
* Core functionality for Snowplow JavaScript trackers v3.0.0-beta.1 (http://bit.ly/sp-js) | ||
* Copyright 2021 Snowplow Analytics Ltd, 2010 Anthon Pang | ||
@@ -7,3 +7,3 @@ * Licensed under BSD-3-Clause | ||
"use strict";!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).snowplowTrackerCore={})}(this,(function(e){function n(e){if(!e)return e;switch(4-e.length%4){case 2:e+="==";break;case 3:e+="="}return function(e){var n=0,t=0,r="",o=[];if(!e)return e;e+="";do{var a=N.indexOf(e.charAt(n++)),i=N.indexOf(e.charAt(n++));r=N.indexOf(e.charAt(n++));var c=N.indexOf(e.charAt(n++)),s=a<<18|i<<12|r<<6|c;a=s>>16&255,i=s>>8&255,s&=255,o[t++]=64===r?String.fromCharCode(a):64===c?String.fromCharCode(a,i):String.fromCharCode(a,i,s)}while(n<e.length);return function(e){return decodeURIComponent(e.split("").map((function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})).join(""))}((r=o.join("")).replace(/\0+$/,""))}(e=e.replace(/-/g,"+").replace(/_/g,"/"))}function t(e){if(!e)return e;var n=0,t=0,r=[];if(e){e=unescape(encodeURIComponent(e));do{var o=e.charCodeAt(n++),a=e.charCodeAt(n++),i=e.charCodeAt(n++),c=o<<16|a<<8|i;o=c>>18&63,a=c>>12&63,i=c>>6&63,c&=63,r[t++]=N.charAt(o)+N.charAt(a)+N.charAt(i)+N.charAt(c)}while(n<e.length);n=r.join(""),e=((e=e.length%3)?n.slice(0,e-3):n)+"===".slice(e||3)}return e.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function r(){var e,n={},t=[],r=function(e,t){null!=t&&""!==t&&(n[e]=t)};return{add:r,addDict:function(e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r(n,e[n])},addJson:function(e,n,r){r&&a(r)&&t.push([e,n,r])},withJsonProcessor:function(n){e=n},build:function(){return null==e||e(this,t),n}}}function o(e){return function(n,r){for(var o=0;o<r.length;o++){var a=r[o],i=JSON.stringify(a[2]);e?n.add(a[0],t(i)):n.add(a[1],i)}r.length=0}}function a(e){if(!i(e))return!1;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n))return!0;return!1}function i(e){return null!=e&&(e.constructor==={}.constructor||e.constructor===[].constructor)}function c(){var e=[],t=[];return{getGlobalPrimitives:function(){return e},getConditionalProviders:function(){return t},addGlobalContexts:function(n){for(var r=[],o=[],a=0;a<n.length;a++){var i=n[a];x(i)?r.push(i):b(i)&&o.push(i)}e=e.concat(o),t=t.concat(r)},clearGlobalContexts:function(){t=[],e=[]},removeGlobalContexts:function(n){for(var r=function(n){x(n)?t=t.filter((function(e){return JSON.stringify(e)===JSON.stringify(n)})):b(n)&&(e=e.filter((function(e){return JSON.stringify(e)===JSON.stringify(n)})))},o=0;o<n.length;o++)r(n[o])},getApplicableContexts:function(r){if(g(r=r.build())){r=T({},r);try{Object.prototype.hasOwnProperty.call(r,"ue_px")&&(r.ue_px=JSON.parse(n(r.ue_px)));var o=r}catch(e){o=r}var a,i,c,s,l,u,d,f,p;return r="string"==typeof(null===(i=null===(a=o.ue_px)||void 0===a?void 0:a.data)||void 0===i?void 0:i.schema)?null===(s=null===(c=o.ue_px)||void 0===c?void 0:c.data)||void 0===s?void 0:s.schema:"string"==typeof(null===(u=null===(l=o.ue_pr)||void 0===l?void 0:l.data)||void 0===u?void 0:u.schema)?null===(f=null===(d=o.ue_pr)||void 0===d?void 0:d.data)||void 0===f?void 0:f.schema:"string"==typeof(null==o?void 0:o.schema)?null==o?void 0:o.schema:"",a=null!==(p=null==o?void 0:o.e)&&void 0!==p?p:"",p=[],i=S(e,o,a,r),p.push.apply(p,i),a=function(e,n,t,r){var o;return e=P(e).map((function(e){e:{if(_(e)){var o=e[0],a=!1;try{a=o({event:n,eventType:t,eventSchema:r})}catch(e){a=!1}if(!0===a){e=S(e[1],n,t,r);break e}}else if(C(e)&&A(e[0],r)){e=S(e[1],n,t,r);break e}e=[]}if(e&&0!==e.length)return e})),(o=[]).concat.apply(o,e.filter((function(e){return null!=e&&e.filter(Boolean)})))}(t,o,a,r),p.push.apply(p,a),p}return[]}}}function s(e){return{addPluginContexts:function(n){var t=null!=n?n:[];return e.forEach((function(e){try{e.contexts&&t.push.apply(t,e.contexts())}catch(e){console.warn("Snowplow: error with plugin context",e)}})),t}}}function l(e){if(null!==(e=/^iglu:([a-zA-Z0-9-_.]+)\/([a-zA-Z0-9-_]+)\/jsonschema\/([1-9][0-9]*)-(0|[1-9][0-9]*)-(0|[1-9][0-9]*)$/.exec(e)))return e.slice(1,6)}function u(e){if("*"===e[0]||"*"===e[1])return!1;if(0<e.slice(2).length){var n=!1,t=0;for(e=e.slice(2);t<e.length;t++)if("*"===e[t])n=!0;else if(n)return!1;return!0}return 2==e.length}function d(e){return!!((e=e.split("."))&&1<e.length)&&u(e)}function f(e){if(null!==(e=/^iglu:((?:(?:[a-zA-Z0-9-_]+|\*).)+(?:[a-zA-Z0-9-_]+|\*))\/([a-zA-Z0-9-_.]+|\*)\/jsonschema\/([1-9][0-9]*|\*)-(0|[1-9][0-9]*|\*)-(0|[1-9][0-9]*|\*)$/.exec(e))&&d(e[1]))return e.slice(1,6)}function p(e){if(e=f(e)){var n=e[0];return 5===e.length&&d(n)}return!1}function m(e){return Array.isArray(e)&&e.every((function(e){return"string"==typeof e}))}function v(e){return m(e)?e.every((function(e){return p(e)})):"string"==typeof e&&p(e)}function y(e){return!!(a(e)&&"schema"in e&&"data"in e)&&("string"==typeof e.schema&&"object"==typeof e.data)}function g(e){return!(!a(e)||!("e"in e))&&"string"==typeof e.e}function h(e){var n=0;if(null!=e&&"object"==typeof e&&!Array.isArray(e)){if(Object.prototype.hasOwnProperty.call(e,"accept")){if(!v(e.accept))return!1;n+=1}if(Object.prototype.hasOwnProperty.call(e,"reject")){if(!v(e.reject))return!1;n+=1}return 0<n&&2>=n}return!1}function w(e){return"function"==typeof e&&1>=e.length}function b(e){return w(e)||y(e)}function _(e){return!(!Array.isArray(e)||2!==e.length)&&(Array.isArray(e[1])?w(e[0])&&e[1].every(b):w(e[0])&&b(e[1]))}function C(e){return!(!Array.isArray(e)||2!==e.length)&&(!!h(e[0])&&(Array.isArray(e[1])?e[1].every(b):b(e[1])))}function x(e){return _(e)||C(e)}function A(e,n){var t=0,r=0,o=e.accept;return Array.isArray(o)?e.accept.some((function(e){return I(e,n)}))&&r++:"string"==typeof o&&I(o,n)&&r++,o=e.reject,Array.isArray(o)?e.reject.some((function(e){return I(e,n)}))&&t++:"string"==typeof o&&I(o,n)&&t++,0<r&&0===t}function I(e,n){if(!p(e))return!1;if(e=f(e),n=l(n),e&&n){if(!function(e,n){if(n=n.split("."),e=e.split("."),n&&e){if(n.length!==e.length)return!1;for(var t=0;t<e.length;t++)if(!j(n[t],e[t]))return!1;return!0}return!1}(e[0],n[0]))return!1;for(var t=1;5>t;t++)if(!j(e[t],n[t]))return!1;return!0}return!1}function j(e,n){return e&&n&&"*"===e||e===n}function P(e){return Array.isArray(e)?e:[e]}function S(e,n,t,r){var o;return e=P(e).map((function(e){e:if(y(e))e=[e];else{if(w(e)){n:{var o=void 0;try{if(o=e({event:n,eventType:t,eventSchema:r}),Array.isArray(o)&&o.every(y)||y(o)){var a=o;break n}a=void 0;break n}catch(e){}a=void 0}if(y(a)){e=[a];break e}if(Array.isArray(a)){e=a;break e}}e=void 0}if(e&&0!==e.length)return e})),(o=[]).concat.apply(o,e.filter((function(e){return null!=e&&e.filter(Boolean)})))}function k(e){var n=e.event;return e={schema:"iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0",data:{schema:e=n.schema,data:n.data}},(n=r()).add("e","ue"),n.addJson("ue_px","ue_pr",e),n}function O(e,n){void 0===n&&(n={});var t,r={};for(t in e)(n[t]||null!==e[t]&&void 0!==e[t])&&(r[t]=e[t]);return r}for(var T=function(){return(T=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e}).apply(this,arguments)},N="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",R=(E=void 0,function(e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var t=new Uint8Array(16);e.exports=function(){return n(t),t}}else{var r=Array(16);e.exports=function(){for(var e,n=0;16>n;n++)0==(3&n)&&(e=4294967296*Math.random()),r[n]=e>>>((3&n)<<3)&255;return r}}}(E={exports:{}}),E.exports),J=[],V=0;256>V;++V)J[V]=(V+256).toString(16).substr(1);var E,U,z,G=function(e,n){return n=n||0,[J[e[n++]],J[e[n++]],J[e[n++]],J[e[n++]],"-",J[e[n++]],J[e[n++]],"-",J[e[n++]],J[e[n++]],"-",J[e[n++]],J[e[n++]],"-",J[e[n++]],J[e[n++]],J[e[n++]],J[e[n++]],J[e[n++]],J[e[n++]]].join("")},D=0,q=0,M=function(e,n,t){if(t=n&&t||0,"string"==typeof e&&(n="binary"===e?Array(16):null,e=null),(e=(e=e||{}).random||(e.rng||R)())[6]=15&e[6]|64,e[8]=63&e[8]|128,n)for(var r=0;16>r;++r)n[t+r]=e[r];return n||G(e)};M.v1=function(e,n,t){t=n&&t||0;var r=n||[],o=(e=e||{}).node||U,a=void 0!==e.clockseq?e.clockseq:z;if(null==o||null==a){var i=R();null==o&&(o=U=[1|i[0],i[1],i[2],i[3],i[4],i[5]]),null==a&&(a=z=16383&(i[6]<<8|i[7]))}i=void 0!==e.msecs?e.msecs:(new Date).getTime();var c=void 0!==e.nsecs?e.nsecs:q+1,s=i-D+(c-q)/1e4;if(0>s&&void 0===e.clockseq&&(a=a+1&16383),(0>s||i>D)&&void 0===e.nsecs&&(c=0),1e4<=c)throw Error("uuid.v1(): Can't create more than 10M uuids/sec");for(D=i,q=c,z=a,e=(1e4*(268435455&(i+=122192928e5))+c)%4294967296,r[t++]=e>>>24&255,r[t++]=e>>>16&255,r[t++]=e>>>8&255,r[t++]=255&e,e=i/4294967296*1e4&268435455,r[t++]=e>>>8&255,r[t++]=255&e,r[t++]=e>>>24&15|16,r[t++]=e>>>16&255,r[t++]=a>>>8|128,r[t++]=255&a,a=0;6>a;++a)r[t+a]=o[a];return n||G(r)},M.v4=M,e.buildAdClick=function(e){return k({event:e={schema:"iglu:com.snowplowanalytics.snowplow/ad_click/jsonschema/1-0-0",data:O({targetUrl:e.targetUrl,clickId:e.clickId,costModel:e.costModel,cost:e.cost,bannerId:e.bannerId,zoneId:e.zoneId,impressionId:e.impressionId,advertiserId:e.advertiserId,campaignId:e.campaignId})}})},e.buildAdConversion=function(e){return k({event:e={schema:"iglu:com.snowplowanalytics.snowplow/ad_conversion/jsonschema/1-0-0",data:O({conversionId:e.conversionId,costModel:e.costModel,cost:e.cost,category:e.category,action:e.action,property:e.property,initialValue:e.initialValue,advertiserId:e.advertiserId,campaignId:e.campaignId})}})},e.buildAdImpression=function(e){return k({event:e={schema:"iglu:com.snowplowanalytics.snowplow/ad_impression/jsonschema/1-0-0",data:O({impressionId:e.impressionId,costModel:e.costModel,cost:e.cost,targetUrl:e.targetUrl,bannerId:e.bannerId,zoneId:e.zoneId,advertiserId:e.advertiserId,campaignId:e.campaignId})}})},e.buildAddToCart=function(e){return k({event:{schema:"iglu:com.snowplowanalytics.snowplow/add_to_cart/jsonschema/1-0-0",data:O({sku:e.sku,quantity:e.quantity,name:e.name,category:e.category,unitPrice:e.unitPrice,currency:e.currency})}})},e.buildConsentGranted=function(e){var n=e.expiry;return e={schema:"iglu:com.snowplowanalytics.snowplow/consent_document/jsonschema/1-0-0",data:O({id:e.id,version:e.version,name:e.name,description:e.description})},{event:k({event:{schema:"iglu:com.snowplowanalytics.snowplow/consent_granted/jsonschema/1-0-0",data:O({expiry:n})}}),context:[e]}},e.buildConsentWithdrawn=function(e){var n=e.all;return e={schema:"iglu:com.snowplowanalytics.snowplow/consent_document/jsonschema/1-0-0",data:O({id:e.id,version:e.version,name:e.name,description:e.description})},{event:k({event:{schema:"iglu:com.snowplowanalytics.snowplow/consent_withdrawn/jsonschema/1-0-0",data:O({all:n})}}),context:[e]}},e.buildEcommerceTransaction=function(e){var n=e.orderId,t=e.total,o=e.affiliation,a=e.tax,i=e.shipping,c=e.city,s=e.state,l=e.country;e=e.currency;var u=r();return u.add("e","tr"),u.add("tr_id",n),u.add("tr_af",o),u.add("tr_tt",t),u.add("tr_tx",a),u.add("tr_sh",i),u.add("tr_ci",c),u.add("tr_st",s),u.add("tr_co",l),u.add("tr_cu",e),u},e.buildEcommerceTransactionItem=function(e){var n=e.orderId,t=e.sku,o=e.price,a=e.name,i=e.category,c=e.quantity;e=e.currency;var s=r();return s.add("e","ti"),s.add("ti_id",n),s.add("ti_sk",t),s.add("ti_nm",a),s.add("ti_ca",i),s.add("ti_pr",o),s.add("ti_qu",c),s.add("ti_cu",e),s},e.buildFormFocusOrChange=function(e){var n="",t=e.schema,r=e.type;return e={formId:e.formId,elementId:e.elementId,nodeName:e.nodeName,elementClasses:e.elementClasses,value:e.value},"change_form"===t?(n="iglu:com.snowplowanalytics.snowplow/change_form/jsonschema/1-0-0",e.type=r):"focus_form"===t&&(n="iglu:com.snowplowanalytics.snowplow/focus_form/jsonschema/1-0-0",e.elementType=r),k({event:{schema:n,data:O(e,{value:!0})}})},e.buildFormSubmission=function(e){return k({event:{schema:"iglu:com.snowplowanalytics.snowplow/submit_form/jsonschema/1-0-0",data:O({formId:e.formId,formClasses:e.formClasses,elements:e.elements})}})},e.buildLinkClick=function(e){return k({event:e={schema:"iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1",data:O({targetUrl:e.targetUrl,elementId:e.elementId,elementClasses:e.elementClasses,elementTarget:e.elementTarget,elementContent:e.elementContent})}})},e.buildPagePing=function(e){var n=e.pageUrl,t=e.pageTitle,o=e.referrer,a=e.minXOffset,i=e.maxXOffset,c=e.minYOffset;e=e.maxYOffset;var s=r();return s.add("e","pp"),s.add("url",n),s.add("page",t),s.add("refr",o),a&&!isNaN(Number(a))&&s.add("pp_mix",a.toString()),i&&!isNaN(Number(i))&&s.add("pp_max",i.toString()),c&&!isNaN(Number(c))&&s.add("pp_miy",c.toString()),e&&!isNaN(Number(e))&&s.add("pp_may",e.toString()),s},e.buildPageView=function(e){var n=e.pageUrl,t=e.pageTitle;e=e.referrer;var o=r();return o.add("e","pv"),o.add("url",n),o.add("page",t),o.add("refr",e),o},e.buildRemoveFromCart=function(e){return k({event:{schema:"iglu:com.snowplowanalytics.snowplow/remove_from_cart/jsonschema/1-0-0",data:O({sku:e.sku,quantity:e.quantity,name:e.name,category:e.category,unitPrice:e.unitPrice,currency:e.currency})}})},e.buildScreenView=function(e){return k({event:{schema:"iglu:com.snowplowanalytics.snowplow/screen_view/jsonschema/1-0-0",data:O({name:e.name,id:e.id})}})},e.buildSelfDescribingEvent=k,e.buildSiteSearch=function(e){return k({event:{schema:"iglu:com.snowplowanalytics.snowplow/site_search/jsonschema/1-0-0",data:O({terms:e.terms,filters:e.filters,totalResults:e.totalResults,pageResults:e.pageResults})}})},e.buildSocialInteraction=function(e){return k({event:e={schema:"iglu:com.snowplowanalytics.snowplow/social_interaction/jsonschema/1-0-0",data:O({action:e.action,network:e.network,target:e.target})}})},e.buildStructEvent=function(e){var n=e.category,t=e.action,o=e.label,a=e.property;e=e.value;var i=r();return i.add("e","se"),i.add("se_ca",n),i.add("se_ac",t),i.add("se_la",o),i.add("se_pr",a),i.add("se_va",null==e?void 0:e.toString()),i},e.getRuleParts=f,e.getSchemaParts=l,e.globalContexts=c,e.isConditionalContextProvider=x,e.isContextCallbackFunction=w,e.isContextPrimitive=b,e.isEventJson=g,e.isFilterProvider=_,e.isJson=i,e.isNonEmptyJson=a,e.isRuleSet=h,e.isRuleSetProvider=C,e.isSelfDescribingJson=y,e.isStringArray=m,e.isValidRule=p,e.isValidRuleSetArg=v,e.matchSchemaAgainstRule=I,e.matchSchemaAgainstRuleSet=A,e.payloadBuilder=r,e.payloadJsonProcessor=o,e.pluginContexts=s,e.resolveDynamicContext=function(e){for(var n,t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return null!==(n=null==e?void 0:e.map((function(e){if("function"!=typeof e)return e;try{return e.apply(void 0,t)}catch(e){}})).filter(Boolean))&&void 0!==n?n:[]},e.trackerCore=function(e){void 0===e&&(e={});var n=e.base64,t=e.corePlugins,r=null!=t?t:[];e=function(e,n,t){function r(e,n){e=l.getApplicableContexts(e);var t=[];return n&&n.length&&t.push.apply(t,n),e&&e.length&&t.push.apply(t,e),t}var a=s(n),l=c(),u=e,d={};return{track:function(e,i,c){e.withJsonProcessor(o(u)),e.add("eid",M.v4()),e.addDict(d),c=function(e){return null==e?{type:"dtm",value:(new Date).getTime()}:"number"==typeof e?{type:"dtm",value:e}:"ttm"===e.type?{type:"ttm",value:e.value}:{type:"dtm",value:e.value||(new Date).getTime()}}(c),e.add(c.type,c.value.toString()),void 0!==(i=(i=r(e,a.addPluginContexts(i)))&&i.length?{schema:"iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0",data:i}:void 0)&&e.addJson("cx","co",i),n.forEach((function(n){try{n.beforeTrack&&n.beforeTrack(e)}catch(e){console.warn("Snowplow: error with plugin beforeTrack",e)}})),"function"==typeof t&&t(e);var s=e.build();return n.forEach((function(e){try{e.afterTrack&&e.afterTrack(s)}catch(e){console.warn("Snowplow: error with plugin ",e)}})),s},addPayloadPair:function(e,n){d[e]=n},getBase64Encoding:function(){return u},setBase64Encoding:function(e){u=e},addPayloadDict:function(e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(d[n]=e[n])},resetPayloadPairs:function(e){d=i(e)?e:{}},setTrackerVersion:function(e){d.tv=e},setTrackerNamespace:function(e){d.tna=e},setAppId:function(e){d.aid=e},setPlatform:function(e){d.p=e},setUserId:function(e){d.uid=e},setScreenResolution:function(e,n){d.res=e+"x"+n},setViewport:function(e,n){d.vp=e+"x"+n},setColorDepth:function(e){d.cd=e},setTimezone:function(e){d.tz=e},setLang:function(e){d.lang=e},setIpAddress:function(e){d.ip=e},setUseragent:function(e){d.ua=e},addGlobalContexts:function(e){l.addGlobalContexts(e)},clearGlobalContexts:function(){l.clearGlobalContexts()},removeGlobalContexts:function(e){l.removeGlobalContexts(e)}}}(null==n||n,r,e.callback);var a=T(T({},e),{addPlugin:function(e){var n;r.push(e),null===(n=e.activateCorePlugin)||void 0===n||n.call(e,a)}});return null==r||r.forEach((function(e){var n;null===(n=e.activateCorePlugin)||void 0===n||n.call(e,a)})),a},e.validateVendor=d,e.validateVendorParts=u,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
"use strict";!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).snowplowTrackerCore={})}(this,(function(e){function n(e){if(!e)return e;var n=0,t=0,r=[];if(e){e=unescape(encodeURIComponent(e));do{var o=e.charCodeAt(n++),a=e.charCodeAt(n++),i=e.charCodeAt(n++),c=o<<16|a<<8|i;o=c>>18&63,a=c>>12&63,i=c>>6&63,c&=63,r[t++]=E.charAt(o)+E.charAt(a)+E.charAt(i)+E.charAt(c)}while(n<e.length);n=r.join(""),e=((e=e.length%3)?n.slice(0,e-3):n)+"===".slice(e||3)}return e.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function t(){var e,n={},t=[],r=[],a=function(e,t){null!=t&&""!==t&&(n[e]=t)};return{add:a,addDict:function(e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&a(n,e[n])},addJson:function(e,n,a){a&&o(a)&&(e=[e,n,a],r.push(e),t.push(e))},getPayload:function(){return n},getJson:function(){return t},withJsonProcessor:function(n){e=n},build:function(){return null==e||e(this,r),n}}}function r(e){return function(t,r){for(var o=0;o<r.length;o++){var a=r[o],i=JSON.stringify(a[2]);e?t.add(a[0],n(i)):t.add(a[1],i)}r.length=0}}function o(e){if(!a(e))return!1;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n))return!0;return!1}function a(e){return null!=e&&(e.constructor==={}.constructor||e.constructor===[].constructor)}function i(e,n){for(var t=0,r=n.length,o=e.length;t<r;t++,o++)e[o]=n[t];return e}function c(){var e=[],n=[];return{getGlobalPrimitives:function(){return e},getConditionalProviders:function(){return n},addGlobalContexts:function(t){for(var r=[],o=[],a=0;a<t.length;a++){var i=t[a];C(i)?r.push(i):w(i)&&o.push(i)}e=e.concat(o),n=n.concat(r)},clearGlobalContexts:function(){n=[],e=[]},removeGlobalContexts:function(t){for(var r=function(t){C(t)?n=n.filter((function(e){return JSON.stringify(e)===JSON.stringify(t)})):w(t)&&(e=e.filter((function(e){return JSON.stringify(e)===JSON.stringify(t)})))},o=0;o<t.length;o++)r(t[o])},getApplicableContexts:function(t){e:{for(var r=0,o=t.getJson();r<o.length;r++){var a=o[r];if(3===a.length&&"ue_px"===a[0]&&"object"==typeof a[2].data&&"string"==typeof(a=a[2].data.schema)){r=a;break e}}r=""}a="string"==typeof(o=t.getPayload().e)?o:"",o=[];var i=k(e,t,a,r);return o.push.apply(o,i),t=function(e,n,t,r){var o;return e=P(e).map((function(e){e:{if(b(e)){var o=e[0],a=!1;try{a=o({event:n.getPayload(),eventType:t,eventSchema:r})}catch(e){a=!1}if(!0===a){e=k(e[1],n,t,r);break e}}else if(_(e)&&A(e[0],r)){e=k(e[1],n,t,r);break e}e=[]}if(e&&0!==e.length)return e})),(o=[]).concat.apply(o,e.filter((function(e){return null!=e&&e.filter(Boolean)})))}(n,t,a,r),o.push.apply(o,t),o}}}function s(e){return{addPluginContexts:function(n){var t=null!=n?n:[];return e.forEach((function(e){try{e.contexts&&t.push.apply(t,e.contexts())}catch(e){V.error("Error adding plugin contexts",e)}})),t}}}function l(e){if(null!==(e=/^iglu:([a-zA-Z0-9-_.]+)\/([a-zA-Z0-9-_]+)\/jsonschema\/([1-9][0-9]*)-(0|[1-9][0-9]*)-(0|[1-9][0-9]*)$/.exec(e)))return e.slice(1,6)}function u(e){if("*"===e[0]||"*"===e[1])return!1;if(0<e.slice(2).length){var n=!1,t=0;for(e=e.slice(2);t<e.length;t++)if("*"===e[t])n=!0;else if(n)return!1;return!0}return 2==e.length}function d(e){return!!((e=e.split("."))&&1<e.length)&&u(e)}function f(e){if(null!==(e=/^iglu:((?:(?:[a-zA-Z0-9-_]+|\*).)+(?:[a-zA-Z0-9-_]+|\*))\/([a-zA-Z0-9-_.]+|\*)\/jsonschema\/([1-9][0-9]*|\*)-(0|[1-9][0-9]*|\*)-(0|[1-9][0-9]*|\*)$/.exec(e))&&d(e[1]))return e.slice(1,6)}function p(e){if(e=f(e)){var n=e[0];return 5===e.length&&d(n)}return!1}function m(e){return Array.isArray(e)&&e.every((function(e){return"string"==typeof e}))}function y(e){return m(e)?e.every((function(e){return p(e)})):"string"==typeof e&&p(e)}function v(e){return!!(o(e)&&"schema"in e&&"data"in e)&&("string"==typeof e.schema&&"object"==typeof e.data)}function g(e){var n=0;if(null!=e&&"object"==typeof e&&!Array.isArray(e)){if(Object.prototype.hasOwnProperty.call(e,"accept")){if(!y(e.accept))return!1;n+=1}if(Object.prototype.hasOwnProperty.call(e,"reject")){if(!y(e.reject))return!1;n+=1}return 0<n&&2>=n}return!1}function h(e){return"function"==typeof e&&1>=e.length}function w(e){return h(e)||v(e)}function b(e){return!(!Array.isArray(e)||2!==e.length)&&(Array.isArray(e[1])?h(e[0])&&e[1].every(w):h(e[0])&&w(e[1]))}function _(e){return!(!Array.isArray(e)||2!==e.length)&&(!!g(e[0])&&(Array.isArray(e[1])?e[1].every(w):w(e[1])))}function C(e){return b(e)||_(e)}function A(e,n){var t=0,r=0,o=e.accept;return Array.isArray(o)?e.accept.some((function(e){return x(e,n)}))&&r++:"string"==typeof o&&x(o,n)&&r++,o=e.reject,Array.isArray(o)?e.reject.some((function(e){return x(e,n)}))&&t++:"string"==typeof o&&x(o,n)&&t++,0<r&&0===t}function x(e,n){if(!p(e))return!1;if(e=f(e),n=l(n),e&&n){if(!function(e,n){if(n=n.split("."),e=e.split("."),n&&e){if(n.length!==e.length)return!1;for(var t=0;t<e.length;t++)if(!I(n[t],e[t]))return!1;return!0}return!1}(e[0],n[0]))return!1;for(var t=1;5>t;t++)if(!I(e[t],n[t]))return!1;return!0}return!1}function I(e,n){return e&&n&&"*"===e||e===n}function P(e){return Array.isArray(e)?e:[e]}function k(e,n,t,r){var o;return e=P(e).map((function(e){e:if(v(e))e=[e];else{if(h(e)){n:{var o=void 0;try{if(o=e({event:n.getPayload(),eventType:t,eventSchema:r}),Array.isArray(o)&&o.every(v)||v(o)){var a=o;break n}a=void 0;break n}catch(e){}a=void 0}if(v(a)){e=[a];break e}if(Array.isArray(a)){e=a;break e}}e=void 0}if(e&&0!==e.length)return e})),(o=[]).concat.apply(o,e.filter((function(e){return null!=e&&e.filter(Boolean)})))}function j(e){var n=e.event;return e={schema:"iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0",data:{schema:e=n.schema,data:n.data}},(n=t()).add("e","ue"),n.addJson("ue_px","ue_pr",e),n}function L(e,n){void 0===n&&(n={});var t,r={};for(t in e)(n[t]||null!==e[t]&&void 0!==e[t])&&(r[t]=e[t]);return r}var O,S,E="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",T=function(){return(T=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e}).apply(this,arguments)};e.LOG_LEVEL=void 0,(O=e.LOG_LEVEL||(e.LOG_LEVEL={}))[O.none=0]="none",O[O.error=1]="error",O[O.warn=2]="warn",O[O.debug=3]="debug",O[O.info=4]="info";for(var V=function(n){return void 0===n&&(n=e.LOG_LEVEL.warn),{setLogLevel:function(t){n=e.LOG_LEVEL[t]?t:e.LOG_LEVEL.warn},warn:function(t,r){for(var o=[],a=2;a<arguments.length;a++)o[a-2]=arguments[a];n>=e.LOG_LEVEL.warn&&"undefined"!=typeof console&&"undefined"!=typeof console&&(a="Snowplow: "+t,r?console.warn.apply(console,i([a+"\n",r],o)):console.warn.apply(console,i([a],o)))},error:function(t,r){for(var o=[],a=2;a<arguments.length;a++)o[a-2]=arguments[a];n>=e.LOG_LEVEL.error&&"undefined"!=typeof console&&(a="Snowplow: "+t+"\n",r?console.error.apply(console,i([a+"\n",r],o)):console.error.apply(console,i([a],o)))},debug:function(t){for(var r=[],o=1;o<arguments.length;o++)r[o-1]=arguments[o];n>=e.LOG_LEVEL.debug&&"undefined"!=typeof console&&"undefined"!=typeof console&&console.warn.apply(console,i(["Snowplow: "+t],r))},info:function(t){for(var r=[],o=1;o<arguments.length;o++)r[o-1]=arguments[o];n>=e.LOG_LEVEL.info&&"undefined"!=typeof console&&"undefined"!=typeof console&&console.info.apply(console,i(["Snowplow: "+t],r))}}}(),G=(S=void 0,function(e){var n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(n){var t=new Uint8Array(16);e.exports=function(){return n(t),t}}else{var r=Array(16);e.exports=function(){for(var e,n=0;16>n;n++)0==(3&n)&&(e=4294967296*Math.random()),r[n]=e>>>((3&n)<<3)&255;return r}}}(S={exports:{}}),S.exports),N=[],R=0;256>R;++R)N[R]=(R+256).toString(16).substr(1);var J,U,z=function(e,n){return n=n||0,[N[e[n++]],N[e[n++]],N[e[n++]],N[e[n++]],"-",N[e[n++]],N[e[n++]],"-",N[e[n++]],N[e[n++]],"-",N[e[n++]],N[e[n++]],"-",N[e[n++]],N[e[n++]],N[e[n++]],N[e[n++]],N[e[n++]],N[e[n++]]].join("")},D=0,q=0,M=function(e,n,t){if(t=n&&t||0,"string"==typeof e&&(n="binary"===e?Array(16):null,e=null),(e=(e=e||{}).random||(e.rng||G)())[6]=15&e[6]|64,e[8]=63&e[8]|128,n)for(var r=0;16>r;++r)n[t+r]=e[r];return n||z(e)};M.v1=function(e,n,t){t=n&&t||0;var r=n||[],o=(e=e||{}).node||J,a=void 0!==e.clockseq?e.clockseq:U;if(null==o||null==a){var i=G();null==o&&(o=J=[1|i[0],i[1],i[2],i[3],i[4],i[5]]),null==a&&(a=U=16383&(i[6]<<8|i[7]))}i=void 0!==e.msecs?e.msecs:(new Date).getTime();var c=void 0!==e.nsecs?e.nsecs:q+1,s=i-D+(c-q)/1e4;if(0>s&&void 0===e.clockseq&&(a=a+1&16383),(0>s||i>D)&&void 0===e.nsecs&&(c=0),1e4<=c)throw Error("uuid.v1(): Can't create more than 10M uuids/sec");for(D=i,q=c,U=a,e=(1e4*(268435455&(i+=122192928e5))+c)%4294967296,r[t++]=e>>>24&255,r[t++]=e>>>16&255,r[t++]=e>>>8&255,r[t++]=255&e,e=i/4294967296*1e4&268435455,r[t++]=e>>>8&255,r[t++]=255&e,r[t++]=e>>>24&15|16,r[t++]=e>>>16&255,r[t++]=a>>>8|128,r[t++]=255&a,a=0;6>a;++a)r[t+a]=o[a];return n||z(r)},M.v4=M,e.LOG=V,e.buildAdClick=function(e){return j({event:e={schema:"iglu:com.snowplowanalytics.snowplow/ad_click/jsonschema/1-0-0",data:L({targetUrl:e.targetUrl,clickId:e.clickId,costModel:e.costModel,cost:e.cost,bannerId:e.bannerId,zoneId:e.zoneId,impressionId:e.impressionId,advertiserId:e.advertiserId,campaignId:e.campaignId})}})},e.buildAdConversion=function(e){return j({event:e={schema:"iglu:com.snowplowanalytics.snowplow/ad_conversion/jsonschema/1-0-0",data:L({conversionId:e.conversionId,costModel:e.costModel,cost:e.cost,category:e.category,action:e.action,property:e.property,initialValue:e.initialValue,advertiserId:e.advertiserId,campaignId:e.campaignId})}})},e.buildAdImpression=function(e){return j({event:e={schema:"iglu:com.snowplowanalytics.snowplow/ad_impression/jsonschema/1-0-0",data:L({impressionId:e.impressionId,costModel:e.costModel,cost:e.cost,targetUrl:e.targetUrl,bannerId:e.bannerId,zoneId:e.zoneId,advertiserId:e.advertiserId,campaignId:e.campaignId})}})},e.buildAddToCart=function(e){return j({event:{schema:"iglu:com.snowplowanalytics.snowplow/add_to_cart/jsonschema/1-0-0",data:L({sku:e.sku,quantity:e.quantity,name:e.name,category:e.category,unitPrice:e.unitPrice,currency:e.currency})}})},e.buildConsentGranted=function(e){var n=e.expiry;return e={schema:"iglu:com.snowplowanalytics.snowplow/consent_document/jsonschema/1-0-0",data:L({id:e.id,version:e.version,name:e.name,description:e.description})},{event:j({event:{schema:"iglu:com.snowplowanalytics.snowplow/consent_granted/jsonschema/1-0-0",data:L({expiry:n})}}),context:[e]}},e.buildConsentWithdrawn=function(e){var n=e.all;return e={schema:"iglu:com.snowplowanalytics.snowplow/consent_document/jsonschema/1-0-0",data:L({id:e.id,version:e.version,name:e.name,description:e.description})},{event:j({event:{schema:"iglu:com.snowplowanalytics.snowplow/consent_withdrawn/jsonschema/1-0-0",data:L({all:n})}}),context:[e]}},e.buildEcommerceTransaction=function(e){var n=e.orderId,r=e.total,o=e.affiliation,a=e.tax,i=e.shipping,c=e.city,s=e.state,l=e.country;e=e.currency;var u=t();return u.add("e","tr"),u.add("tr_id",n),u.add("tr_af",o),u.add("tr_tt",r),u.add("tr_tx",a),u.add("tr_sh",i),u.add("tr_ci",c),u.add("tr_st",s),u.add("tr_co",l),u.add("tr_cu",e),u},e.buildEcommerceTransactionItem=function(e){var n=e.orderId,r=e.sku,o=e.price,a=e.name,i=e.category,c=e.quantity;e=e.currency;var s=t();return s.add("e","ti"),s.add("ti_id",n),s.add("ti_sk",r),s.add("ti_nm",a),s.add("ti_ca",i),s.add("ti_pr",o),s.add("ti_qu",c),s.add("ti_cu",e),s},e.buildFormFocusOrChange=function(e){var n="",t=e.schema,r=e.type;return e={formId:e.formId,elementId:e.elementId,nodeName:e.nodeName,elementClasses:e.elementClasses,value:e.value},"change_form"===t?(n="iglu:com.snowplowanalytics.snowplow/change_form/jsonschema/1-0-0",e.type=r):"focus_form"===t&&(n="iglu:com.snowplowanalytics.snowplow/focus_form/jsonschema/1-0-0",e.elementType=r),j({event:{schema:n,data:L(e,{value:!0})}})},e.buildFormSubmission=function(e){return j({event:{schema:"iglu:com.snowplowanalytics.snowplow/submit_form/jsonschema/1-0-0",data:L({formId:e.formId,formClasses:e.formClasses,elements:e.elements})}})},e.buildLinkClick=function(e){return j({event:e={schema:"iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1",data:L({targetUrl:e.targetUrl,elementId:e.elementId,elementClasses:e.elementClasses,elementTarget:e.elementTarget,elementContent:e.elementContent})}})},e.buildPagePing=function(e){var n=e.pageUrl,r=e.pageTitle,o=e.referrer,a=e.minXOffset,i=e.maxXOffset,c=e.minYOffset;e=e.maxYOffset;var s=t();return s.add("e","pp"),s.add("url",n),s.add("page",r),s.add("refr",o),a&&!isNaN(Number(a))&&s.add("pp_mix",a.toString()),i&&!isNaN(Number(i))&&s.add("pp_max",i.toString()),c&&!isNaN(Number(c))&&s.add("pp_miy",c.toString()),e&&!isNaN(Number(e))&&s.add("pp_may",e.toString()),s},e.buildPageView=function(e){var n=e.pageUrl,r=e.pageTitle;e=e.referrer;var o=t();return o.add("e","pv"),o.add("url",n),o.add("page",r),o.add("refr",e),o},e.buildRemoveFromCart=function(e){return j({event:{schema:"iglu:com.snowplowanalytics.snowplow/remove_from_cart/jsonschema/1-0-0",data:L({sku:e.sku,quantity:e.quantity,name:e.name,category:e.category,unitPrice:e.unitPrice,currency:e.currency})}})},e.buildScreenView=function(e){return j({event:{schema:"iglu:com.snowplowanalytics.snowplow/screen_view/jsonschema/1-0-0",data:L({name:e.name,id:e.id})}})},e.buildSelfDescribingEvent=j,e.buildSiteSearch=function(e){return j({event:{schema:"iglu:com.snowplowanalytics.snowplow/site_search/jsonschema/1-0-0",data:L({terms:e.terms,filters:e.filters,totalResults:e.totalResults,pageResults:e.pageResults})}})},e.buildSocialInteraction=function(e){return j({event:e={schema:"iglu:com.snowplowanalytics.snowplow/social_interaction/jsonschema/1-0-0",data:L({action:e.action,network:e.network,target:e.target})}})},e.buildStructEvent=function(e){var n=e.category,r=e.action,o=e.label,a=e.property;e=e.value;var i=t();return i.add("e","se"),i.add("se_ca",n),i.add("se_ac",r),i.add("se_la",o),i.add("se_pr",a),i.add("se_va",null==e?void 0:e.toString()),i},e.getRuleParts=f,e.getSchemaParts=l,e.globalContexts=c,e.isConditionalContextProvider=C,e.isContextCallbackFunction=h,e.isContextPrimitive=w,e.isFilterProvider=b,e.isJson=a,e.isNonEmptyJson=o,e.isRuleSet=g,e.isRuleSetProvider=_,e.isSelfDescribingJson=v,e.isStringArray=m,e.isValidRule=p,e.isValidRuleSetArg=y,e.matchSchemaAgainstRule=x,e.matchSchemaAgainstRuleSet=A,e.payloadBuilder=t,e.payloadJsonProcessor=r,e.pluginContexts=s,e.resolveDynamicContext=function(e){for(var n,t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return null!==(n=null==e?void 0:e.map((function(e){if("function"!=typeof e)return e;try{return e.apply(void 0,t)}catch(e){}})).filter(Boolean))&&void 0!==n?n:[]},e.trackerCore=function(e){void 0===e&&(e={});var n=e.base64,t=e.corePlugins,o=null!=t?t:[];e=function(e,n,t){function o(e,n){e=l.getApplicableContexts(e);var t=[];return n&&n.length&&t.push.apply(t,n),e&&e.length&&t.push.apply(t,e),t}var i=s(n),l=c(),u=e,d={};return{track:function(e,a,c){e.withJsonProcessor(r(u)),e.add("eid",M.v4()),e.addDict(d),c=function(e){return null==e?{type:"dtm",value:(new Date).getTime()}:"number"==typeof e?{type:"dtm",value:e}:"ttm"===e.type?{type:"ttm",value:e.value}:{type:"dtm",value:e.value||(new Date).getTime()}}(c),e.add(c.type,c.value.toString()),void 0!==(a=(a=o(e,i.addPluginContexts(a)))&&a.length?{schema:"iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0",data:a}:void 0)&&e.addJson("cx","co",a),n.forEach((function(n){try{n.beforeTrack&&n.beforeTrack(e)}catch(e){V.error("Plugin beforeTrack",e)}})),"function"==typeof t&&t(e);var s=e.build();return n.forEach((function(e){try{e.afterTrack&&e.afterTrack(s)}catch(e){V.error("Plugin afterTrack",e)}})),s},addPayloadPair:function(e,n){d[e]=n},getBase64Encoding:function(){return u},setBase64Encoding:function(e){u=e},addPayloadDict:function(e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(d[n]=e[n])},resetPayloadPairs:function(e){d=a(e)?e:{}},setTrackerVersion:function(e){d.tv=e},setTrackerNamespace:function(e){d.tna=e},setAppId:function(e){d.aid=e},setPlatform:function(e){d.p=e},setUserId:function(e){d.uid=e},setScreenResolution:function(e,n){d.res=e+"x"+n},setViewport:function(e,n){d.vp=e+"x"+n},setColorDepth:function(e){d.cd=e},setTimezone:function(e){d.tz=e},setLang:function(e){d.lang=e},setIpAddress:function(e){d.ip=e},setUseragent:function(e){d.ua=e},addGlobalContexts:function(e){l.addGlobalContexts(e)},clearGlobalContexts:function(){l.clearGlobalContexts()},removeGlobalContexts:function(e){l.removeGlobalContexts(e)}}}(null==n||n,o,e.callback);var i=T(T({},e),{addPlugin:function(e){var n;o.push(e),null===(n=e.activateCorePlugin)||void 0===n||n.call(e,i)}});return null==o||o.forEach((function(e){var n,t;null===(n=e.logger)||void 0===n||n.call(e,V),null===(t=e.activateCorePlugin)||void 0===t||t.call(e,i)})),i},e.validateVendor=d,e.validateVendorParts=u,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.min.js.map |
@@ -6,13 +6,17 @@ /** | ||
/** | ||
* An array of tuples which represented the unprocessed JSON to be added to the Payload | ||
* A tuple which represents the unprocessed JSON to be added to the Payload | ||
*/ | ||
type JsonForProcessing = Array<[ | ||
type EventJsonWithKeys = [ | ||
keyIfEncoded: string, | ||
keyIfNotEncoded: string, | ||
json: Record<string, unknown> | ||
]>; | ||
]; | ||
/** | ||
* An array of tuples which represents the unprocessed JSON to be added to the Payload | ||
*/ | ||
type EventJson = Array<EventJsonWithKeys>; | ||
/** | ||
* A function which will processor the Json onto the injected PayloadBuilder | ||
*/ | ||
type JsonProcessor = (payloadBuilder: PayloadBuilder, jsonForProcessing: JsonForProcessing) => void; | ||
type JsonProcessor = (payloadBuilder: PayloadBuilder, jsonForProcessing: EventJson) => void; | ||
/** | ||
@@ -41,2 +45,10 @@ * Interface for mutable object encapsulating tracker payload | ||
/** | ||
* Gets the current payload, before cached JSON is processed | ||
*/ | ||
getPayload: () => Payload; | ||
/** | ||
* Gets all JSON objects added to payload | ||
*/ | ||
getJson: () => EventJson; | ||
/** | ||
* Adds a function which will be executed when building | ||
@@ -49,3 +61,3 @@ * the payload to process the JSON which has been added to this payload | ||
* Builds and returns the Payload | ||
* @param base64Encode configures if cached json should be encoded | ||
* @param base64Encode configures if unprocessed, cached json should be encoded | ||
*/ | ||
@@ -72,2 +84,17 @@ build: () => Payload; | ||
declare function isJson(property?: Record<string, unknown>): boolean; | ||
declare enum LOG_LEVEL { | ||
none = 0, | ||
error = 1, | ||
warn = 2, | ||
debug = 3, | ||
info = 4 | ||
} | ||
interface Logger { | ||
setLogLevel: (level: LOG_LEVEL) => void; | ||
info: (message: string, ...extraParams: unknown[]) => void; | ||
debug: (message: string, ...extraParams: unknown[]) => void; | ||
warn: (message: string, error?: Error, ...extraParams: unknown[]) => void; | ||
error: (message: string, error?: Error, ...extraParams: unknown[]) => void; | ||
} | ||
declare const LOG: Logger; | ||
/** | ||
@@ -99,2 +126,7 @@ * Interface which defines Core Plugins | ||
contexts?: () => SelfDescribingJson[]; | ||
/** | ||
* Passed a logger instance which can be used to send log information | ||
* to the active logger | ||
*/ | ||
logger?: (logger: Logger) => void; | ||
} | ||
@@ -291,2 +323,6 @@ /** | ||
removeGlobalContexts(contexts: Array<ConditionalContextProvider | ContextPrimitive>): void; | ||
/** | ||
* Add a plugin into the plugin collection after Core has already been initialised | ||
* @param plugin The plugin to add | ||
*/ | ||
addPlugin(plugin: CorePlugin): void; | ||
@@ -1009,8 +1045,2 @@ } | ||
/** | ||
* Check if a variable to is a valid, non-empty Payload event by looking for the 'e' parameter of a Payload | ||
* @param input The variable to validate | ||
* @returns True if a valid Payload | ||
*/ | ||
declare function isEventJson(input: unknown): input is Payload; | ||
/** | ||
* Validates if the input object contains the expected properties of a ruleset | ||
@@ -1060,2 +1090,2 @@ * @param input The object containing a rule set | ||
declare function matchSchemaAgainstRule(rule: string, schema: string): boolean; | ||
export { ContextEvent, ContextGenerator, ContextFilter, ContextPrimitive, FilterProvider, RuleSet, RuleSetProvider, ConditionalContextProvider, DynamicContext, GlobalContexts, globalContexts, PluginContexts, pluginContexts, resolveDynamicContext, getSchemaParts, validateVendorParts, validateVendor, getRuleParts, isValidRule, isStringArray, isValidRuleSetArg, isSelfDescribingJson, isEventJson, isRuleSet, isContextCallbackFunction, isContextPrimitive, isFilterProvider, isRuleSetProvider, isConditionalContextProvider, matchSchemaAgainstRuleSet, matchSchemaAgainstRule, CorePlugin, Payload, JsonForProcessing, JsonProcessor, PayloadBuilder, payloadBuilder, payloadJsonProcessor, isNonEmptyJson, isJson, SelfDescribingJson, SelfDescribingJsonArray, Timestamp, TrueTimestamp, DeviceTimestamp, CommonEventProperties, TrackerCore, CoreConfiguration, trackerCore, SelfDescribingEvent, buildSelfDescribingEvent, PageViewEvent, buildPageView, PagePingEvent, buildPagePing, StructuredEvent, buildStructEvent, EcommerceTransactionEvent, buildEcommerceTransaction, EcommerceTransactionItemEvent, buildEcommerceTransactionItem, ScreenViewEvent, buildScreenView, LinkClickEvent, buildLinkClick, AdImpressionEvent, buildAdImpression, AdClickEvent, buildAdClick, AdConversionEvent, buildAdConversion, SocialInteractionEvent, buildSocialInteraction, AddToCartEvent, buildAddToCart, RemoveFromCartEvent, buildRemoveFromCart, FormFocusOrChangeEvent, buildFormFocusOrChange, FormElement, FormSubmissionEvent, buildFormSubmission, SiteSearchEvent, buildSiteSearch, ConsentWithdrawnEvent, buildConsentWithdrawn, ConsentGrantedEvent, buildConsentGranted }; | ||
export { ContextEvent, ContextGenerator, ContextFilter, ContextPrimitive, FilterProvider, RuleSet, RuleSetProvider, ConditionalContextProvider, DynamicContext, GlobalContexts, globalContexts, PluginContexts, pluginContexts, resolveDynamicContext, getSchemaParts, validateVendorParts, validateVendor, getRuleParts, isValidRule, isStringArray, isValidRuleSetArg, isSelfDescribingJson, isRuleSet, isContextCallbackFunction, isContextPrimitive, isFilterProvider, isRuleSetProvider, isConditionalContextProvider, matchSchemaAgainstRuleSet, matchSchemaAgainstRule, CorePlugin, Payload, EventJsonWithKeys, EventJson, JsonProcessor, PayloadBuilder, payloadBuilder, payloadJsonProcessor, isNonEmptyJson, isJson, SelfDescribingJson, SelfDescribingJsonArray, Timestamp, TrueTimestamp, DeviceTimestamp, CommonEventProperties, TrackerCore, CoreConfiguration, trackerCore, SelfDescribingEvent, buildSelfDescribingEvent, PageViewEvent, buildPageView, PagePingEvent, buildPagePing, StructuredEvent, buildStructEvent, EcommerceTransactionEvent, buildEcommerceTransaction, EcommerceTransactionItemEvent, buildEcommerceTransactionItem, ScreenViewEvent, buildScreenView, LinkClickEvent, buildLinkClick, AdImpressionEvent, buildAdImpression, AdClickEvent, buildAdClick, AdConversionEvent, buildAdConversion, SocialInteractionEvent, buildSocialInteraction, AddToCartEvent, buildAddToCart, RemoveFromCartEvent, buildRemoveFromCart, FormFocusOrChangeEvent, buildFormFocusOrChange, FormElement, FormSubmissionEvent, buildFormSubmission, SiteSearchEvent, buildSiteSearch, ConsentWithdrawnEvent, buildConsentWithdrawn, ConsentGrantedEvent, buildConsentGranted, LOG, LOG_LEVEL, Logger }; |
/*! | ||
* Core functionality for Snowplow JavaScript trackers v3.0.0-alpha.4 (http://bit.ly/sp-js) | ||
* Core functionality for Snowplow JavaScript trackers v3.0.0-beta.1 (http://bit.ly/sp-js) | ||
* Copyright 2021 Snowplow Analytics Ltd, 2010 Anthon Pang | ||
@@ -7,3 +7,3 @@ * Licensed under BSD-3-Clause | ||
import { __assign } from 'tslib'; | ||
import { __spreadArray, __assign } from 'tslib'; | ||
import { v4 } from 'uuid'; | ||
@@ -34,24 +34,2 @@ | ||
/** | ||
* Decodes a url safe Base 64 encoded string | ||
* @remark See: {@link http://tools.ietf.org/html/rfc4648#page-7} | ||
* @param data String to decode | ||
* @returns The decoded string | ||
*/ | ||
function base64urldecode(data) { | ||
if (!data) { | ||
return data; | ||
} | ||
var padding = 4 - (data.length % 4); | ||
switch (padding) { | ||
case 2: | ||
data += '=='; | ||
break; | ||
case 3: | ||
data += '='; | ||
break; | ||
} | ||
var b64Data = data.replace(/-/g, '+').replace(/_/g, '/'); | ||
return base64decode(b64Data); | ||
} | ||
/** | ||
* Encodes a string into a url safe Base 64 encoded string | ||
@@ -115,67 +93,2 @@ * @remark See: {@link http://tools.ietf.org/html/rfc4648#page-7} | ||
} | ||
/** | ||
* Decode base64 to string | ||
* | ||
* @param data base64 to string | ||
* @returns decoded string | ||
*/ | ||
function base64decode(encodedData) { | ||
// discuss at: http://locutus.io/php/base64_decode/ | ||
// original by: Tyler Akins (http://rumkin.com) | ||
// improved by: Thunder.m | ||
// improved by: Kevin van Zonneveld (http://kvz.io) | ||
// improved by: Kevin van Zonneveld (http://kvz.io) | ||
// input by: Aman Gupta | ||
// input by: Brett Zamir (http://brett-zamir.me) | ||
// bugfixed by: Onno Marsman (https://twitter.com/onnomarsman) | ||
// bugfixed by: Pellentesque Malesuada | ||
// bugfixed by: Kevin van Zonneveld (http://kvz.io) | ||
// improved by: Indigo744 | ||
// example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==') | ||
// returns 1: 'Kevin van Zonneveld' | ||
// example 2: base64_decode('YQ==') | ||
// returns 2: 'a' | ||
// example 3: base64_decode('4pyTIMOgIGxhIG1vZGU=') | ||
// returns 3: '✓ à la mode' | ||
// decodeUTF8string() | ||
// Internal function to decode properly UTF8 string | ||
// Adapted from Solution #1 at https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding | ||
var decodeUTF8string = function (str) { | ||
// Going backwards: from bytestream, to percent-encoding, to original string. | ||
return decodeURIComponent(str | ||
.split('') | ||
.map(function (c) { | ||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); | ||
}) | ||
.join('')); | ||
}; | ||
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = ''; | ||
var tmpArr = []; | ||
if (!encodedData) { | ||
return encodedData; | ||
} | ||
encodedData += ''; | ||
do { | ||
// unpack four hexets into three octets using index points in b64 | ||
h1 = b64.indexOf(encodedData.charAt(i++)); | ||
h2 = b64.indexOf(encodedData.charAt(i++)); | ||
h3 = b64.indexOf(encodedData.charAt(i++)); | ||
h4 = b64.indexOf(encodedData.charAt(i++)); | ||
bits = (h1 << 18) | (h2 << 12) | (h3 << 6) | h4; | ||
o1 = (bits >> 16) & 0xff; | ||
o2 = (bits >> 8) & 0xff; | ||
o3 = bits & 0xff; | ||
if (h3 === 64) { | ||
tmpArr[ac++] = String.fromCharCode(o1); | ||
} | ||
else if (h4 === 64) { | ||
tmpArr[ac++] = String.fromCharCode(o1, o2); | ||
} | ||
else { | ||
tmpArr[ac++] = String.fromCharCode(o1, o2, o3); | ||
} | ||
} while (i < encodedData.length); | ||
dec = tmpArr.join(''); | ||
return decodeUTF8string(dec.replace(/\0+$/, '')); | ||
} | ||
@@ -212,3 +125,3 @@ /* | ||
function payloadBuilder() { | ||
var dict = {}, jsonForProcessing = []; | ||
var dict = {}, allJson = [], jsonForProcessing = []; | ||
var processor; | ||
@@ -230,3 +143,5 @@ var add = function (key, value) { | ||
if (json && isNonEmptyJson(json)) { | ||
jsonForProcessing.push([keyIfEncoded, keyIfNotEncoded, json]); | ||
var jsonWithKeys = [keyIfEncoded, keyIfNotEncoded, json]; | ||
jsonForProcessing.push(jsonWithKeys); | ||
allJson.push(jsonWithKeys); | ||
} | ||
@@ -238,2 +153,4 @@ }; | ||
addJson: addJson, | ||
getPayload: function () { return dict; }, | ||
getJson: function () { return allJson; }, | ||
withJsonProcessor: function (jsonProcessor) { | ||
@@ -323,2 +240,120 @@ processor = jsonProcessor; | ||
*/ | ||
var label = 'Snowplow: '; | ||
var LOG_LEVEL; | ||
(function (LOG_LEVEL) { | ||
LOG_LEVEL[LOG_LEVEL["none"] = 0] = "none"; | ||
LOG_LEVEL[LOG_LEVEL["error"] = 1] = "error"; | ||
LOG_LEVEL[LOG_LEVEL["warn"] = 2] = "warn"; | ||
LOG_LEVEL[LOG_LEVEL["debug"] = 3] = "debug"; | ||
LOG_LEVEL[LOG_LEVEL["info"] = 4] = "info"; | ||
})(LOG_LEVEL || (LOG_LEVEL = {})); | ||
var LOG = logger(); | ||
function logger(logLevel) { | ||
if (logLevel === void 0) { logLevel = LOG_LEVEL.warn; } | ||
function setLogLevel(level) { | ||
if (LOG_LEVEL[level]) { | ||
logLevel = level; | ||
} | ||
else { | ||
logLevel = LOG_LEVEL.warn; | ||
} | ||
} | ||
/** | ||
* Log errors, with or without error object | ||
*/ | ||
function error(message, error) { | ||
var extraParams = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
extraParams[_i - 2] = arguments[_i]; | ||
} | ||
if (logLevel >= LOG_LEVEL.error && typeof console !== 'undefined') { | ||
var logMsg = label + message + '\n'; | ||
if (error) { | ||
console.error.apply(console, __spreadArray([logMsg + '\n', error], extraParams)); | ||
} | ||
else { | ||
console.error.apply(console, __spreadArray([logMsg], extraParams)); | ||
} | ||
} | ||
} | ||
/** | ||
* Log warnings, with or without error object | ||
*/ | ||
function warn(message, error) { | ||
var extraParams = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
extraParams[_i - 2] = arguments[_i]; | ||
} | ||
if (logLevel >= LOG_LEVEL.warn && typeof console !== 'undefined') { | ||
if (typeof console !== 'undefined') { | ||
var logMsg = label + message; | ||
if (error) { | ||
console.warn.apply(console, __spreadArray([logMsg + '\n', error], extraParams)); | ||
} | ||
else { | ||
console.warn.apply(console, __spreadArray([logMsg], extraParams)); | ||
} | ||
} | ||
} | ||
} | ||
/** | ||
* Log debug messages | ||
*/ | ||
function debug(message) { | ||
var extraParams = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
extraParams[_i - 1] = arguments[_i]; | ||
} | ||
if (logLevel >= LOG_LEVEL.debug && typeof console !== 'undefined') { | ||
if (typeof console !== 'undefined') { | ||
console.warn.apply(console, __spreadArray([label + message], extraParams)); | ||
} | ||
} | ||
} | ||
/** | ||
* Log info messages | ||
*/ | ||
function info(message) { | ||
var extraParams = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
extraParams[_i - 1] = arguments[_i]; | ||
} | ||
if (logLevel >= LOG_LEVEL.info && typeof console !== 'undefined') { | ||
if (typeof console !== 'undefined') { | ||
console.info.apply(console, __spreadArray([label + message], extraParams)); | ||
} | ||
} | ||
} | ||
return { setLogLevel: setLogLevel, warn: warn, error: error, debug: debug, info: info }; | ||
} | ||
/* | ||
* Copyright (c) 2021 Snowplow Analytics Ltd, 2010 Anthon Pang | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* 3. Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
/** | ||
@@ -386,10 +421,3 @@ * Contains helper functions to aid in the addition and removal of Global Contexts | ||
getApplicableContexts: function (event) { | ||
var builtEvent = event.build(); | ||
if (isEventJson(builtEvent)) { | ||
var decodedEvent = getDecodedEvent(builtEvent); | ||
return assembleAllContexts(decodedEvent); | ||
} | ||
else { | ||
return []; | ||
} | ||
return assembleAllContexts(event); | ||
} | ||
@@ -415,3 +443,3 @@ }; | ||
catch (ex) { | ||
console.warn('Snowplow: error with plugin context', ex); | ||
LOG.error('Error adding plugin contexts', ex); | ||
} | ||
@@ -564,13 +592,2 @@ }); | ||
/** | ||
* Check if a variable to is a valid, non-empty Payload event by looking for the 'e' parameter of a Payload | ||
* @param input The variable to validate | ||
* @returns True if a valid Payload | ||
*/ | ||
function isEventJson(input) { | ||
var payload = input; | ||
if (isNonEmptyJson(payload) && 'e' in payload) | ||
return typeof payload.e === 'string'; | ||
return false; | ||
} | ||
/** | ||
* Validates if the input object contains the expected properties of a ruleset | ||
@@ -737,31 +754,20 @@ * @param input The object containing a rule set | ||
// Returns the "useful" schema, i.e. what would someone want to use to identify events. | ||
// The idea being that you can determine the event type from 'e', so getting the schema from | ||
// 'ue_px.schema'/'ue_pr.schema' would be redundant - it'll return the unstruct_event schema. | ||
// Instead the schema nested inside the unstruct_event is more useful! | ||
// This doesn't decode ue_px, it works because it's called by code that has already decoded it | ||
// For some events this is the 'e' property but for unstructured events, this is the | ||
// 'schema' from the 'ue_px' field. | ||
function getUsefulSchema(sb) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; | ||
if (typeof ((_b = (_a = sb['ue_px']) === null || _a === void 0 ? void 0 : _a['data']) === null || _b === void 0 ? void 0 : _b['schema']) === 'string') | ||
return (_d = (_c = sb['ue_px']) === null || _c === void 0 ? void 0 : _c['data']) === null || _d === void 0 ? void 0 : _d['schema']; | ||
else if (typeof ((_f = (_e = sb['ue_pr']) === null || _e === void 0 ? void 0 : _e['data']) === null || _f === void 0 ? void 0 : _f['schema']) === 'string') | ||
return (_h = (_g = sb['ue_pr']) === null || _g === void 0 ? void 0 : _g['data']) === null || _h === void 0 ? void 0 : _h['schema']; | ||
else if (typeof ((_j = sb) === null || _j === void 0 ? void 0 : _j['schema']) === 'string') | ||
return (_k = sb) === null || _k === void 0 ? void 0 : _k['schema']; | ||
return ''; | ||
} | ||
function getDecodedEvent(sb) { | ||
var decodedEvent = __assign({}, sb); // spread operator, instantiates new object | ||
try { | ||
if (Object.prototype.hasOwnProperty.call(decodedEvent, 'ue_px')) { | ||
decodedEvent['ue_px'] = JSON.parse(base64urldecode(decodedEvent['ue_px'])); | ||
var eventJson = sb.getJson(); | ||
for (var _i = 0, eventJson_1 = eventJson; _i < eventJson_1.length; _i++) { | ||
var json = eventJson_1[_i]; | ||
if (json.length === 3 && json[0] === 'ue_px' && typeof json[2]['data'] === 'object') { | ||
var schema = json[2]['data']['schema']; | ||
if (typeof schema == 'string') { | ||
return schema; | ||
} | ||
} | ||
return decodedEvent; | ||
} | ||
catch (e) { | ||
return decodedEvent; | ||
} | ||
return ''; | ||
} | ||
function getEventType(sb) { | ||
var _a; | ||
return ((_a = sb === null || sb === void 0 ? void 0 : sb['e']) !== null && _a !== void 0 ? _a : ''); | ||
function getEventType(payloadBuilder) { | ||
var eventType = payloadBuilder.getPayload()['e']; | ||
return typeof eventType === 'string' ? eventType : ''; | ||
} | ||
@@ -773,3 +779,3 @@ function buildGenerator(generator, event, eventType, eventSchema) { | ||
var args = { | ||
event: event, | ||
event: event.getPayload(), | ||
eventType: eventType, | ||
@@ -835,3 +841,3 @@ eventSchema: eventSchema | ||
var args = { | ||
event: event, | ||
event: event.getPayload(), | ||
eventType: eventType, | ||
@@ -993,3 +999,3 @@ eventSchema: eventSchema | ||
catch (ex) { | ||
console.warn('Snowplow: error with plugin beforeTrack', ex); | ||
LOG.error('Plugin beforeTrack', ex); | ||
} | ||
@@ -1008,3 +1014,3 @@ }); | ||
catch (ex) { | ||
console.warn('Snowplow: error with plugin ', ex); | ||
LOG.error('Plugin afterTrack', ex); | ||
} | ||
@@ -1096,4 +1102,5 @@ }); | ||
plugins === null || plugins === void 0 ? void 0 : plugins.forEach(function (plugin) { | ||
var _a; | ||
(_a = plugin.activateCorePlugin) === null || _a === void 0 ? void 0 : _a.call(plugin, core); | ||
var _a, _b; | ||
(_a = plugin.logger) === null || _a === void 0 ? void 0 : _a.call(plugin, LOG); | ||
(_b = plugin.activateCorePlugin) === null || _b === void 0 ? void 0 : _b.call(plugin, core); | ||
}); | ||
@@ -1531,3 +1538,3 @@ return core; | ||
export { buildAdClick, buildAdConversion, buildAdImpression, buildAddToCart, buildConsentGranted, buildConsentWithdrawn, buildEcommerceTransaction, buildEcommerceTransactionItem, buildFormFocusOrChange, buildFormSubmission, buildLinkClick, buildPagePing, buildPageView, buildRemoveFromCart, buildScreenView, buildSelfDescribingEvent, buildSiteSearch, buildSocialInteraction, buildStructEvent, getRuleParts, getSchemaParts, globalContexts, isConditionalContextProvider, isContextCallbackFunction, isContextPrimitive, isEventJson, isFilterProvider, isJson, isNonEmptyJson, isRuleSet, isRuleSetProvider, isSelfDescribingJson, isStringArray, isValidRule, isValidRuleSetArg, matchSchemaAgainstRule, matchSchemaAgainstRuleSet, payloadBuilder, payloadJsonProcessor, pluginContexts, resolveDynamicContext, trackerCore, validateVendor, validateVendorParts }; | ||
export { LOG, LOG_LEVEL, buildAdClick, buildAdConversion, buildAdImpression, buildAddToCart, buildConsentGranted, buildConsentWithdrawn, buildEcommerceTransaction, buildEcommerceTransactionItem, buildFormFocusOrChange, buildFormSubmission, buildLinkClick, buildPagePing, buildPageView, buildRemoveFromCart, buildScreenView, buildSelfDescribingEvent, buildSiteSearch, buildSocialInteraction, buildStructEvent, getRuleParts, getSchemaParts, globalContexts, isConditionalContextProvider, isContextCallbackFunction, isContextPrimitive, isFilterProvider, isJson, isNonEmptyJson, isRuleSet, isRuleSetProvider, isSelfDescribingJson, isStringArray, isValidRule, isValidRuleSetArg, matchSchemaAgainstRule, matchSchemaAgainstRuleSet, payloadBuilder, payloadJsonProcessor, pluginContexts, resolveDynamicContext, trackerCore, validateVendor, validateVendorParts }; | ||
//# sourceMappingURL=index.module.js.map |
{ | ||
"name": "@snowplow/tracker-core", | ||
"version": "3.0.0-alpha.4", | ||
"version": "3.0.0-beta.1", | ||
"description": "Core functionality for Snowplow JavaScript trackers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
627843
6421