Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@snowplow/browser-plugin-ecommerce

Package Overview
Dependencies
Maintainers
0
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@snowplow/browser-plugin-ecommerce - npm Package Compare versions

Comparing version 3.24.2 to 3.24.3

2

dist/index.module.js
/*!
* Ecommerce tracking for Snowplow v3.24.2 (http://bit.ly/sp-js)
* Ecommerce tracking for Snowplow v3.24.3 (http://bit.ly/sp-js)
* Copyright 2022 Snowplow Analytics Ltd, 2010 Anthon Pang

@@ -4,0 +4,0 @@ * Licensed under BSD-3-Clause

/*!
* Ecommerce tracking for Snowplow v3.24.2 (http://bit.ly/sp-js)
* Ecommerce tracking for Snowplow v3.24.3 (http://bit.ly/sp-js)
* Copyright 2022 Snowplow Analytics Ltd, 2010 Anthon Pang

@@ -8,535 +8,540 @@ * Licensed under BSD-3-Clause

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.snowplowEcommerce = {}));
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.snowplowEcommerce = {}));
})(this, (function (exports) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
return to.concat(ar || Array.prototype.slice.call(from));
}
return to.concat(ar || Array.prototype.slice.call(from));
}
/*!
* Core functionality for Snowplow JavaScript trackers v3.24.2 (http://bit.ly/sp-js)
* Copyright 2022 Snowplow Analytics Ltd, 2010 Anthon Pang
* Licensed under BSD-3-Clause
*/
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
var e = new Error(message);
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
};
/*
* Copyright (c) 2022 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.
*/
function payloadBuilder() {
var dict = {}, allJson = [], jsonForProcessing = [], contextEntitiesForProcessing = [];
var processor;
var add = function (key, value) {
if (value != null && value !== '') {
// null also checks undefined
dict[key] = value;
}
};
var addDict = function (dict) {
for (var key in dict) {
if (Object.prototype.hasOwnProperty.call(dict, key)) {
add(key, dict[key]);
}
}
};
var addJson = function (keyIfEncoded, keyIfNotEncoded, json) {
if (json && isNonEmptyJson(json)) {
var jsonWithKeys = { keyIfEncoded: keyIfEncoded, keyIfNotEncoded: keyIfNotEncoded, json: json };
jsonForProcessing.push(jsonWithKeys);
allJson.push(jsonWithKeys);
}
};
var addContextEntity = function (entity) {
contextEntitiesForProcessing.push(entity);
};
return {
add: add,
addDict: addDict,
addJson: addJson,
addContextEntity: addContextEntity,
getPayload: function () { return dict; },
getJson: function () { return allJson; },
withJsonProcessor: function (jsonProcessor) {
processor = jsonProcessor;
},
build: function () {
processor === null || processor === void 0 ? void 0 : processor(this, jsonForProcessing, contextEntitiesForProcessing);
return dict;
}
};
}
/**
* 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));
}
/*!
* Core functionality for Snowplow JavaScript trackers v3.24.3 (http://bit.ly/sp-js)
* Copyright 2022 Snowplow Analytics Ltd, 2010 Anthon Pang
* Licensed under BSD-3-Clause
*/
/*
* Copyright (c) 2022 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.
*/
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, false));
}
else {
console.error.apply(console, __spreadArray([logMsg], extraParams, false));
}
}
}
/**
* 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') {
var logMsg = label + message;
if (error) {
console.warn.apply(console, __spreadArray([logMsg + '\n', error], extraParams, false));
}
else {
console.warn.apply(console, __spreadArray([logMsg], extraParams, false));
}
}
}
/**
* 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') {
console.debug.apply(console, __spreadArray([label + message], extraParams, false));
}
}
/**
* 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') {
console.info.apply(console, __spreadArray([label + message], extraParams, false));
}
}
return { setLogLevel: setLogLevel, warn: warn, error: error, debug: debug, info: info };
}
/**
* Build a self-describing event
* A custom event type, allowing for an event to be tracked using your own custom schema
* and a data object which conforms to the supplied schema
*
* @param event - Contains the properties and schema location for the event
* @returns PayloadBuilder to be sent to {@link @snowplow/tracker-core#TrackerCore.track}
*/
function buildSelfDescribingEvent(event) {
var _a = event.event, schema = _a.schema, data = _a.data, pb = payloadBuilder();
var ueJson = {
schema: 'iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0',
data: { schema: schema, data: data }
};
pb.add('e', 'ue');
pb.addJson('ue_px', 'ue_pr', ueJson);
return pb;
}
/**
* Build an Ecommerce Transaction Event
* Allows for tracking common ecommerce events, this event is usually used when
* a consumer completes a transaction.
*
* @param event - Contains the properties for the Ecommerce Transactoion event
* @returns PayloadBuilder to be sent to {@link @snowplow/tracker-core#TrackerCore.track}
*/
function buildEcommerceTransaction(event) {
var orderId = event.orderId, total = event.total, affiliation = event.affiliation, tax = event.tax, shipping = event.shipping, city = event.city, state = event.state, country = event.country, currency = event.currency, pb = payloadBuilder();
pb.add('e', 'tr'); // 'tr' for Transaction
pb.add('tr_id', orderId);
pb.add('tr_af', affiliation);
pb.add('tr_tt', total);
pb.add('tr_tx', tax);
pb.add('tr_sh', shipping);
pb.add('tr_ci', city);
pb.add('tr_st', state);
pb.add('tr_co', country);
pb.add('tr_cu', currency);
return pb;
}
/**
* Build an Ecommerce Transaction Item Event
* Related to the {@link buildEcommerceTransaction}
* Each Ecommerce Transaction may contain one or more EcommerceTransactionItem events
*
* @param event - Contains the properties for the Ecommerce Transaction Item event
* @returns PayloadBuilder to be sent to {@link @snowplow/tracker-core#TrackerCore.track}
*/
function buildEcommerceTransactionItem(event) {
var orderId = event.orderId, sku = event.sku, price = event.price, name = event.name, category = event.category, quantity = event.quantity, currency = event.currency, pb = payloadBuilder();
pb.add('e', 'ti'); // 'tr' for Transaction Item
pb.add('ti_id', orderId);
pb.add('ti_sk', sku);
pb.add('ti_nm', name);
pb.add('ti_ca', category);
pb.add('ti_pr', price);
pb.add('ti_qu', quantity);
pb.add('ti_cu', currency);
return pb;
}
/**
* Build a Add To Cart Event
* For tracking users adding items from a cart
* on an ecommerce site.
*
* @param event - Contains the properties for the Add To Cart event
* @returns PayloadBuilder to be sent to {@link @snowplow/tracker-core#TrackerCore.track}
*/
function buildAddToCart(event) {
var sku = event.sku, quantity = event.quantity, name = event.name, category = event.category, unitPrice = event.unitPrice, currency = event.currency;
return buildSelfDescribingEvent({
event: {
schema: 'iglu:com.snowplowanalytics.snowplow/add_to_cart/jsonschema/1-0-0',
data: removeEmptyProperties({
sku: sku,
quantity: quantity,
name: name,
category: category,
unitPrice: unitPrice,
currency: currency
})
}
});
}
/**
* Build a Remove From Cart Event
* For tracking users removing items from a cart
* on an ecommerce site.
*
* @param event - Contains the properties for the Remove From Cart event
* @returns PayloadBuilder to be sent to {@link @snowplow/tracker-core#TrackerCore.track}
*/
function buildRemoveFromCart(event) {
var sku = event.sku, quantity = event.quantity, name = event.name, category = event.category, unitPrice = event.unitPrice, currency = event.currency;
return buildSelfDescribingEvent({
event: {
schema: 'iglu:com.snowplowanalytics.snowplow/remove_from_cart/jsonschema/1-0-0',
data: removeEmptyProperties({
sku: sku,
quantity: quantity,
name: name,
category: category,
unitPrice: unitPrice,
currency: currency
})
}
});
}
/**
* Returns a copy of a JSON with undefined and null properties removed
*
* @param event - JSON object to clean
* @param exemptFields - Set of fields which should not be removed even if empty
* @returns A cleaned copy of eventJson
*/
function removeEmptyProperties(event, exemptFields) {
if (exemptFields === void 0) { exemptFields = {}; }
var ret = {};
for (var k in event) {
if (exemptFields[k] || (event[k] !== null && typeof event[k] !== 'undefined')) {
ret[k] = event[k];
}
}
return ret;
}
/*
* Copyright (c) 2022 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.
*/
function payloadBuilder() {
var dict = {}, allJson = [], jsonForProcessing = [], contextEntitiesForProcessing = [];
var processor;
var add = function (key, value) {
if (value != null && value !== '') {
// null also checks undefined
dict[key] = value;
}
};
var addDict = function (dict) {
for (var key in dict) {
if (Object.prototype.hasOwnProperty.call(dict, key)) {
add(key, dict[key]);
}
}
};
var addJson = function (keyIfEncoded, keyIfNotEncoded, json) {
if (json && isNonEmptyJson(json)) {
var jsonWithKeys = { keyIfEncoded: keyIfEncoded, keyIfNotEncoded: keyIfNotEncoded, json: json };
jsonForProcessing.push(jsonWithKeys);
allJson.push(jsonWithKeys);
}
};
var addContextEntity = function (entity) {
contextEntitiesForProcessing.push(entity);
};
return {
add: add,
addDict: addDict,
addJson: addJson,
addContextEntity: addContextEntity,
getPayload: function () { return dict; },
getJson: function () { return allJson; },
withJsonProcessor: function (jsonProcessor) {
processor = jsonProcessor;
},
build: function () {
processor === null || processor === void 0 ? void 0 : processor(this, jsonForProcessing, contextEntitiesForProcessing);
return dict;
}
};
}
/**
* 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));
}
/*!
* Core functionality for Snowplow Browser trackers v3.24.2 (http://bit.ly/sp-js)
* Copyright 2022 Snowplow Analytics Ltd, 2010 Anthon Pang
* Licensed under BSD-3-Clause
*/
/**
* Dispatch function to all specified trackers from the supplied collection
*
* @param trackers - An optional list of trackers to send the event to, or will send to all trackers
* @param trackerCollection - The collection which the trackers will be selected from
* @param fn - The function which will run against each tracker
*/
function dispatchToTrackersInCollection(trackers, trackerCollection, fn) {
try {
getTrackersFromCollection(trackers !== null && trackers !== void 0 ? trackers : Object.keys(trackerCollection), trackerCollection).forEach(fn);
}
catch (ex) {
LOG.error('Function failed', ex);
}
}
function getTrackersFromCollection(trackerIds, trackerCollection) {
var trackers = [];
for (var _i = 0, trackerIds_1 = trackerIds; _i < trackerIds_1.length; _i++) {
var id = trackerIds_1[_i];
if (trackerCollection.hasOwnProperty(id)) {
trackers.push(trackerCollection[id]);
}
else {
LOG.warn(id + ' not configured');
}
}
return trackers;
}
/*
* Copyright (c) 2022 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.
*/
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, false));
}
else {
console.error.apply(console, __spreadArray([logMsg], extraParams, false));
}
}
}
/**
* 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') {
var logMsg = label + message;
if (error) {
console.warn.apply(console, __spreadArray([logMsg + '\n', error], extraParams, false));
}
else {
console.warn.apply(console, __spreadArray([logMsg], extraParams, false));
}
}
}
/**
* 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') {
console.debug.apply(console, __spreadArray([label + message], extraParams, false));
}
}
/**
* 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') {
console.info.apply(console, __spreadArray([label + message], extraParams, false));
}
}
return { setLogLevel: setLogLevel, warn: warn, error: error, debug: debug, info: info };
}
/**
* Build a self-describing event
* A custom event type, allowing for an event to be tracked using your own custom schema
* and a data object which conforms to the supplied schema
*
* @param event - Contains the properties and schema location for the event
* @returns PayloadBuilder to be sent to {@link @snowplow/tracker-core#TrackerCore.track}
*/
function buildSelfDescribingEvent(event) {
var _a = event.event, schema = _a.schema, data = _a.data, pb = payloadBuilder();
var ueJson = {
schema: 'iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0',
data: { schema: schema, data: data }
};
pb.add('e', 'ue');
pb.addJson('ue_px', 'ue_pr', ueJson);
return pb;
}
/**
* Build an Ecommerce Transaction Event
* Allows for tracking common ecommerce events, this event is usually used when
* a consumer completes a transaction.
*
* @param event - Contains the properties for the Ecommerce Transactoion event
* @returns PayloadBuilder to be sent to {@link @snowplow/tracker-core#TrackerCore.track}
*/
function buildEcommerceTransaction(event) {
var orderId = event.orderId, total = event.total, affiliation = event.affiliation, tax = event.tax, shipping = event.shipping, city = event.city, state = event.state, country = event.country, currency = event.currency, pb = payloadBuilder();
pb.add('e', 'tr'); // 'tr' for Transaction
pb.add('tr_id', orderId);
pb.add('tr_af', affiliation);
pb.add('tr_tt', total);
pb.add('tr_tx', tax);
pb.add('tr_sh', shipping);
pb.add('tr_ci', city);
pb.add('tr_st', state);
pb.add('tr_co', country);
pb.add('tr_cu', currency);
return pb;
}
/**
* Build an Ecommerce Transaction Item Event
* Related to the {@link buildEcommerceTransaction}
* Each Ecommerce Transaction may contain one or more EcommerceTransactionItem events
*
* @param event - Contains the properties for the Ecommerce Transaction Item event
* @returns PayloadBuilder to be sent to {@link @snowplow/tracker-core#TrackerCore.track}
*/
function buildEcommerceTransactionItem(event) {
var orderId = event.orderId, sku = event.sku, price = event.price, name = event.name, category = event.category, quantity = event.quantity, currency = event.currency, pb = payloadBuilder();
pb.add('e', 'ti'); // 'tr' for Transaction Item
pb.add('ti_id', orderId);
pb.add('ti_sk', sku);
pb.add('ti_nm', name);
pb.add('ti_ca', category);
pb.add('ti_pr', price);
pb.add('ti_qu', quantity);
pb.add('ti_cu', currency);
return pb;
}
/**
* Build a Add To Cart Event
* For tracking users adding items from a cart
* on an ecommerce site.
*
* @param event - Contains the properties for the Add To Cart event
* @returns PayloadBuilder to be sent to {@link @snowplow/tracker-core#TrackerCore.track}
*/
function buildAddToCart(event) {
var sku = event.sku, quantity = event.quantity, name = event.name, category = event.category, unitPrice = event.unitPrice, currency = event.currency;
return buildSelfDescribingEvent({
event: {
schema: 'iglu:com.snowplowanalytics.snowplow/add_to_cart/jsonschema/1-0-0',
data: removeEmptyProperties({
sku: sku,
quantity: quantity,
name: name,
category: category,
unitPrice: unitPrice,
currency: currency
})
}
});
}
/**
* Build a Remove From Cart Event
* For tracking users removing items from a cart
* on an ecommerce site.
*
* @param event - Contains the properties for the Remove From Cart event
* @returns PayloadBuilder to be sent to {@link @snowplow/tracker-core#TrackerCore.track}
*/
function buildRemoveFromCart(event) {
var sku = event.sku, quantity = event.quantity, name = event.name, category = event.category, unitPrice = event.unitPrice, currency = event.currency;
return buildSelfDescribingEvent({
event: {
schema: 'iglu:com.snowplowanalytics.snowplow/remove_from_cart/jsonschema/1-0-0',
data: removeEmptyProperties({
sku: sku,
quantity: quantity,
name: name,
category: category,
unitPrice: unitPrice,
currency: currency
})
}
});
}
/**
* Returns a copy of a JSON with undefined and null properties removed
*
* @param event - JSON object to clean
* @param exemptFields - Set of fields which should not be removed even if empty
* @returns A cleaned copy of eventJson
*/
function removeEmptyProperties(event, exemptFields) {
if (exemptFields === void 0) { exemptFields = {}; }
var ret = {};
for (var k in event) {
if (exemptFields[k] || (event[k] !== null && typeof event[k] !== 'undefined')) {
ret[k] = event[k];
}
}
return ret;
}
/*
* Copyright (c) 2022 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.
*/
function ecommerceTransactionTemplate() {
return {
items: []
};
}
var _trackers = {};
var _transactions = {};
/**
* Adds ecommerce and cart tracking
*/
function EcommercePlugin() {
return {
activateBrowserPlugin: function (tracker) {
_trackers[tracker.id] = tracker;
_transactions[tracker.id] = ecommerceTransactionTemplate();
}
};
}
/**
* Track an ecommerce transaction
*
* @param event - The event information
* @param trackers - The tracker identifiers which the event will be sent to
*/
function addTrans(event, trackers) {
if (trackers === void 0) { trackers = Object.keys(_trackers); }
trackers.forEach(function (t) {
if (_transactions[t]) {
_transactions[t].transaction = event;
}
});
}
/**
* Track an ecommerce transaction item
*
* @param event - The event information
* @param trackers - The tracker identifiers which the event will be sent to
*/
function addItem(event, trackers) {
if (trackers === void 0) { trackers = Object.keys(_trackers); }
trackers.forEach(function (t) {
if (_transactions[t]) {
_transactions[t].items.push(event);
}
});
}
/**
* Commit the ecommerce transaction
*
* @remarks
* This call will send the data specified with addTrans, ddItem methods to the tracking server.
*/
function trackTrans(trackers) {
if (trackers === void 0) { trackers = Object.keys(_trackers); }
dispatchToTrackersInCollection(trackers, _trackers, function (t) {
var transaction = _transactions[t.id].transaction;
if (transaction) {
t.core.track(buildEcommerceTransaction(transaction), transaction.context, transaction.timestamp);
}
for (var i = 0; i < _transactions[t.id].items.length; i++) {
var item = _transactions[t.id].items[i];
t.core.track(buildEcommerceTransactionItem(item), item.context, item.timestamp);
}
_transactions[t.id] = ecommerceTransactionTemplate();
});
}
/**
* Track an add-to-cart event
*
* @param event - The event information
* @param trackers - The tracker identifiers which the event will be sent to
*/
function trackAddToCart(event, trackers) {
if (trackers === void 0) { trackers = Object.keys(_trackers); }
dispatchToTrackersInCollection(trackers, _trackers, function (t) {
t.core.track(buildAddToCart(event), event.context, event.timestamp);
});
}
/**
* Track a remove-from-cart event
*
* @param event - The event information
* @param trackers - The tracker identifiers which the event will be sent to
*/
function trackRemoveFromCart(event, trackers) {
if (trackers === void 0) { trackers = Object.keys(_trackers); }
dispatchToTrackersInCollection(trackers, _trackers, function (t) {
t.core.track(buildRemoveFromCart(event), event.context, event.timestamp);
});
}
/*!
* Core functionality for Snowplow Browser trackers v3.24.3 (http://bit.ly/sp-js)
* Copyright 2022 Snowplow Analytics Ltd, 2010 Anthon Pang
* Licensed under BSD-3-Clause
*/
/**
* Dispatch function to all specified trackers from the supplied collection
*
* @param trackers - An optional list of trackers to send the event to, or will send to all trackers
* @param trackerCollection - The collection which the trackers will be selected from
* @param fn - The function which will run against each tracker
*/
function dispatchToTrackersInCollection(trackers, trackerCollection, fn) {
try {
getTrackersFromCollection(trackers !== null && trackers !== void 0 ? trackers : Object.keys(trackerCollection), trackerCollection).forEach(fn);
}
catch (ex) {
LOG.error('Function failed', ex);
}
}
function getTrackersFromCollection(trackerIds, trackerCollection) {
var trackers = [];
for (var _i = 0, trackerIds_1 = trackerIds; _i < trackerIds_1.length; _i++) {
var id = trackerIds_1[_i];
if (trackerCollection.hasOwnProperty(id)) {
trackers.push(trackerCollection[id]);
}
else {
LOG.warn(id + ' not configured');
}
}
return trackers;
}
exports.EcommercePlugin = EcommercePlugin;
exports.addItem = addItem;
exports.addTrans = addTrans;
exports.trackAddToCart = trackAddToCart;
exports.trackRemoveFromCart = trackRemoveFromCart;
exports.trackTrans = trackTrans;
/*
* Copyright (c) 2022 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.
*/
function ecommerceTransactionTemplate() {
return {
items: []
};
}
var _trackers = {};
var _transactions = {};
/**
* Adds ecommerce and cart tracking
*/
function EcommercePlugin() {
return {
activateBrowserPlugin: function (tracker) {
_trackers[tracker.id] = tracker;
_transactions[tracker.id] = ecommerceTransactionTemplate();
}
};
}
/**
* Track an ecommerce transaction
*
* @param event - The event information
* @param trackers - The tracker identifiers which the event will be sent to
*/
function addTrans(event, trackers) {
if (trackers === void 0) { trackers = Object.keys(_trackers); }
trackers.forEach(function (t) {
if (_transactions[t]) {
_transactions[t].transaction = event;
}
});
}
/**
* Track an ecommerce transaction item
*
* @param event - The event information
* @param trackers - The tracker identifiers which the event will be sent to
*/
function addItem(event, trackers) {
if (trackers === void 0) { trackers = Object.keys(_trackers); }
trackers.forEach(function (t) {
if (_transactions[t]) {
_transactions[t].items.push(event);
}
});
}
/**
* Commit the ecommerce transaction
*
* @remarks
* This call will send the data specified with addTrans, ddItem methods to the tracking server.
*/
function trackTrans(trackers) {
if (trackers === void 0) { trackers = Object.keys(_trackers); }
dispatchToTrackersInCollection(trackers, _trackers, function (t) {
var transaction = _transactions[t.id].transaction;
if (transaction) {
t.core.track(buildEcommerceTransaction(transaction), transaction.context, transaction.timestamp);
}
for (var i = 0; i < _transactions[t.id].items.length; i++) {
var item = _transactions[t.id].items[i];
t.core.track(buildEcommerceTransactionItem(item), item.context, item.timestamp);
}
_transactions[t.id] = ecommerceTransactionTemplate();
});
}
/**
* Track an add-to-cart event
*
* @param event - The event information
* @param trackers - The tracker identifiers which the event will be sent to
*/
function trackAddToCart(event, trackers) {
if (trackers === void 0) { trackers = Object.keys(_trackers); }
dispatchToTrackersInCollection(trackers, _trackers, function (t) {
t.core.track(buildAddToCart(event), event.context, event.timestamp);
});
}
/**
* Track a remove-from-cart event
*
* @param event - The event information
* @param trackers - The tracker identifiers which the event will be sent to
*/
function trackRemoveFromCart(event, trackers) {
if (trackers === void 0) { trackers = Object.keys(_trackers); }
dispatchToTrackersInCollection(trackers, _trackers, function (t) {
t.core.track(buildRemoveFromCart(event), event.context, event.timestamp);
});
}
Object.defineProperty(exports, '__esModule', { value: true });
exports.EcommercePlugin = EcommercePlugin;
exports.addItem = addItem;
exports.addTrans = addTrans;
exports.trackAddToCart = trackAddToCart;
exports.trackRemoveFromCart = trackRemoveFromCart;
exports.trackTrans = trackTrans;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=index.umd.js.map
/*!
* Ecommerce tracking for Snowplow v3.24.2 (http://bit.ly/sp-js)
* Ecommerce tracking for Snowplow v3.24.3 (http://bit.ly/sp-js)
* Copyright 2022 Snowplow Analytics Ltd, 2010 Anthon Pang

@@ -7,3 +7,3 @@ * Licensed under BSD-3-Clause

"use strict";!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).snowplowEcommerce={})}(this,(function(n){function t(n,t,o){if(o||2===arguments.length)for(var e,r=0,c=t.length;r<c;r++)!e&&r in t||(e||(e=Array.prototype.slice.call(t,0,r)),e[r]=t[r]);return n.concat(e||Array.prototype.slice.call(t))}function o(){var n,t={},o=[],e=[],r=[],c=function(n,o){null!=o&&""!==o&&(t[n]=o)};return{add:c,addDict:function(n){for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&c(t,n[t])},addJson:function(n,t,r){var c;if(c=r)n:{if(null!=r&&(r.constructor==={}.constructor||r.constructor===[].constructor))for(var a in r)if(Object.prototype.hasOwnProperty.call(r,a)){c=!0;break n}c=!1}c&&(n={keyIfEncoded:n,keyIfNotEncoded:t,json:r},e.push(n),o.push(n))},addContextEntity:function(n){r.push(n)},getPayload:function(){return t},getJson:function(){return o},withJsonProcessor:function(t){n=t},build:function(){return null==n||n(this,e,r),t}}}function e(n){var t=n.event;return n={schema:"iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0",data:{schema:n=t.schema,data:t.data}},(t=o()).add("e","ue"),t.addJson("ue_px","ue_pr",n),t}function r(n,t){void 0===t&&(t={});var o,e={};for(o in n)(t[o]||null!==n[o]&&void 0!==n[o])&&(e[o]=n[o]);return e}function c(n,t,o){try{var e=null!=n?n:Object.keys(t);n=[];for(var r=0;r<e.length;r++){var c=e[r];t.hasOwnProperty(c)?n.push(t[c]):d.warn(c+" not configured")}n.forEach(o)}catch(n){d.error("Function failed",n)}}var a,i;(i=a||(a={}))[i.none=0]="none",i[i.error=1]="error",i[i.warn=2]="warn",i[i.debug=3]="debug",i[i.info=4]="info";var d=function(n){return void 0===n&&(n=a.warn),{setLogLevel:function(t){n=a[t]?t:a.warn},warn:function(o,e){for(var r=[],c=2;c<arguments.length;c++)r[c-2]=arguments[c];n>=a.warn&&"undefined"!=typeof console&&(c="Snowplow: "+o,e?console.warn.apply(console,t([c+"\n",e],r,!1)):console.warn.apply(console,t([c],r,!1)))},error:function(o,e){for(var r=[],c=2;c<arguments.length;c++)r[c-2]=arguments[c];n>=a.error&&"undefined"!=typeof console&&(c="Snowplow: "+o+"\n",e?console.error.apply(console,t([c+"\n",e],r,!1)):console.error.apply(console,t([c],r,!1)))},debug:function(o){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];n>=a.debug&&"undefined"!=typeof console&&console.debug.apply(console,t(["Snowplow: "+o],e,!1))},info:function(o){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];n>=a.info&&"undefined"!=typeof console&&console.info.apply(console,t(["Snowplow: "+o],e,!1))}}}(),u={},s={};n.EcommercePlugin=function(){return{activateBrowserPlugin:function(n){u[n.id]=n,s[n.id]={items:[]}}}},n.addItem=function(n,t){void 0===t&&(t=Object.keys(u)),t.forEach((function(t){s[t]&&s[t].items.push(n)}))},n.addTrans=function(n,t){void 0===t&&(t=Object.keys(u)),t.forEach((function(t){s[t]&&(s[t].transaction=n)}))},n.trackAddToCart=function(n,t){void 0===t&&(t=Object.keys(u)),c(t,u,(function(t){var o=(t=t.core).track,c=e({event:{schema:"iglu:com.snowplowanalytics.snowplow/add_to_cart/jsonschema/1-0-0",data:r({sku:n.sku,quantity:n.quantity,name:n.name,category:n.category,unitPrice:n.unitPrice,currency:n.currency})}});o.call(t,c,n.context,n.timestamp)}))},n.trackRemoveFromCart=function(n,t){void 0===t&&(t=Object.keys(u)),c(t,u,(function(t){var o=(t=t.core).track,c=e({event:{schema:"iglu:com.snowplowanalytics.snowplow/remove_from_cart/jsonschema/1-0-0",data:r({sku:n.sku,quantity:n.quantity,name:n.name,category:n.category,unitPrice:n.unitPrice,currency:n.currency})}});o.call(t,c,n.context,n.timestamp)}))},n.trackTrans=function(n){void 0===n&&(n=Object.keys(u)),c(n,u,(function(n){var t=s[n.id].transaction;if(t){var e=n.core,r=e.track,c=t.orderId,a=t.total,i=t.affiliation,d=t.tax,u=t.shipping,l=t.city,f=t.state,p=t.country,y=t.currency,m=o();m.add("e","tr"),m.add("tr_id",c),m.add("tr_af",i),m.add("tr_tt",a),m.add("tr_tx",d),m.add("tr_sh",u),m.add("tr_ci",l),m.add("tr_st",f),m.add("tr_co",p),m.add("tr_cu",y),r.call(e,m,t.context,t.timestamp)}for(t=0;t<s[n.id].items.length;t++)e=s[n.id].items[t],c=(r=n.core).track,a=e.orderId,i=e.sku,d=e.price,u=e.name,l=e.category,f=e.quantity,p=e.currency,(y=o()).add("e","ti"),y.add("ti_id",a),y.add("ti_sk",i),y.add("ti_nm",u),y.add("ti_ca",l),y.add("ti_pr",d),y.add("ti_qu",f),y.add("ti_cu",p),c.call(r,y,e.context,e.timestamp);s[n.id]={items:[]}}))},Object.defineProperty(n,"__esModule",{value:!0})}));
"use strict";!function(n,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o((n="undefined"!=typeof globalThis?globalThis:n||self).snowplowEcommerce={})}(this,(function(n){function o(n,o,t){if(t||2===arguments.length)for(var e,r=0,c=o.length;r<c;r++)!e&&r in o||(e||(e=Array.prototype.slice.call(o,0,r)),e[r]=o[r]);return n.concat(e||Array.prototype.slice.call(o))}function t(){var n,o={},t=[],e=[],r=[],c=function(n,t){null!=t&&""!==t&&(o[n]=t)};return{add:c,addDict:function(n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&c(o,n[o])},addJson:function(n,o,r){var c;if(c=r)n:{if(null!=r&&(r.constructor==={}.constructor||r.constructor===[].constructor))for(var a in r)if(Object.prototype.hasOwnProperty.call(r,a)){c=!0;break n}c=!1}c&&(n={keyIfEncoded:n,keyIfNotEncoded:o,json:r},e.push(n),t.push(n))},addContextEntity:function(n){r.push(n)},getPayload:function(){return o},getJson:function(){return t},withJsonProcessor:function(o){n=o},build:function(){return null==n||n(this,e,r),o}}}function e(n){var o=n.event;return n={schema:"iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0",data:{schema:n=o.schema,data:o.data}},(o=t()).add("e","ue"),o.addJson("ue_px","ue_pr",n),o}function r(n,o){void 0===o&&(o={});var t,e={};for(t in n)(o[t]||null!==n[t]&&void 0!==n[t])&&(e[t]=n[t]);return e}function c(n,o,t){try{var e=null!=n?n:Object.keys(o);n=[];for(var r=0;r<e.length;r++){var c=e[r];o.hasOwnProperty(c)?n.push(o[c]):d.warn(c+" not configured")}n.forEach(t)}catch(n){d.error("Function failed",n)}}var a,i;"function"==typeof SuppressedError&&SuppressedError,(i=a||(a={}))[i.none=0]="none",i[i.error=1]="error",i[i.warn=2]="warn",i[i.debug=3]="debug",i[i.info=4]="info";var d=function(n){return void 0===n&&(n=a.warn),{setLogLevel:function(o){n=a[o]?o:a.warn},warn:function(t,e){for(var r=[],c=2;c<arguments.length;c++)r[c-2]=arguments[c];n>=a.warn&&"undefined"!=typeof console&&(c="Snowplow: "+t,e?console.warn.apply(console,o([c+"\n",e],r,!1)):console.warn.apply(console,o([c],r,!1)))},error:function(t,e){for(var r=[],c=2;c<arguments.length;c++)r[c-2]=arguments[c];n>=a.error&&"undefined"!=typeof console&&(c="Snowplow: "+t+"\n",e?console.error.apply(console,o([c+"\n",e],r,!1)):console.error.apply(console,o([c],r,!1)))},debug:function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];n>=a.debug&&"undefined"!=typeof console&&console.debug.apply(console,o(["Snowplow: "+t],e,!1))},info:function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];n>=a.info&&"undefined"!=typeof console&&console.info.apply(console,o(["Snowplow: "+t],e,!1))}}}(),u={},s={};n.EcommercePlugin=function(){return{activateBrowserPlugin:function(n){u[n.id]=n,s[n.id]={items:[]}}}},n.addItem=function(n,o){void 0===o&&(o=Object.keys(u)),o.forEach((function(o){s[o]&&s[o].items.push(n)}))},n.addTrans=function(n,o){void 0===o&&(o=Object.keys(u)),o.forEach((function(o){s[o]&&(s[o].transaction=n)}))},n.trackAddToCart=function(n,o){void 0===o&&(o=Object.keys(u)),c(o,u,(function(o){var t=(o=o.core).track,c=e({event:{schema:"iglu:com.snowplowanalytics.snowplow/add_to_cart/jsonschema/1-0-0",data:r({sku:n.sku,quantity:n.quantity,name:n.name,category:n.category,unitPrice:n.unitPrice,currency:n.currency})}});t.call(o,c,n.context,n.timestamp)}))},n.trackRemoveFromCart=function(n,o){void 0===o&&(o=Object.keys(u)),c(o,u,(function(o){var t=(o=o.core).track,c=e({event:{schema:"iglu:com.snowplowanalytics.snowplow/remove_from_cart/jsonschema/1-0-0",data:r({sku:n.sku,quantity:n.quantity,name:n.name,category:n.category,unitPrice:n.unitPrice,currency:n.currency})}});t.call(o,c,n.context,n.timestamp)}))},n.trackTrans=function(n){void 0===n&&(n=Object.keys(u)),c(n,u,(function(n){var o=s[n.id].transaction;if(o){var e=n.core,r=e.track,c=o.orderId,a=o.total,i=o.affiliation,d=o.tax,u=o.shipping,l=o.city,f=o.state,p=o.country,y=o.currency,m=t();m.add("e","tr"),m.add("tr_id",c),m.add("tr_af",i),m.add("tr_tt",a),m.add("tr_tx",d),m.add("tr_sh",u),m.add("tr_ci",l),m.add("tr_st",f),m.add("tr_co",p),m.add("tr_cu",y),r.call(e,m,o.context,o.timestamp)}for(o=0;o<s[n.id].items.length;o++)e=s[n.id].items[o],c=(r=n.core).track,a=e.orderId,i=e.sku,d=e.price,u=e.name,l=e.category,f=e.quantity,p=e.currency,(y=t()).add("e","ti"),y.add("ti_id",a),y.add("ti_sk",i),y.add("ti_nm",u),y.add("ti_ca",l),y.add("ti_pr",d),y.add("ti_qu",f),y.add("ti_cu",p),c.call(r,y,e.context,e.timestamp);s[n.id]={items:[]}}))},Object.defineProperty(n,"__esModule",{value:!0})}));
//# sourceMappingURL=index.umd.min.js.map
{
"name": "@snowplow/browser-plugin-ecommerce",
"version": "3.24.2",
"version": "3.24.3",
"description": "Ecommerce tracking for Snowplow",

@@ -21,5 +21,5 @@ "homepage": "http://bit.ly/sp-js",

"dependencies": {
"@snowplow/browser-tracker-core": "3.24.2",
"@snowplow/tracker-core": "3.24.2",
"tslib": "^2.3.1"
"tslib": "^2.3.1",
"@snowplow/tracker-core": "3.24.3",
"@snowplow/browser-tracker-core": "3.24.3"
},

@@ -50,3 +50,3 @@ "devDependencies": {

"peerDependencies": {
"@snowplow/browser-tracker": "~3.24.2"
"@snowplow/browser-tracker": "~3.24.3"
},

@@ -56,4 +56,3 @@ "scripts": {

"test": "jest"
},
"readme": "# Snowplow Ecommerce Tracking\n\n[![npm version][npm-image]][npm-url]\n[![License][license-image]](LICENSE)\n\nBrowser Plugin to be used with `@snowplow/browser-tracker`.\n\nAdds ecommerce events to your Snowplow tracking.\n\n## Maintainer quick start\n\nPart of the Snowplow JavaScript Tracker monorepo. \nBuild with [Node.js](https://nodejs.org/en/) (14 or 16) and [Rush](https://rushjs.io/).\n\n### Setup repository\n\n```bash\nnpm install -g @microsoft/rush \ngit clone https://github.com/snowplow/snowplow-javascript-tracker.git\nrush update\n```\n\n## Package Installation\n\nWith npm:\n\n```bash\nnpm install @snowplow/browser-plugin-ecommerce\n```\n\n## Usage\n\nInitialize your tracker with the EcommercePlugin:\n\n```js\nimport { newTracker } from '@snowplow/browser-tracker';\nimport { EcommercePlugin } from '@snowplow/browser-plugin-ecommerce';\n\nnewTracker('sp1', '{{collector}}', { plugins: [ EcommercePlugin() ] }); // Also stores reference at module level\n```\n\nThen use the available functions from this package to track to all trackers which have been initialized with this plugin:\n\n```js\nimport { addTrans, addItem, trackTrans, trackAddToCart } from '@snowplow/browser-plugin-ecommerce';\n\ntrackAddToCart({\n sku: '000345',\n name: 'blue tie',\n category: 'clothing',\n unitPrice: 3.49,\n quantity: 2,\n currency: 'GBP',\n});\n\n// Grouped, events are sent on `trackTrans()` call\naddTrans({\n orderId: 'order-123',\n total: 8000,\n affiliation: 'acme',\n tax: 100,\n shipping: 50,\n city: 'pheonix',\n state: 'arizona',\n country: 'USA',\n currency: 'JPY',\n});\naddItem({\n orderId: 'order-123',\n sku: '1001',\n name: 'Blue t-shirt',\n category: 'clothing',\n price: '2000',\n quantity: '2',\n currency: 'JPY',\n});\ntrackTrans();\n```\n\n## Copyright and license\n\nLicensed and distributed under the [BSD 3-Clause License](LICENSE) ([An OSI Approved License][osi]).\n\nCopyright (c) 2022 Snowplow Analytics Ltd, 2010 Anthon Pang.\n\nAll rights reserved.\n\n[npm-url]: https://www.npmjs.com/package/@snowplow/browser-plugin-ecommerce\n[npm-image]: https://img.shields.io/npm/v/@snowplow/browser-plugin-ecommerce\n[docs]: https://docs.snowplowanalytics.com/docs/collecting-data/collecting-from-own-applications/javascript-tracker/\n[osi]: https://opensource.org/licenses/BSD-3-Clause\n[license-image]: https://img.shields.io/npm/l/@snowplow/browser-plugin-ecommerce\n"
}
}

@@ -13,3 +13,3 @@ # Snowplow Ecommerce Tracking

Part of the Snowplow JavaScript Tracker monorepo.
Build with [Node.js](https://nodejs.org/en/) (14 or 16) and [Rush](https://rushjs.io/).
Build with [Node.js](https://nodejs.org/en/) (18 - 20) and [Rush](https://rushjs.io/).

@@ -16,0 +16,0 @@ ### Setup repository

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc