@snowplow/tracker-core
Advanced tools
Comparing version 3.0.0-alpha.3 to 3.0.0-alpha.4
@@ -6,2 +6,14 @@ /** | ||
/** | ||
* An array of tuples which represented the unprocessed JSON to be added to the Payload | ||
*/ | ||
type JsonForProcessing = Array<[ | ||
keyIfEncoded: string, | ||
keyIfNotEncoded: string, | ||
json: Record<string, unknown> | ||
]>; | ||
/** | ||
* A function which will processor the Json onto the injected PayloadBuilder | ||
*/ | ||
type JsonProcessor = (payloadBuilder: PayloadBuilder, jsonForProcessing: JsonForProcessing) => void; | ||
/** | ||
* Interface for mutable object encapsulating tracker payload | ||
@@ -11,7 +23,2 @@ */ | ||
/** | ||
* Sets whether the JSON within the payload should be base64 encoded | ||
* @param base64 Toggle for base64 encoding | ||
*/ | ||
setBase64Encoding: (base64: boolean) => void; | ||
/** | ||
* Adds an entry to the Payload | ||
@@ -35,2 +42,8 @@ * @param key Key for Payload dictionary entry | ||
/** | ||
* Adds a function which will be executed when building | ||
* the payload to process the JSON which has been added to this payload | ||
* @param jsonProcessor The JsonProcessor function for this builder | ||
*/ | ||
withJsonProcessor: (jsonProcessor: JsonProcessor) => void; | ||
/** | ||
* Builds and returns the Payload | ||
@@ -41,3 +54,11 @@ * @param base64Encode configures if cached json should be encoded | ||
} | ||
declare function payloadBuilder(): PayloadBuilder; | ||
/** | ||
* A helper to build a Snowplow request from a set of name-value pairs, provided using the add methods. | ||
* Will base64 encode JSON, if desired, on build | ||
* | ||
* @return The request builder, with add and build methods | ||
*/ | ||
declare function payloadJsonProcessor(encodeBase64: boolean): JsonProcessor; | ||
/** | ||
* Is property a non-empty JSON? | ||
@@ -53,9 +74,2 @@ * @param property Checks if object is non-empty json | ||
/** | ||
* A helper to build a Snowplow request from a set of name-value pairs, provided using the add methods. | ||
* Will base64 encode JSON, if desired, on build | ||
* | ||
* @return The request builder, with add and build methods | ||
*/ | ||
declare function payloadBuilder(): PayloadBuilder; | ||
/** | ||
* Interface which defines Core Plugins | ||
@@ -159,3 +173,3 @@ */ | ||
context?: Array<SelfDescribingJson> | null, /** Timestamp override */ | ||
timestamp?: Timestamp | null) => PayloadBuilder; | ||
timestamp?: Timestamp | null) => Payload; | ||
/** | ||
@@ -278,3 +292,9 @@ * Set a persistent key-value pair to be added to every payload | ||
removeGlobalContexts(contexts: Array<ConditionalContextProvider | ContextPrimitive>): void; | ||
addPlugin(plugin: CorePlugin): void; | ||
} | ||
interface CoreConfiguration { | ||
base64?: boolean; | ||
corePlugins?: Array<CorePlugin>; | ||
callback?: (PayloadData: PayloadBuilder) => void; | ||
} | ||
/** | ||
@@ -288,3 +308,3 @@ * Create a tracker core object | ||
*/ | ||
declare function trackerCore(base64?: boolean, corePlugins?: Array<CorePlugin>, callback?: (PayloadData: PayloadBuilder) => void): TrackerCore; | ||
declare function trackerCore(configuration?: CoreConfiguration): TrackerCore; | ||
/** | ||
@@ -1041,2 +1061,2 @@ * A Self Describing Event | ||
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, PayloadBuilder, isNonEmptyJson, isJson, payloadBuilder, SelfDescribingJson, SelfDescribingJsonArray, Timestamp, TrueTimestamp, DeviceTimestamp, CommonEventProperties, TrackerCore, 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, 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 }; |
/*! | ||
* Core functionality for Snowplow JavaScript trackers v3.0.0-alpha.3 (http://bit.ly/sp-js) | ||
* Core functionality for Snowplow JavaScript trackers v3.0.0-alpha.4 (http://bit.ly/sp-js) | ||
* Copyright 2021 Snowplow Analytics Ltd, 2010 Anthon Pang | ||
@@ -71,2 +71,3 @@ * Licensed under BSD-3-Clause | ||
} | ||
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
/** | ||
@@ -94,3 +95,2 @@ * Encode string as base64. | ||
// returns 3: '4pyTIMOgIGxhIG1vZGU=' | ||
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0; | ||
@@ -155,3 +155,2 @@ var tmp_arr = []; | ||
}; | ||
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = ''; | ||
@@ -216,39 +215,5 @@ var tmpArr = []; | ||
*/ | ||
/** | ||
* Is property a non-empty JSON? | ||
* @param property Checks if object is non-empty json | ||
*/ | ||
function isNonEmptyJson(property) { | ||
if (!isJson(property)) { | ||
return false; | ||
} | ||
for (var key in property) { | ||
if (Object.prototype.hasOwnProperty.call(property, key)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
/** | ||
* Is property a JSON? | ||
* @param property Checks if object is json | ||
*/ | ||
function isJson(property) { | ||
return (typeof property !== 'undefined' && | ||
property !== null && | ||
(property.constructor === {}.constructor || property.constructor === [].constructor)); | ||
} | ||
/** | ||
* A helper to build a Snowplow request from a set of name-value pairs, provided using the add methods. | ||
* Will base64 encode JSON, if desired, on build | ||
* | ||
* @return The request builder, with add and build methods | ||
*/ | ||
function payloadBuilder() { | ||
var dict = {}; | ||
var jsonForEncoding = []; | ||
var encodeBase64 = true; | ||
var setBase64Encoding = function (base64) { | ||
encodeBase64 = base64; | ||
}; | ||
var dict = {}, jsonForProcessing = []; | ||
var processor; | ||
var add = function (key, value) { | ||
@@ -269,27 +234,63 @@ if (value != null && value !== '') { | ||
if (json && isNonEmptyJson(json)) { | ||
jsonForEncoding.push([keyIfEncoded, keyIfNotEncoded, json]); | ||
jsonForProcessing.push([keyIfEncoded, keyIfNotEncoded, json]); | ||
} | ||
}; | ||
var build = function () { | ||
for (var _i = 0, jsonForEncoding_1 = jsonForEncoding; _i < jsonForEncoding_1.length; _i++) { | ||
var json = jsonForEncoding_1[_i]; | ||
return { | ||
add: add, | ||
addDict: addDict, | ||
addJson: addJson, | ||
withJsonProcessor: function (jsonProcessor) { | ||
processor = jsonProcessor; | ||
}, | ||
build: function () { | ||
processor === null || processor === void 0 ? void 0 : processor(this, jsonForProcessing); | ||
return dict; | ||
} | ||
}; | ||
} | ||
/** | ||
* A helper to build a Snowplow request from a set of name-value pairs, provided using the add methods. | ||
* Will base64 encode JSON, if desired, on build | ||
* | ||
* @return The request builder, with add and build methods | ||
*/ | ||
function payloadJsonProcessor(encodeBase64) { | ||
return function (payloadBuilder, jsonForProcessing) { | ||
for (var _i = 0, jsonForProcessing_1 = jsonForProcessing; _i < jsonForProcessing_1.length; _i++) { | ||
var json = jsonForProcessing_1[_i]; | ||
var str = JSON.stringify(json[2]); | ||
if (encodeBase64) { | ||
add(json[0], base64urlencode(str)); | ||
payloadBuilder.add(json[0], base64urlencode(str)); | ||
} | ||
else { | ||
add(json[1], str); | ||
payloadBuilder.add(json[1], str); | ||
} | ||
} | ||
jsonForEncoding.length = 0; | ||
return dict; | ||
jsonForProcessing.length = 0; | ||
}; | ||
return { | ||
setBase64Encoding: setBase64Encoding, | ||
add: add, | ||
addDict: addDict, | ||
addJson: addJson, | ||
build: build | ||
}; | ||
} | ||
/** | ||
* Is property a non-empty JSON? | ||
* @param property Checks if object is non-empty json | ||
*/ | ||
function isNonEmptyJson(property) { | ||
if (!isJson(property)) { | ||
return false; | ||
} | ||
for (var key in property) { | ||
if (Object.prototype.hasOwnProperty.call(property, key)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
/** | ||
* Is property a JSON? | ||
* @param property Checks if object is json | ||
*/ | ||
function isJson(property) { | ||
return (typeof property !== 'undefined' && | ||
property !== null && | ||
(property.constructor === {}.constructor || property.constructor === [].constructor)); | ||
} | ||
@@ -923,157 +924,171 @@ /* | ||
*/ | ||
function trackerCore(base64, corePlugins, callback) { | ||
var plugins = corePlugins !== null && corePlugins !== void 0 ? corePlugins : [], pluginContextsHelper = pluginContexts(plugins), globalContextsHelper = globalContexts(); | ||
var encodeBase64 = base64 !== null && base64 !== void 0 ? base64 : true, payloadPairs = {}; // Dictionary of key-value pairs which get added to every payload, e.g. tracker version | ||
/** | ||
* Wraps an array of custom contexts in a self-describing JSON | ||
* | ||
* @param contexts Array of custom context self-describing JSONs | ||
* @return Outer JSON | ||
*/ | ||
function completeContexts(contexts) { | ||
if (contexts && contexts.length) { | ||
return { | ||
schema: 'iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0', | ||
data: contexts | ||
}; | ||
function trackerCore(configuration) { | ||
if (configuration === void 0) { configuration = {}; } | ||
function newCore(base64, corePlugins, callback) { | ||
var pluginContextsHelper = pluginContexts(corePlugins), globalContextsHelper = globalContexts(); | ||
var encodeBase64 = base64, payloadPairs = {}; // Dictionary of key-value pairs which get added to every payload, e.g. tracker version | ||
/** | ||
* Wraps an array of custom contexts in a self-describing JSON | ||
* | ||
* @param contexts Array of custom context self-describing JSONs | ||
* @return Outer JSON | ||
*/ | ||
function completeContexts(contexts) { | ||
if (contexts && contexts.length) { | ||
return { | ||
schema: 'iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0', | ||
data: contexts | ||
}; | ||
} | ||
return undefined; | ||
} | ||
return undefined; | ||
} | ||
/** | ||
* Adds all global contexts to a contexts array | ||
* | ||
* @param pb PayloadData | ||
* @param contexts Custom contexts relating to the event | ||
*/ | ||
function attachGlobalContexts(pb, contexts) { | ||
var applicableContexts = globalContextsHelper.getApplicableContexts(pb); | ||
var returnedContexts = []; | ||
if (contexts && contexts.length) { | ||
returnedContexts.push.apply(returnedContexts, contexts); | ||
/** | ||
* Adds all global contexts to a contexts array | ||
* | ||
* @param pb PayloadData | ||
* @param contexts Custom contexts relating to the event | ||
*/ | ||
function attachGlobalContexts(pb, contexts) { | ||
var applicableContexts = globalContextsHelper.getApplicableContexts(pb); | ||
var returnedContexts = []; | ||
if (contexts && contexts.length) { | ||
returnedContexts.push.apply(returnedContexts, contexts); | ||
} | ||
if (applicableContexts && applicableContexts.length) { | ||
returnedContexts.push.apply(returnedContexts, applicableContexts); | ||
} | ||
return returnedContexts; | ||
} | ||
if (applicableContexts && applicableContexts.length) { | ||
returnedContexts.push.apply(returnedContexts, applicableContexts); | ||
} | ||
return returnedContexts; | ||
} | ||
/** | ||
* Gets called by every trackXXX method | ||
* Adds context and payloadPairs name-value pairs to the payload | ||
* Applies the callback to the built payload | ||
* | ||
* @param pb Payload | ||
* @param context Custom contexts relating to the event | ||
* @param timestamp Timestamp of the event | ||
* @return Payload after the callback is applied | ||
*/ | ||
function track(pb, context, timestamp) { | ||
pb.setBase64Encoding(encodeBase64); | ||
pb.add('eid', uuid.v4()); | ||
pb.addDict(payloadPairs); | ||
var tstamp = getTimestamp(timestamp); | ||
pb.add(tstamp.type, tstamp.value.toString()); | ||
var allContexts = attachGlobalContexts(pb, pluginContextsHelper.addPluginContexts(context)); | ||
var wrappedContexts = completeContexts(allContexts); | ||
if (wrappedContexts !== undefined) { | ||
pb.addJson('cx', 'co', wrappedContexts); | ||
} | ||
plugins.forEach(function (plugin) { | ||
try { | ||
if (plugin.beforeTrack) { | ||
plugin.beforeTrack(pb); | ||
/** | ||
* Gets called by every trackXXX method | ||
* Adds context and payloadPairs name-value pairs to the payload | ||
* Applies the callback to the built payload | ||
* | ||
* @param pb Payload | ||
* @param context Custom contexts relating to the event | ||
* @param timestamp Timestamp of the event | ||
* @return Payload after the callback is applied | ||
*/ | ||
function track(pb, context, timestamp) { | ||
pb.withJsonProcessor(payloadJsonProcessor(encodeBase64)); | ||
pb.add('eid', uuid.v4()); | ||
pb.addDict(payloadPairs); | ||
var tstamp = getTimestamp(timestamp); | ||
pb.add(tstamp.type, tstamp.value.toString()); | ||
var allContexts = attachGlobalContexts(pb, pluginContextsHelper.addPluginContexts(context)); | ||
var wrappedContexts = completeContexts(allContexts); | ||
if (wrappedContexts !== undefined) { | ||
pb.addJson('cx', 'co', wrappedContexts); | ||
} | ||
corePlugins.forEach(function (plugin) { | ||
try { | ||
if (plugin.beforeTrack) { | ||
plugin.beforeTrack(pb); | ||
} | ||
} | ||
catch (ex) { | ||
console.warn('Snowplow: error with plugin beforeTrack', ex); | ||
} | ||
}); | ||
if (typeof callback === 'function') { | ||
callback(pb); | ||
} | ||
catch (ex) { | ||
console.warn('Snowplow: error with plugin beforeTrack', ex); | ||
} | ||
}); | ||
if (typeof callback === 'function') { | ||
callback(pb); | ||
var finalPayload = pb.build(); | ||
corePlugins.forEach(function (plugin) { | ||
try { | ||
if (plugin.afterTrack) { | ||
plugin.afterTrack(finalPayload); | ||
} | ||
} | ||
catch (ex) { | ||
console.warn('Snowplow: error with plugin ', ex); | ||
} | ||
}); | ||
return finalPayload; | ||
} | ||
plugins.forEach(function (plugin) { | ||
try { | ||
if (plugin.afterTrack) { | ||
plugin.afterTrack(pb.build()); | ||
/** | ||
* Set a persistent key-value pair to be added to every payload | ||
* | ||
* @param key Field name | ||
* @param value Field value | ||
*/ | ||
function addPayloadPair(key, value) { | ||
payloadPairs[key] = value; | ||
} | ||
var core = { | ||
track: track, | ||
addPayloadPair: addPayloadPair, | ||
getBase64Encoding: function () { | ||
return encodeBase64; | ||
}, | ||
setBase64Encoding: function (encode) { | ||
encodeBase64 = encode; | ||
}, | ||
addPayloadDict: function (dict) { | ||
for (var key in dict) { | ||
if (Object.prototype.hasOwnProperty.call(dict, key)) { | ||
payloadPairs[key] = dict[key]; | ||
} | ||
} | ||
}, | ||
resetPayloadPairs: function (dict) { | ||
payloadPairs = isJson(dict) ? dict : {}; | ||
}, | ||
setTrackerVersion: function (version) { | ||
addPayloadPair('tv', version); | ||
}, | ||
setTrackerNamespace: function (name) { | ||
addPayloadPair('tna', name); | ||
}, | ||
setAppId: function (appId) { | ||
addPayloadPair('aid', appId); | ||
}, | ||
setPlatform: function (value) { | ||
addPayloadPair('p', value); | ||
}, | ||
setUserId: function (userId) { | ||
addPayloadPair('uid', userId); | ||
}, | ||
setScreenResolution: function (width, height) { | ||
addPayloadPair('res', width + 'x' + height); | ||
}, | ||
setViewport: function (width, height) { | ||
addPayloadPair('vp', width + 'x' + height); | ||
}, | ||
setColorDepth: function (depth) { | ||
addPayloadPair('cd', depth); | ||
}, | ||
setTimezone: function (timezone) { | ||
addPayloadPair('tz', timezone); | ||
}, | ||
setLang: function (lang) { | ||
addPayloadPair('lang', lang); | ||
}, | ||
setIpAddress: function (ip) { | ||
addPayloadPair('ip', ip); | ||
}, | ||
setUseragent: function (useragent) { | ||
addPayloadPair('ua', useragent); | ||
}, | ||
addGlobalContexts: function (contexts) { | ||
globalContextsHelper.addGlobalContexts(contexts); | ||
}, | ||
clearGlobalContexts: function () { | ||
globalContextsHelper.clearGlobalContexts(); | ||
}, | ||
removeGlobalContexts: function (contexts) { | ||
globalContextsHelper.removeGlobalContexts(contexts); | ||
} | ||
catch (ex) { | ||
console.warn('Snowplow: error with plugin ', ex); | ||
} | ||
}); | ||
return pb; | ||
}; | ||
return core; | ||
} | ||
/** | ||
* Set a persistent key-value pair to be added to every payload | ||
* | ||
* @param key Field name | ||
* @param value Field value | ||
*/ | ||
function addPayloadPair(key, value) { | ||
payloadPairs[key] = value; | ||
} | ||
var core = { | ||
track: track, | ||
addPayloadPair: addPayloadPair, | ||
getBase64Encoding: function () { | ||
return encodeBase64; | ||
}, | ||
setBase64Encoding: function (encode) { | ||
encodeBase64 = encode; | ||
}, | ||
addPayloadDict: function (dict) { | ||
for (var key in dict) { | ||
if (Object.prototype.hasOwnProperty.call(dict, key)) { | ||
payloadPairs[key] = dict[key]; | ||
} | ||
} | ||
}, | ||
resetPayloadPairs: function (dict) { | ||
payloadPairs = isJson(dict) ? dict : {}; | ||
}, | ||
setTrackerVersion: function (version) { | ||
addPayloadPair('tv', version); | ||
}, | ||
setTrackerNamespace: function (name) { | ||
addPayloadPair('tna', name); | ||
}, | ||
setAppId: function (appId) { | ||
addPayloadPair('aid', appId); | ||
}, | ||
setPlatform: function (value) { | ||
addPayloadPair('p', value); | ||
}, | ||
setUserId: function (userId) { | ||
addPayloadPair('uid', userId); | ||
}, | ||
setScreenResolution: function (width, height) { | ||
addPayloadPair('res', width + 'x' + height); | ||
}, | ||
setViewport: function (width, height) { | ||
addPayloadPair('vp', width + 'x' + height); | ||
}, | ||
setColorDepth: function (depth) { | ||
addPayloadPair('cd', depth); | ||
}, | ||
setTimezone: function (timezone) { | ||
addPayloadPair('tz', timezone); | ||
}, | ||
setLang: function (lang) { | ||
addPayloadPair('lang', lang); | ||
}, | ||
setIpAddress: function (ip) { | ||
addPayloadPair('ip', ip); | ||
}, | ||
setUseragent: function (useragent) { | ||
addPayloadPair('ua', useragent); | ||
}, | ||
addGlobalContexts: function (contexts) { | ||
globalContextsHelper.addGlobalContexts(contexts); | ||
}, | ||
clearGlobalContexts: function () { | ||
globalContextsHelper.clearGlobalContexts(); | ||
}, | ||
removeGlobalContexts: function (contexts) { | ||
globalContextsHelper.removeGlobalContexts(contexts); | ||
} | ||
}; | ||
var base64 = configuration.base64, corePlugins = configuration.corePlugins, callback = configuration.callback, plugins = corePlugins !== null && corePlugins !== void 0 ? corePlugins : [], partialCore = newCore(base64 !== null && base64 !== void 0 ? base64 : true, plugins, callback), core = tslib.__assign(tslib.__assign({}, partialCore), { addPlugin: function (plugin) { | ||
var _a; | ||
plugins.push(plugin); | ||
(_a = plugin.activateCorePlugin) === null || _a === void 0 ? void 0 : _a.call(plugin, core); | ||
} }); | ||
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); | ||
}); | ||
return core; | ||
@@ -1548,2 +1563,3 @@ } | ||
exports.payloadBuilder = payloadBuilder; | ||
exports.payloadJsonProcessor = payloadJsonProcessor; | ||
exports.pluginContexts = pluginContexts; | ||
@@ -1550,0 +1566,0 @@ exports.resolveDynamicContext = resolveDynamicContext; |
@@ -6,2 +6,14 @@ /** | ||
/** | ||
* An array of tuples which represented the unprocessed JSON to be added to the Payload | ||
*/ | ||
type JsonForProcessing = Array<[ | ||
keyIfEncoded: string, | ||
keyIfNotEncoded: string, | ||
json: Record<string, unknown> | ||
]>; | ||
/** | ||
* A function which will processor the Json onto the injected PayloadBuilder | ||
*/ | ||
type JsonProcessor = (payloadBuilder: PayloadBuilder, jsonForProcessing: JsonForProcessing) => void; | ||
/** | ||
* Interface for mutable object encapsulating tracker payload | ||
@@ -11,7 +23,2 @@ */ | ||
/** | ||
* Sets whether the JSON within the payload should be base64 encoded | ||
* @param base64 Toggle for base64 encoding | ||
*/ | ||
setBase64Encoding: (base64: boolean) => void; | ||
/** | ||
* Adds an entry to the Payload | ||
@@ -35,2 +42,8 @@ * @param key Key for Payload dictionary entry | ||
/** | ||
* Adds a function which will be executed when building | ||
* the payload to process the JSON which has been added to this payload | ||
* @param jsonProcessor The JsonProcessor function for this builder | ||
*/ | ||
withJsonProcessor: (jsonProcessor: JsonProcessor) => void; | ||
/** | ||
* Builds and returns the Payload | ||
@@ -41,3 +54,11 @@ * @param base64Encode configures if cached json should be encoded | ||
} | ||
declare function payloadBuilder(): PayloadBuilder; | ||
/** | ||
* A helper to build a Snowplow request from a set of name-value pairs, provided using the add methods. | ||
* Will base64 encode JSON, if desired, on build | ||
* | ||
* @return The request builder, with add and build methods | ||
*/ | ||
declare function payloadJsonProcessor(encodeBase64: boolean): JsonProcessor; | ||
/** | ||
* Is property a non-empty JSON? | ||
@@ -53,9 +74,2 @@ * @param property Checks if object is non-empty json | ||
/** | ||
* A helper to build a Snowplow request from a set of name-value pairs, provided using the add methods. | ||
* Will base64 encode JSON, if desired, on build | ||
* | ||
* @return The request builder, with add and build methods | ||
*/ | ||
declare function payloadBuilder(): PayloadBuilder; | ||
/** | ||
* Interface which defines Core Plugins | ||
@@ -159,3 +173,3 @@ */ | ||
context?: Array<SelfDescribingJson> | null, /** Timestamp override */ | ||
timestamp?: Timestamp | null) => PayloadBuilder; | ||
timestamp?: Timestamp | null) => Payload; | ||
/** | ||
@@ -278,3 +292,9 @@ * Set a persistent key-value pair to be added to every payload | ||
removeGlobalContexts(contexts: Array<ConditionalContextProvider | ContextPrimitive>): void; | ||
addPlugin(plugin: CorePlugin): void; | ||
} | ||
interface CoreConfiguration { | ||
base64?: boolean; | ||
corePlugins?: Array<CorePlugin>; | ||
callback?: (PayloadData: PayloadBuilder) => void; | ||
} | ||
/** | ||
@@ -288,3 +308,3 @@ * Create a tracker core object | ||
*/ | ||
declare function trackerCore(base64?: boolean, corePlugins?: Array<CorePlugin>, callback?: (PayloadData: PayloadBuilder) => void): TrackerCore; | ||
declare function trackerCore(configuration?: CoreConfiguration): TrackerCore; | ||
/** | ||
@@ -1041,2 +1061,2 @@ * A Self Describing Event | ||
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, PayloadBuilder, isNonEmptyJson, isJson, payloadBuilder, SelfDescribingJson, SelfDescribingJsonArray, Timestamp, TrueTimestamp, DeviceTimestamp, CommonEventProperties, TrackerCore, 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, 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 }; |
/*! | ||
* Core functionality for Snowplow JavaScript trackers v3.0.0-alpha.3 (http://bit.ly/sp-js) | ||
* Core functionality for Snowplow JavaScript trackers v3.0.0-alpha.4 (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="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e.charAt(n++)),i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e.charAt(n++));r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e.charAt(n++));var c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".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(!r(e))return!1;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n))return!0;return!1}function r(e){return null!=e&&(e.constructor==={}.constructor||e.constructor===[].constructor)}function o(){var e={},n=[],r=!0,o=function(n,t){null!=t&&""!==t&&(e[n]=t)};return{setBase64Encoding:function(e){r=e},add:o,addDict:function(e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&o(n,e[n])},addJson:function(e,r,o){o&&t(o)&&n.push([e,r,o])},build:function(){for(var t=0;t<n.length;t++){var a=n[t],i=JSON.stringify(a[2]);if(r){if(a=a[0],i){var c=0,s=0,l=[];if(i){i=unescape(encodeURIComponent(i));do{var u=i.charCodeAt(c++),d=i.charCodeAt(c++),f=i.charCodeAt(c++),p=u<<16|d<<8|f;u=p>>18&63,d=p>>12&63,f=p>>6&63,p&=63,l[s++]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(u)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(d)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(f)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(p)}while(c<i.length);c=l.join(""),i=((i=i.length%3)?c.slice(0,i-3):c)+"===".slice(i||3)}i=i.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}o(a,i)}else o(a[1],i)}return n.length=0,e}}}function a(){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];C(i)?r.push(i):h(i)&&o.push(i)}e=e.concat(o),t=t.concat(r)},clearGlobalContexts:function(){t=[],e=[]},removeGlobalContexts:function(n){for(var r=function(n){C(n)?t=t.filter((function(e){return JSON.stringify(e)===JSON.stringify(n)})):h(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(v(r=r.build())){r=P({},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=j(e,o,a,r),p.push.apply(p,i),a=function(e,n,t,r){var o;return e=I(e).map((function(e){e:{if(w(e)){var o=e[0],a=!1;try{a=o({event:n,eventType:t,eventSchema:r})}catch(e){a=!1}if(!0===a){e=j(e[1],n,t,r);break e}}else if(b(e)&&_(e[0],r)){e=j(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 i(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 c(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 s(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 l(e){return!!((e=e.split("."))&&1<e.length)&&s(e)}function u(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))&&l(e[1]))return e.slice(1,6)}function d(e){if(e=u(e)){var n=e[0];return 5===e.length&&l(n)}return!1}function f(e){return Array.isArray(e)&&e.every((function(e){return"string"==typeof e}))}function p(e){return f(e)?e.every((function(e){return d(e)})):"string"==typeof e&&d(e)}function m(e){return!!(t(e)&&"schema"in e&&"data"in e)&&("string"==typeof e.schema&&"object"==typeof e.data)}function v(e){return!(!t(e)||!("e"in e))&&"string"==typeof e.e}function y(e){var n=0;if(null!=e&&"object"==typeof e&&!Array.isArray(e)){if(Object.prototype.hasOwnProperty.call(e,"accept")){if(!p(e.accept))return!1;n+=1}if(Object.prototype.hasOwnProperty.call(e,"reject")){if(!p(e.reject))return!1;n+=1}return 0<n&&2>=n}return!1}function g(e){return"function"==typeof e&&1>=e.length}function h(e){return g(e)||m(e)}function w(e){return!(!Array.isArray(e)||2!==e.length)&&(Array.isArray(e[1])?g(e[0])&&e[1].every(h):g(e[0])&&h(e[1]))}function b(e){return!(!Array.isArray(e)||2!==e.length)&&(!!y(e[0])&&(Array.isArray(e[1])?e[1].every(h):h(e[1])))}function C(e){return w(e)||b(e)}function _(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(!d(e))return!1;if(e=u(e),n=c(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(!A(n[t],e[t]))return!1;return!0}return!1}(e[0],n[0]))return!1;for(var t=1;5>t;t++)if(!A(e[t],n[t]))return!1;return!0}return!1}function A(e,n){return e&&n&&"*"===e||e===n}function I(e){return Array.isArray(e)?e:[e]}function j(e,n,t,r){var o;return e=I(e).map((function(e){e:if(m(e))e=[e];else{if(g(e)){n:{var o=void 0;try{if(o=e({event:n,eventType:t,eventSchema:r}),Array.isArray(o)&&o.every(m)||m(o)){var a=o;break n}a=void 0;break n}catch(e){}a=void 0}if(m(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 S(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=o()).add("e","ue"),n.addJson("ue_px","ue_pr",e),n}function k(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 P=function(){return(P=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)},O=(R=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}}}(R={exports:{}}),R.exports),T=[],N=0;256>N;++N)T[N]=(N+256).toString(16).substr(1);var R,E,V,J=function(e,n){return n=n||0,[T[e[n++]],T[e[n++]],T[e[n++]],T[e[n++]],"-",T[e[n++]],T[e[n++]],"-",T[e[n++]],T[e[n++]],"-",T[e[n++]],T[e[n++]],"-",T[e[n++]],T[e[n++]],T[e[n++]],T[e[n++]],T[e[n++]],T[e[n++]]].join("")},U=0,z=0,G=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||O)())[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||J(e)};G.v1=function(e,n,t){t=n&&t||0;var r=n||[],o=(e=e||{}).node||E,a=void 0!==e.clockseq?e.clockseq:V;if(null==o||null==a){var i=O();null==o&&(o=E=[1|i[0],i[1],i[2],i[3],i[4],i[5]]),null==a&&(a=V=16383&(i[6]<<8|i[7]))}i=void 0!==e.msecs?e.msecs:(new Date).getTime();var c=void 0!==e.nsecs?e.nsecs:z+1,s=i-U+(c-z)/1e4;if(0>s&&void 0===e.clockseq&&(a=a+1&16383),(0>s||i>U)&&void 0===e.nsecs&&(c=0),1e4<=c)throw Error("uuid.v1(): Can't create more than 10M uuids/sec");for(U=i,z=c,V=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||J(r)},G.v4=G,e.buildAdClick=function(e){return S({event:e={schema:"iglu:com.snowplowanalytics.snowplow/ad_click/jsonschema/1-0-0",data:k({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 S({event:e={schema:"iglu:com.snowplowanalytics.snowplow/ad_conversion/jsonschema/1-0-0",data:k({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 S({event:e={schema:"iglu:com.snowplowanalytics.snowplow/ad_impression/jsonschema/1-0-0",data:k({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 S({event:{schema:"iglu:com.snowplowanalytics.snowplow/add_to_cart/jsonschema/1-0-0",data:k({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:k({id:e.id,version:e.version,name:e.name,description:e.description})},{event:S({event:{schema:"iglu:com.snowplowanalytics.snowplow/consent_granted/jsonschema/1-0-0",data:k({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:k({id:e.id,version:e.version,name:e.name,description:e.description})},{event:S({event:{schema:"iglu:com.snowplowanalytics.snowplow/consent_withdrawn/jsonschema/1-0-0",data:k({all:n})}}),context:[e]}},e.buildEcommerceTransaction=function(e){var n=e.orderId,t=e.total,r=e.affiliation,a=e.tax,i=e.shipping,c=e.city,s=e.state,l=e.country;e=e.currency;var u=o();return u.add("e","tr"),u.add("tr_id",n),u.add("tr_af",r),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,r=e.price,a=e.name,i=e.category,c=e.quantity;e=e.currency;var s=o();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",r),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),S({event:{schema:n,data:k(e,{value:!0})}})},e.buildFormSubmission=function(e){return S({event:{schema:"iglu:com.snowplowanalytics.snowplow/submit_form/jsonschema/1-0-0",data:k({formId:e.formId,formClasses:e.formClasses,elements:e.elements})}})},e.buildLinkClick=function(e){return S({event:e={schema:"iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1",data:k({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,r=e.referrer,a=e.minXOffset,i=e.maxXOffset,c=e.minYOffset;e=e.maxYOffset;var s=o();return s.add("e","pp"),s.add("url",n),s.add("page",t),s.add("refr",r),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 r=o();return r.add("e","pv"),r.add("url",n),r.add("page",t),r.add("refr",e),r},e.buildRemoveFromCart=function(e){return S({event:{schema:"iglu:com.snowplowanalytics.snowplow/remove_from_cart/jsonschema/1-0-0",data:k({sku:e.sku,quantity:e.quantity,name:e.name,category:e.category,unitPrice:e.unitPrice,currency:e.currency})}})},e.buildScreenView=function(e){return S({event:{schema:"iglu:com.snowplowanalytics.snowplow/screen_view/jsonschema/1-0-0",data:k({name:e.name,id:e.id})}})},e.buildSelfDescribingEvent=S,e.buildSiteSearch=function(e){return S({event:{schema:"iglu:com.snowplowanalytics.snowplow/site_search/jsonschema/1-0-0",data:k({terms:e.terms,filters:e.filters,totalResults:e.totalResults,pageResults:e.pageResults})}})},e.buildSocialInteraction=function(e){return S({event:e={schema:"iglu:com.snowplowanalytics.snowplow/social_interaction/jsonschema/1-0-0",data:k({action:e.action,network:e.network,target:e.target})}})},e.buildStructEvent=function(e){var n=e.category,t=e.action,r=e.label,a=e.property;e=e.value;var i=o();return i.add("e","se"),i.add("se_ca",n),i.add("se_ac",t),i.add("se_la",r),i.add("se_pr",a),i.add("se_va",null==e?void 0:e.toString()),i},e.getRuleParts=u,e.getSchemaParts=c,e.globalContexts=a,e.isConditionalContextProvider=C,e.isContextCallbackFunction=g,e.isContextPrimitive=h,e.isEventJson=v,e.isFilterProvider=w,e.isJson=r,e.isNonEmptyJson=t,e.isRuleSet=y,e.isRuleSetProvider=b,e.isSelfDescribingJson=m,e.isStringArray=f,e.isValidRule=d,e.isValidRuleSetArg=p,e.matchSchemaAgainstRule=x,e.matchSchemaAgainstRuleSet=_,e.payloadBuilder=o,e.pluginContexts=i,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,n,t){var o=null!=n?n:[],c=i(o),s=a(),l=null==e||e,u={};return{track:function(e,n,r){return e.setBase64Encoding(l),e.add("eid",G.v4()),e.addDict(u),r=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()}}(r),e.add(r.type,r.value.toString()),void 0!==(n=(n=function(e,n){e=s.getApplicableContexts(e);var t=[];return n&&n.length&&t.push.apply(t,n),e&&e.length&&t.push.apply(t,e),t}(e,c.addPluginContexts(n)))&&n.length?{schema:"iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0",data:n}:void 0)&&e.addJson("cx","co",n),o.forEach((function(n){try{n.beforeTrack&&n.beforeTrack(e)}catch(e){console.warn("Snowplow: error with plugin beforeTrack",e)}})),"function"==typeof t&&t(e),o.forEach((function(n){try{n.afterTrack&&n.afterTrack(e.build())}catch(e){console.warn("Snowplow: error with plugin ",e)}})),e},addPayloadPair:function(e,n){u[e]=n},getBase64Encoding:function(){return l},setBase64Encoding:function(e){l=e},addPayloadDict:function(e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(u[n]=e[n])},resetPayloadPairs:function(e){u=r(e)?e:{}},setTrackerVersion:function(e){u.tv=e},setTrackerNamespace:function(e){u.tna=e},setAppId:function(e){u.aid=e},setPlatform:function(e){u.p=e},setUserId:function(e){u.uid=e},setScreenResolution:function(e,n){u.res=e+"x"+n},setViewport:function(e,n){u.vp=e+"x"+n},setColorDepth:function(e){u.cd=e},setTimezone:function(e){u.tz=e},setLang:function(e){u.lang=e},setIpAddress:function(e){u.ip=e},setUseragent:function(e){u.ua=e},addGlobalContexts:function(e){s.addGlobalContexts(e)},clearGlobalContexts:function(){s.clearGlobalContexts()},removeGlobalContexts:function(e){s.removeGlobalContexts(e)}}},e.validateVendor=l,e.validateVendorParts=s,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;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})})); | ||
//# sourceMappingURL=index.min.js.map |
@@ -6,2 +6,14 @@ /** | ||
/** | ||
* An array of tuples which represented the unprocessed JSON to be added to the Payload | ||
*/ | ||
type JsonForProcessing = Array<[ | ||
keyIfEncoded: string, | ||
keyIfNotEncoded: string, | ||
json: Record<string, unknown> | ||
]>; | ||
/** | ||
* A function which will processor the Json onto the injected PayloadBuilder | ||
*/ | ||
type JsonProcessor = (payloadBuilder: PayloadBuilder, jsonForProcessing: JsonForProcessing) => void; | ||
/** | ||
* Interface for mutable object encapsulating tracker payload | ||
@@ -11,7 +23,2 @@ */ | ||
/** | ||
* Sets whether the JSON within the payload should be base64 encoded | ||
* @param base64 Toggle for base64 encoding | ||
*/ | ||
setBase64Encoding: (base64: boolean) => void; | ||
/** | ||
* Adds an entry to the Payload | ||
@@ -35,2 +42,8 @@ * @param key Key for Payload dictionary entry | ||
/** | ||
* Adds a function which will be executed when building | ||
* the payload to process the JSON which has been added to this payload | ||
* @param jsonProcessor The JsonProcessor function for this builder | ||
*/ | ||
withJsonProcessor: (jsonProcessor: JsonProcessor) => void; | ||
/** | ||
* Builds and returns the Payload | ||
@@ -41,3 +54,11 @@ * @param base64Encode configures if cached json should be encoded | ||
} | ||
declare function payloadBuilder(): PayloadBuilder; | ||
/** | ||
* A helper to build a Snowplow request from a set of name-value pairs, provided using the add methods. | ||
* Will base64 encode JSON, if desired, on build | ||
* | ||
* @return The request builder, with add and build methods | ||
*/ | ||
declare function payloadJsonProcessor(encodeBase64: boolean): JsonProcessor; | ||
/** | ||
* Is property a non-empty JSON? | ||
@@ -53,9 +74,2 @@ * @param property Checks if object is non-empty json | ||
/** | ||
* A helper to build a Snowplow request from a set of name-value pairs, provided using the add methods. | ||
* Will base64 encode JSON, if desired, on build | ||
* | ||
* @return The request builder, with add and build methods | ||
*/ | ||
declare function payloadBuilder(): PayloadBuilder; | ||
/** | ||
* Interface which defines Core Plugins | ||
@@ -159,3 +173,3 @@ */ | ||
context?: Array<SelfDescribingJson> | null, /** Timestamp override */ | ||
timestamp?: Timestamp | null) => PayloadBuilder; | ||
timestamp?: Timestamp | null) => Payload; | ||
/** | ||
@@ -278,3 +292,9 @@ * Set a persistent key-value pair to be added to every payload | ||
removeGlobalContexts(contexts: Array<ConditionalContextProvider | ContextPrimitive>): void; | ||
addPlugin(plugin: CorePlugin): void; | ||
} | ||
interface CoreConfiguration { | ||
base64?: boolean; | ||
corePlugins?: Array<CorePlugin>; | ||
callback?: (PayloadData: PayloadBuilder) => void; | ||
} | ||
/** | ||
@@ -288,3 +308,3 @@ * Create a tracker core object | ||
*/ | ||
declare function trackerCore(base64?: boolean, corePlugins?: Array<CorePlugin>, callback?: (PayloadData: PayloadBuilder) => void): TrackerCore; | ||
declare function trackerCore(configuration?: CoreConfiguration): TrackerCore; | ||
/** | ||
@@ -1041,2 +1061,2 @@ * A Self Describing Event | ||
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, PayloadBuilder, isNonEmptyJson, isJson, payloadBuilder, SelfDescribingJson, SelfDescribingJsonArray, Timestamp, TrueTimestamp, DeviceTimestamp, CommonEventProperties, TrackerCore, 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, 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 }; |
/*! | ||
* Core functionality for Snowplow JavaScript trackers v3.0.0-alpha.3 (http://bit.ly/sp-js) | ||
* Core functionality for Snowplow JavaScript trackers v3.0.0-alpha.4 (http://bit.ly/sp-js) | ||
* Copyright 2021 Snowplow Analytics Ltd, 2010 Anthon Pang | ||
@@ -67,2 +67,3 @@ * Licensed under BSD-3-Clause | ||
} | ||
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
/** | ||
@@ -90,3 +91,2 @@ * Encode string as base64. | ||
// returns 3: '4pyTIMOgIGxhIG1vZGU=' | ||
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0; | ||
@@ -151,3 +151,2 @@ var tmp_arr = []; | ||
}; | ||
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = ''; | ||
@@ -212,39 +211,5 @@ var tmpArr = []; | ||
*/ | ||
/** | ||
* Is property a non-empty JSON? | ||
* @param property Checks if object is non-empty json | ||
*/ | ||
function isNonEmptyJson(property) { | ||
if (!isJson(property)) { | ||
return false; | ||
} | ||
for (var key in property) { | ||
if (Object.prototype.hasOwnProperty.call(property, key)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
/** | ||
* Is property a JSON? | ||
* @param property Checks if object is json | ||
*/ | ||
function isJson(property) { | ||
return (typeof property !== 'undefined' && | ||
property !== null && | ||
(property.constructor === {}.constructor || property.constructor === [].constructor)); | ||
} | ||
/** | ||
* A helper to build a Snowplow request from a set of name-value pairs, provided using the add methods. | ||
* Will base64 encode JSON, if desired, on build | ||
* | ||
* @return The request builder, with add and build methods | ||
*/ | ||
function payloadBuilder() { | ||
var dict = {}; | ||
var jsonForEncoding = []; | ||
var encodeBase64 = true; | ||
var setBase64Encoding = function (base64) { | ||
encodeBase64 = base64; | ||
}; | ||
var dict = {}, jsonForProcessing = []; | ||
var processor; | ||
var add = function (key, value) { | ||
@@ -265,27 +230,63 @@ if (value != null && value !== '') { | ||
if (json && isNonEmptyJson(json)) { | ||
jsonForEncoding.push([keyIfEncoded, keyIfNotEncoded, json]); | ||
jsonForProcessing.push([keyIfEncoded, keyIfNotEncoded, json]); | ||
} | ||
}; | ||
var build = function () { | ||
for (var _i = 0, jsonForEncoding_1 = jsonForEncoding; _i < jsonForEncoding_1.length; _i++) { | ||
var json = jsonForEncoding_1[_i]; | ||
return { | ||
add: add, | ||
addDict: addDict, | ||
addJson: addJson, | ||
withJsonProcessor: function (jsonProcessor) { | ||
processor = jsonProcessor; | ||
}, | ||
build: function () { | ||
processor === null || processor === void 0 ? void 0 : processor(this, jsonForProcessing); | ||
return dict; | ||
} | ||
}; | ||
} | ||
/** | ||
* A helper to build a Snowplow request from a set of name-value pairs, provided using the add methods. | ||
* Will base64 encode JSON, if desired, on build | ||
* | ||
* @return The request builder, with add and build methods | ||
*/ | ||
function payloadJsonProcessor(encodeBase64) { | ||
return function (payloadBuilder, jsonForProcessing) { | ||
for (var _i = 0, jsonForProcessing_1 = jsonForProcessing; _i < jsonForProcessing_1.length; _i++) { | ||
var json = jsonForProcessing_1[_i]; | ||
var str = JSON.stringify(json[2]); | ||
if (encodeBase64) { | ||
add(json[0], base64urlencode(str)); | ||
payloadBuilder.add(json[0], base64urlencode(str)); | ||
} | ||
else { | ||
add(json[1], str); | ||
payloadBuilder.add(json[1], str); | ||
} | ||
} | ||
jsonForEncoding.length = 0; | ||
return dict; | ||
jsonForProcessing.length = 0; | ||
}; | ||
return { | ||
setBase64Encoding: setBase64Encoding, | ||
add: add, | ||
addDict: addDict, | ||
addJson: addJson, | ||
build: build | ||
}; | ||
} | ||
/** | ||
* Is property a non-empty JSON? | ||
* @param property Checks if object is non-empty json | ||
*/ | ||
function isNonEmptyJson(property) { | ||
if (!isJson(property)) { | ||
return false; | ||
} | ||
for (var key in property) { | ||
if (Object.prototype.hasOwnProperty.call(property, key)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
/** | ||
* Is property a JSON? | ||
* @param property Checks if object is json | ||
*/ | ||
function isJson(property) { | ||
return (typeof property !== 'undefined' && | ||
property !== null && | ||
(property.constructor === {}.constructor || property.constructor === [].constructor)); | ||
} | ||
@@ -919,157 +920,171 @@ /* | ||
*/ | ||
function trackerCore(base64, corePlugins, callback) { | ||
var plugins = corePlugins !== null && corePlugins !== void 0 ? corePlugins : [], pluginContextsHelper = pluginContexts(plugins), globalContextsHelper = globalContexts(); | ||
var encodeBase64 = base64 !== null && base64 !== void 0 ? base64 : true, payloadPairs = {}; // Dictionary of key-value pairs which get added to every payload, e.g. tracker version | ||
/** | ||
* Wraps an array of custom contexts in a self-describing JSON | ||
* | ||
* @param contexts Array of custom context self-describing JSONs | ||
* @return Outer JSON | ||
*/ | ||
function completeContexts(contexts) { | ||
if (contexts && contexts.length) { | ||
return { | ||
schema: 'iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0', | ||
data: contexts | ||
}; | ||
function trackerCore(configuration) { | ||
if (configuration === void 0) { configuration = {}; } | ||
function newCore(base64, corePlugins, callback) { | ||
var pluginContextsHelper = pluginContexts(corePlugins), globalContextsHelper = globalContexts(); | ||
var encodeBase64 = base64, payloadPairs = {}; // Dictionary of key-value pairs which get added to every payload, e.g. tracker version | ||
/** | ||
* Wraps an array of custom contexts in a self-describing JSON | ||
* | ||
* @param contexts Array of custom context self-describing JSONs | ||
* @return Outer JSON | ||
*/ | ||
function completeContexts(contexts) { | ||
if (contexts && contexts.length) { | ||
return { | ||
schema: 'iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0', | ||
data: contexts | ||
}; | ||
} | ||
return undefined; | ||
} | ||
return undefined; | ||
} | ||
/** | ||
* Adds all global contexts to a contexts array | ||
* | ||
* @param pb PayloadData | ||
* @param contexts Custom contexts relating to the event | ||
*/ | ||
function attachGlobalContexts(pb, contexts) { | ||
var applicableContexts = globalContextsHelper.getApplicableContexts(pb); | ||
var returnedContexts = []; | ||
if (contexts && contexts.length) { | ||
returnedContexts.push.apply(returnedContexts, contexts); | ||
/** | ||
* Adds all global contexts to a contexts array | ||
* | ||
* @param pb PayloadData | ||
* @param contexts Custom contexts relating to the event | ||
*/ | ||
function attachGlobalContexts(pb, contexts) { | ||
var applicableContexts = globalContextsHelper.getApplicableContexts(pb); | ||
var returnedContexts = []; | ||
if (contexts && contexts.length) { | ||
returnedContexts.push.apply(returnedContexts, contexts); | ||
} | ||
if (applicableContexts && applicableContexts.length) { | ||
returnedContexts.push.apply(returnedContexts, applicableContexts); | ||
} | ||
return returnedContexts; | ||
} | ||
if (applicableContexts && applicableContexts.length) { | ||
returnedContexts.push.apply(returnedContexts, applicableContexts); | ||
} | ||
return returnedContexts; | ||
} | ||
/** | ||
* Gets called by every trackXXX method | ||
* Adds context and payloadPairs name-value pairs to the payload | ||
* Applies the callback to the built payload | ||
* | ||
* @param pb Payload | ||
* @param context Custom contexts relating to the event | ||
* @param timestamp Timestamp of the event | ||
* @return Payload after the callback is applied | ||
*/ | ||
function track(pb, context, timestamp) { | ||
pb.setBase64Encoding(encodeBase64); | ||
pb.add('eid', v4()); | ||
pb.addDict(payloadPairs); | ||
var tstamp = getTimestamp(timestamp); | ||
pb.add(tstamp.type, tstamp.value.toString()); | ||
var allContexts = attachGlobalContexts(pb, pluginContextsHelper.addPluginContexts(context)); | ||
var wrappedContexts = completeContexts(allContexts); | ||
if (wrappedContexts !== undefined) { | ||
pb.addJson('cx', 'co', wrappedContexts); | ||
} | ||
plugins.forEach(function (plugin) { | ||
try { | ||
if (plugin.beforeTrack) { | ||
plugin.beforeTrack(pb); | ||
/** | ||
* Gets called by every trackXXX method | ||
* Adds context and payloadPairs name-value pairs to the payload | ||
* Applies the callback to the built payload | ||
* | ||
* @param pb Payload | ||
* @param context Custom contexts relating to the event | ||
* @param timestamp Timestamp of the event | ||
* @return Payload after the callback is applied | ||
*/ | ||
function track(pb, context, timestamp) { | ||
pb.withJsonProcessor(payloadJsonProcessor(encodeBase64)); | ||
pb.add('eid', v4()); | ||
pb.addDict(payloadPairs); | ||
var tstamp = getTimestamp(timestamp); | ||
pb.add(tstamp.type, tstamp.value.toString()); | ||
var allContexts = attachGlobalContexts(pb, pluginContextsHelper.addPluginContexts(context)); | ||
var wrappedContexts = completeContexts(allContexts); | ||
if (wrappedContexts !== undefined) { | ||
pb.addJson('cx', 'co', wrappedContexts); | ||
} | ||
corePlugins.forEach(function (plugin) { | ||
try { | ||
if (plugin.beforeTrack) { | ||
plugin.beforeTrack(pb); | ||
} | ||
} | ||
catch (ex) { | ||
console.warn('Snowplow: error with plugin beforeTrack', ex); | ||
} | ||
}); | ||
if (typeof callback === 'function') { | ||
callback(pb); | ||
} | ||
catch (ex) { | ||
console.warn('Snowplow: error with plugin beforeTrack', ex); | ||
} | ||
}); | ||
if (typeof callback === 'function') { | ||
callback(pb); | ||
var finalPayload = pb.build(); | ||
corePlugins.forEach(function (plugin) { | ||
try { | ||
if (plugin.afterTrack) { | ||
plugin.afterTrack(finalPayload); | ||
} | ||
} | ||
catch (ex) { | ||
console.warn('Snowplow: error with plugin ', ex); | ||
} | ||
}); | ||
return finalPayload; | ||
} | ||
plugins.forEach(function (plugin) { | ||
try { | ||
if (plugin.afterTrack) { | ||
plugin.afterTrack(pb.build()); | ||
/** | ||
* Set a persistent key-value pair to be added to every payload | ||
* | ||
* @param key Field name | ||
* @param value Field value | ||
*/ | ||
function addPayloadPair(key, value) { | ||
payloadPairs[key] = value; | ||
} | ||
var core = { | ||
track: track, | ||
addPayloadPair: addPayloadPair, | ||
getBase64Encoding: function () { | ||
return encodeBase64; | ||
}, | ||
setBase64Encoding: function (encode) { | ||
encodeBase64 = encode; | ||
}, | ||
addPayloadDict: function (dict) { | ||
for (var key in dict) { | ||
if (Object.prototype.hasOwnProperty.call(dict, key)) { | ||
payloadPairs[key] = dict[key]; | ||
} | ||
} | ||
}, | ||
resetPayloadPairs: function (dict) { | ||
payloadPairs = isJson(dict) ? dict : {}; | ||
}, | ||
setTrackerVersion: function (version) { | ||
addPayloadPair('tv', version); | ||
}, | ||
setTrackerNamespace: function (name) { | ||
addPayloadPair('tna', name); | ||
}, | ||
setAppId: function (appId) { | ||
addPayloadPair('aid', appId); | ||
}, | ||
setPlatform: function (value) { | ||
addPayloadPair('p', value); | ||
}, | ||
setUserId: function (userId) { | ||
addPayloadPair('uid', userId); | ||
}, | ||
setScreenResolution: function (width, height) { | ||
addPayloadPair('res', width + 'x' + height); | ||
}, | ||
setViewport: function (width, height) { | ||
addPayloadPair('vp', width + 'x' + height); | ||
}, | ||
setColorDepth: function (depth) { | ||
addPayloadPair('cd', depth); | ||
}, | ||
setTimezone: function (timezone) { | ||
addPayloadPair('tz', timezone); | ||
}, | ||
setLang: function (lang) { | ||
addPayloadPair('lang', lang); | ||
}, | ||
setIpAddress: function (ip) { | ||
addPayloadPair('ip', ip); | ||
}, | ||
setUseragent: function (useragent) { | ||
addPayloadPair('ua', useragent); | ||
}, | ||
addGlobalContexts: function (contexts) { | ||
globalContextsHelper.addGlobalContexts(contexts); | ||
}, | ||
clearGlobalContexts: function () { | ||
globalContextsHelper.clearGlobalContexts(); | ||
}, | ||
removeGlobalContexts: function (contexts) { | ||
globalContextsHelper.removeGlobalContexts(contexts); | ||
} | ||
catch (ex) { | ||
console.warn('Snowplow: error with plugin ', ex); | ||
} | ||
}); | ||
return pb; | ||
}; | ||
return core; | ||
} | ||
/** | ||
* Set a persistent key-value pair to be added to every payload | ||
* | ||
* @param key Field name | ||
* @param value Field value | ||
*/ | ||
function addPayloadPair(key, value) { | ||
payloadPairs[key] = value; | ||
} | ||
var core = { | ||
track: track, | ||
addPayloadPair: addPayloadPair, | ||
getBase64Encoding: function () { | ||
return encodeBase64; | ||
}, | ||
setBase64Encoding: function (encode) { | ||
encodeBase64 = encode; | ||
}, | ||
addPayloadDict: function (dict) { | ||
for (var key in dict) { | ||
if (Object.prototype.hasOwnProperty.call(dict, key)) { | ||
payloadPairs[key] = dict[key]; | ||
} | ||
} | ||
}, | ||
resetPayloadPairs: function (dict) { | ||
payloadPairs = isJson(dict) ? dict : {}; | ||
}, | ||
setTrackerVersion: function (version) { | ||
addPayloadPair('tv', version); | ||
}, | ||
setTrackerNamespace: function (name) { | ||
addPayloadPair('tna', name); | ||
}, | ||
setAppId: function (appId) { | ||
addPayloadPair('aid', appId); | ||
}, | ||
setPlatform: function (value) { | ||
addPayloadPair('p', value); | ||
}, | ||
setUserId: function (userId) { | ||
addPayloadPair('uid', userId); | ||
}, | ||
setScreenResolution: function (width, height) { | ||
addPayloadPair('res', width + 'x' + height); | ||
}, | ||
setViewport: function (width, height) { | ||
addPayloadPair('vp', width + 'x' + height); | ||
}, | ||
setColorDepth: function (depth) { | ||
addPayloadPair('cd', depth); | ||
}, | ||
setTimezone: function (timezone) { | ||
addPayloadPair('tz', timezone); | ||
}, | ||
setLang: function (lang) { | ||
addPayloadPair('lang', lang); | ||
}, | ||
setIpAddress: function (ip) { | ||
addPayloadPair('ip', ip); | ||
}, | ||
setUseragent: function (useragent) { | ||
addPayloadPair('ua', useragent); | ||
}, | ||
addGlobalContexts: function (contexts) { | ||
globalContextsHelper.addGlobalContexts(contexts); | ||
}, | ||
clearGlobalContexts: function () { | ||
globalContextsHelper.clearGlobalContexts(); | ||
}, | ||
removeGlobalContexts: function (contexts) { | ||
globalContextsHelper.removeGlobalContexts(contexts); | ||
} | ||
}; | ||
var base64 = configuration.base64, corePlugins = configuration.corePlugins, callback = configuration.callback, plugins = corePlugins !== null && corePlugins !== void 0 ? corePlugins : [], partialCore = newCore(base64 !== null && base64 !== void 0 ? base64 : true, plugins, callback), core = __assign(__assign({}, partialCore), { addPlugin: function (plugin) { | ||
var _a; | ||
plugins.push(plugin); | ||
(_a = plugin.activateCorePlugin) === null || _a === void 0 ? void 0 : _a.call(plugin, core); | ||
} }); | ||
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); | ||
}); | ||
return core; | ||
@@ -1506,3 +1521,3 @@ } | ||
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, pluginContexts, resolveDynamicContext, trackerCore, validateVendor, validateVendorParts }; | ||
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 }; | ||
//# sourceMappingURL=index.module.js.map |
{ | ||
"name": "@snowplow/tracker-core", | ||
"version": "3.0.0-alpha.3", | ||
"version": "3.0.0-alpha.4", | ||
"description": "Core functionality for Snowplow JavaScript trackers", | ||
@@ -46,8 +46,8 @@ "keywords": [ | ||
"dependencies": { | ||
"tslib": "^2.0.3", | ||
"uuid": "^3.3.3" | ||
"tslib": "^2.1.0", | ||
"uuid": "^3.4.0" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^17.0.0", | ||
"@rollup/plugin-node-resolve": "^11.0.0", | ||
"@rollup/plugin-commonjs": "^17.1.0", | ||
"@rollup/plugin-node-resolve": "^11.2.0", | ||
"@types/node": "^14.6.0", | ||
@@ -61,3 +61,3 @@ "@types/uuid": "^3.4.6", | ||
"jest-standard-reporter": "^2.0.0", | ||
"rollup": "^2.34.0", | ||
"rollup": "^2.41.1", | ||
"rollup-plugin-cleanup": "^3.2.1", | ||
@@ -67,4 +67,4 @@ "rollup-plugin-license": "^2.2.0", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.1.2" | ||
"typescript": "^4.2.3" | ||
} | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
615229
6319
Updatedtslib@^2.1.0
Updateduuid@^3.4.0