@snowplow/tracker-core
Advanced tools
Comparing version 3.5.0 to 3.6.0
/*! | ||
* Core functionality for Snowplow JavaScript trackers v3.5.0 (http://bit.ly/sp-js) | ||
* Core functionality for Snowplow JavaScript trackers v3.6.0 (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(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,n,t){if(t||2===arguments.length)for(var r,o=0,a=n.length;o<a;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return e.concat(r||Array.prototype.slice.call(n))}function t(){var e,n={},t=[],r=[],a=[],i=function(e,t){null!=t&&""!==t&&(n[e]=t)};return{add:i,addDict:function(e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&i(n,e[n])},addJson:function(e,n,a){a&&o(a)&&(e={keyIfEncoded:e,keyIfNotEncoded:n,json:a},r.push(e),t.push(e))},addContextEntity:function(e){a.push(e)},getPayload:function(){return n},getJson:function(){return t},withJsonProcessor:function(n){e=n},build:function(){return null==e||e(this,r,a),n}}}function r(e){return function(t,r,o){for(var a=function(n,r,o){if(n=JSON.stringify(n),e){if(o=t.add,n){var a=0,i=0,c=[];if(n){n=unescape(encodeURIComponent(n));do{var l=n.charCodeAt(a++),s=n.charCodeAt(a++),u=n.charCodeAt(a++),d=l<<16|s<<8|u;l=d>>18&63,s=d>>12&63,u=d>>6&63,d&=63,c[i++]=S.charAt(l)+S.charAt(s)+S.charAt(u)+S.charAt(d)}while(a<n.length);a=c.join(""),n=((n=n.length%3)?a.slice(0,n-3):a)+"===".slice(n||3)}n=n.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}o.call(t,r,n)}else t.add(o,n)},i=function(n,r){if(!n){var o=t.getPayload();if(e?o.cx:o.co){var a=(n=JSON).parse;if(e){if(o=o.cx){switch(4-o.length%4){case 2:o+="==";break;case 3:o+="="}o=function(e){var n,t=0,r=0,o="",a=[];if(!e)return e;e+="";do{var i=S.indexOf(e.charAt(t++)),c=S.indexOf(e.charAt(t++));o=S.indexOf(e.charAt(t++));var l=S.indexOf(e.charAt(t++)),s=i<<18|c<<12|o<<6|l;i=s>>16&255,c=s>>8&255,s&=255,a[r++]=64===o?String.fromCharCode(i):64===l?String.fromCharCode(i,c):String.fromCharCode(i,c,s)}while(t<e.length);return o=a.join(""),n=o.replace(/\0+$/,""),decodeURIComponent(n.split("").map((function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})).join(""))}(o=o.replace(/-/g,"+").replace(/_/g,"/"))}}else o=o.co;n=a.call(n,o)}else n=void 0}return n?n.data=n.data.concat(r.data):n=r,n},c=void 0,l=0;l<r.length;l++){var s=r[l];"cx"===s.keyIfEncoded?c=i(c,s.json):a(s.json,s.keyIfEncoded,s.keyIfNotEncoded)}r.length=0,o.length&&(c=i(c,r={schema:"iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0",data:n([],o,!0)}),o.length=0),c&&a(c,"cx","co")}}function o(e){if(!a(e))return!1;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n))return!0;return!1}function a(e){return null!=e&&(e.constructor==={}.constructor||e.constructor===[].constructor)}function i(){var e=[],n=[];return{getGlobalPrimitives:function(){return e},getConditionalProviders:function(){return n},addGlobalContexts:function(t){for(var r=[],o=[],a=0;a<t.length;a++){var i=t[a];_(i)?r.push(i):h(i)&&o.push(i)}e=e.concat(o),n=n.concat(r)},clearGlobalContexts:function(){n=[],e=[]},removeGlobalContexts:function(t){for(var r=function(t){_(t)?n=n.filter((function(e){return JSON.stringify(e)!==JSON.stringify(t)})):h(t)&&(e=e.filter((function(e){return JSON.stringify(e)!==JSON.stringify(t)})))},o=0;o<t.length;o++)r(t[o])},getApplicableContexts:function(t){e:{for(var r=0,o=t.getJson();r<o.length;r++){var a=o[r];if("ue_px"===a.keyIfEncoded&&"object"==typeof a.json.data&&"string"==typeof(a=a.json.data.schema)){r=a;break e}}r=""}a="string"==typeof(o=t.getPayload().e)?o:"",o=[];var i=j(e,t,a,r);return o.push.apply(o,i),t=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.getPayload(),eventType:t,eventSchema:r})}catch(e){a=!1}if(!0===a){e=j(e[1],n,t,r);break e}}else if(b(e)&&C(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)})))}(n,t,a,r),o.push.apply(o,t),o}}}function c(e){return{addPluginContexts:function(t){var r=t?n([],t,!0):[];return e.forEach((function(e){try{e.contexts&&r.push.apply(r,e.contexts())}catch(e){L.error("Error adding plugin contexts",e)}})),r}}}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 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 u(e){return!!((e=e.split("."))&&1<e.length)&&s(e)}function d(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))&&u(e[1]))return e.slice(1,6)}function f(e){if(e=d(e)){var n=e[0];return 5===e.length&&u(n)}return!1}function p(e){return Array.isArray(e)&&e.every((function(e){return"string"==typeof e}))}function m(e){return p(e)?e.every((function(e){return f(e)})):"string"==typeof e&&f(e)}function y(e){return!!(o(e)&&"schema"in e&&"data"in e)&&("string"==typeof e.schema&&"object"==typeof e.data)}function g(e){var n=0;if(null!=e&&"object"==typeof e&&!Array.isArray(e)){if(Object.prototype.hasOwnProperty.call(e,"accept")){if(!m(e.accept))return!1;n+=1}if(Object.prototype.hasOwnProperty.call(e,"reject")){if(!m(e.reject))return!1;n+=1}return 0<n&&2>=n}return!1}function v(e){return"function"==typeof e&&1>=e.length}function h(e){return v(e)||y(e)}function w(e){return!(!Array.isArray(e)||2!==e.length)&&(Array.isArray(e[1])?v(e[0])&&e[1].every(h):v(e[0])&&h(e[1]))}function b(e){return!(!Array.isArray(e)||2!==e.length)&&(!!g(e[0])&&(Array.isArray(e[1])?e[1].every(h):h(e[1])))}function _(e){return w(e)||b(e)}function C(e,n){var t=0,r=0,o=e.accept;return Array.isArray(o)?e.accept.some((function(e){return A(e,n)}))&&r++:"string"==typeof o&&A(o,n)&&r++,o=e.reject,Array.isArray(o)?e.reject.some((function(e){return A(e,n)}))&&t++:"string"==typeof o&&A(o,n)&&t++,0<r&&0===t}function A(e,n){if(!f(e))return!1;if(e=d(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(!x(n[t],e[t]))return!1;return!0}return!1}(e[0],n[0]))return!1;for(var t=1;5>t;t++)if(!x(e[t],n[t]))return!1;return!0}return!1}function x(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(y(e))e=[e];else{if(v(e)){n:{var o=void 0;try{if(o=e({event:n.getPayload(),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=t()).add("e","ue"),n.addJson("ue_px","ue_pr",e),n}function P(e,n){void 0===n&&(n={});var t,r={};for(t in e)(n[t]||null!==e[t]&&void 0!==e[t])&&(r[t]=e[t]);return r}var E,O=function(){return(O=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)},S="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";e.LOG_LEVEL=void 0,(E=e.LOG_LEVEL||(e.LOG_LEVEL={}))[E.none=0]="none",E[E.error=1]="error",E[E.warn=2]="warn",E[E.debug=3]="debug",E[E.info=4]="info";var L=function(t){return void 0===t&&(t=e.LOG_LEVEL.warn),{setLogLevel:function(n){t=e.LOG_LEVEL[n]?n:e.LOG_LEVEL.warn},warn:function(r,o){for(var a=[],i=2;i<arguments.length;i++)a[i-2]=arguments[i];t>=e.LOG_LEVEL.warn&&"undefined"!=typeof console&&(i="Snowplow: "+r,o?console.warn.apply(console,n([i+"\n",o],a,!1)):console.warn.apply(console,n([i],a,!1)))},error:function(r,o){for(var a=[],i=2;i<arguments.length;i++)a[i-2]=arguments[i];t>=e.LOG_LEVEL.error&&"undefined"!=typeof console&&(i="Snowplow: "+r+"\n",o?console.error.apply(console,n([i+"\n",o],a,!1)):console.error.apply(console,n([i],a,!1)))},debug:function(r){for(var o=[],a=1;a<arguments.length;a++)o[a-1]=arguments[a];t>=e.LOG_LEVEL.debug&&"undefined"!=typeof console&&console.debug.apply(console,n(["Snowplow: "+r],o,!1))},info:function(r){for(var o=[],a=1;a<arguments.length;a++)o[a-1]=arguments[a];t>=e.LOG_LEVEL.info&&"undefined"!=typeof console&&console.info.apply(console,n(["Snowplow: "+r],o,!1))}}}(),T={},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 V=new Uint8Array(16);T=function(){return N(V),V}}else{var G=Array(16);T=function(){for(var e,n=0;16>n;n++)0==(3&n)&&(e=4294967296*Math.random()),G[n]=e>>>((3&n)<<3)&255;return G}}for(var R=[],J=0;256>J;++J)R[J]=(J+256).toString(16).substr(1);var U,z,D=function(e,n){return n=n||0,[R[e[n++]],R[e[n++]],R[e[n++]],R[e[n++]],"-",R[e[n++]],R[e[n++]],"-",R[e[n++]],R[e[n++]],"-",R[e[n++]],R[e[n++]],"-",R[e[n++]],R[e[n++]],R[e[n++]],R[e[n++]],R[e[n++]],R[e[n++]]].join("")},q=T,M=0,B=0,F=T,Z=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||F)())[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||D(e)};Z.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=q();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:B+1,l=i-M+(c-B)/1e4;if(0>l&&void 0===e.clockseq&&(a=a+1&16383),(0>l||i>M)&&void 0===e.nsecs&&(c=0),1e4<=c)throw Error("uuid.v1(): Can't create more than 10M uuids/sec");for(M=i,B=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||D(r)},Z.v4=Z,e.LOG=L,e.buildAdClick=function(e){return k({event:e={schema:"iglu:com.snowplowanalytics.snowplow/ad_click/jsonschema/1-0-0",data:P({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:P({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:P({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:P({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:P({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:P({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:P({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:P({all:n})}}),context:[e]}},e.buildEcommerceTransaction=function(e){var n=e.orderId,r=e.total,o=e.affiliation,a=e.tax,i=e.shipping,c=e.city,l=e.state,s=e.country;e=e.currency;var u=t();return u.add("e","tr"),u.add("tr_id",n),u.add("tr_af",o),u.add("tr_tt",r),u.add("tr_tx",a),u.add("tr_sh",i),u.add("tr_ci",c),u.add("tr_st",l),u.add("tr_co",s),u.add("tr_cu",e),u},e.buildEcommerceTransactionItem=function(e){var n=e.orderId,r=e.sku,o=e.price,a=e.name,i=e.category,c=e.quantity;e=e.currency;var l=t();return l.add("e","ti"),l.add("ti_id",n),l.add("ti_sk",r),l.add("ti_nm",a),l.add("ti_ca",i),l.add("ti_pr",o),l.add("ti_qu",c),l.add("ti_cu",e),l},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:P(e,{value:!0})}})},e.buildFormSubmission=function(e){return k({event:{schema:"iglu:com.snowplowanalytics.snowplow/submit_form/jsonschema/1-0-0",data:P({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:P({targetUrl:e.targetUrl,elementId:e.elementId,elementClasses:e.elementClasses,elementTarget:e.elementTarget,elementContent:e.elementContent})}})},e.buildPagePing=function(e){var n=e.pageUrl,r=e.pageTitle,o=e.referrer,a=e.minXOffset,i=e.maxXOffset,c=e.minYOffset;e=e.maxYOffset;var l=t();return l.add("e","pp"),l.add("url",n),l.add("page",r),l.add("refr",o),a&&!isNaN(Number(a))&&l.add("pp_mix",a.toString()),i&&!isNaN(Number(i))&&l.add("pp_max",i.toString()),c&&!isNaN(Number(c))&&l.add("pp_miy",c.toString()),e&&!isNaN(Number(e))&&l.add("pp_may",e.toString()),l},e.buildPageView=function(e){var n=e.pageUrl,r=e.pageTitle;e=e.referrer;var o=t();return o.add("e","pv"),o.add("url",n),o.add("page",r),o.add("refr",e),o},e.buildRemoveFromCart=function(e){return k({event:{schema:"iglu:com.snowplowanalytics.snowplow/remove_from_cart/jsonschema/1-0-0",data:P({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:P({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:P({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:P({action:e.action,network:e.network,target:e.target})}})},e.buildStructEvent=function(e){var n=e.category,r=e.action,o=e.label,a=e.property;e=e.value;var i=t();return i.add("e","se"),i.add("se_ca",n),i.add("se_ac",r),i.add("se_la",o),i.add("se_pr",a),i.add("se_va",null==e?void 0:e.toString()),i},e.getRuleParts=d,e.getSchemaParts=l,e.globalContexts=i,e.isConditionalContextProvider=_,e.isContextCallbackFunction=v,e.isContextPrimitive=h,e.isFilterProvider=w,e.isJson=a,e.isNonEmptyJson=o,e.isRuleSet=g,e.isRuleSetProvider=b,e.isSelfDescribingJson=y,e.isStringArray=p,e.isValidRule=f,e.isValidRuleSetArg=m,e.matchSchemaAgainstRule=A,e.matchSchemaAgainstRuleSet=C,e.payloadBuilder=t,e.payloadJsonProcessor=r,e.pluginContexts=c,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,t,o,l,s,u,d,f=e.base64,p=e.corePlugins,m=null!=p?p:[];n=null==f||f,t=m,o=e.callback,l=c(t),s=i(),u=n,d={};var y=O(O({},e={track:function(e,n,a){e.withJsonProcessor(r(u)),e.add("eid",Z.v4()),e.addDict(d),a=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()}}(a),e.add(a.type,a.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,l.addPluginContexts(n)))&&n.length?{schema:"iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0",data:n}:void 0)&&e.addJson("cx","co",n),t.forEach((function(n){try{n.beforeTrack&&n.beforeTrack(e)}catch(e){L.error("Plugin beforeTrack",e)}})),"function"==typeof o&&o(e);var i=e.build();return t.forEach((function(e){try{e.afterTrack&&e.afterTrack(i)}catch(e){L.error("Plugin afterTrack",e)}})),i},addPayloadPair:function(e,n){d[e]=n},getBase64Encoding:function(){return u},setBase64Encoding:function(e){u=e},addPayloadDict:function(e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(d[n]=e[n])},resetPayloadPairs:function(e){d=a(e)?e:{}},setTrackerVersion:function(e){d.tv=e},setTrackerNamespace:function(e){d.tna=e},setAppId:function(e){d.aid=e},setPlatform:function(e){d.p=e},setUserId:function(e){d.uid=e},setScreenResolution:function(e,n){d.res=e+"x"+n},setViewport:function(e,n){d.vp=e+"x"+n},setColorDepth:function(e){d.cd=e},setTimezone:function(e){d.tz=e},setLang:function(e){d.lang=e},setIpAddress:function(e){d.ip=e},setUseragent:function(e){d.ua=e},addGlobalContexts:function(e){s.addGlobalContexts(e)},clearGlobalContexts:function(){s.clearGlobalContexts()},removeGlobalContexts:function(e){s.removeGlobalContexts(e)}}),{addPlugin:function(e){var n,t;e=e.plugin,m.push(e),null===(n=e.logger)||void 0===n||n.call(e,L),null===(t=e.activateCorePlugin)||void 0===t||t.call(e,y)}});return null==m||m.forEach((function(e){var n,t;null===(n=e.logger)||void 0===n||n.call(e,L),null===(t=e.activateCorePlugin)||void 0===t||t.call(e,y)})),y},e.validateVendor=u,e.validateVendorParts=s,e.version="3.5.0",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,n,t){if(t||2===arguments.length)for(var r,o=0,a=n.length;o<a;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return e.concat(r||Array.prototype.slice.call(n))}function t(){var e,n={},t=[],r=[],a=[],i=function(e,t){null!=t&&""!==t&&(n[e]=t)};return{add:i,addDict:function(e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&i(n,e[n])},addJson:function(e,n,a){a&&o(a)&&(e={keyIfEncoded:e,keyIfNotEncoded:n,json:a},r.push(e),t.push(e))},addContextEntity:function(e){a.push(e)},getPayload:function(){return n},getJson:function(){return t},withJsonProcessor:function(n){e=n},build:function(){return null==e||e(this,r,a),n}}}function r(e){return function(t,r,o){for(var a=function(n,r,o){if(n=JSON.stringify(n),e){if(o=t.add,n){var a=0,i=0,c=[];if(n){n=unescape(encodeURIComponent(n));do{var l=n.charCodeAt(a++),s=n.charCodeAt(a++),u=n.charCodeAt(a++),d=l<<16|s<<8|u;l=d>>18&63,s=d>>12&63,u=d>>6&63,d&=63,c[i++]=S.charAt(l)+S.charAt(s)+S.charAt(u)+S.charAt(d)}while(a<n.length);a=c.join(""),n=((n=n.length%3)?a.slice(0,n-3):a)+"===".slice(n||3)}n=n.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}o.call(t,r,n)}else t.add(o,n)},i=function(n,r){if(!n){var o=t.getPayload();if(e?o.cx:o.co){var a=(n=JSON).parse;if(e){if(o=o.cx){switch(4-o.length%4){case 2:o+="==";break;case 3:o+="="}o=function(e){var n,t=0,r=0,o="",a=[];if(!e)return e;e+="";do{var i=S.indexOf(e.charAt(t++)),c=S.indexOf(e.charAt(t++));o=S.indexOf(e.charAt(t++));var l=S.indexOf(e.charAt(t++)),s=i<<18|c<<12|o<<6|l;i=s>>16&255,c=s>>8&255,s&=255,a[r++]=64===o?String.fromCharCode(i):64===l?String.fromCharCode(i,c):String.fromCharCode(i,c,s)}while(t<e.length);return o=a.join(""),n=o.replace(/\0+$/,""),decodeURIComponent(n.split("").map((function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})).join(""))}(o=o.replace(/-/g,"+").replace(/_/g,"/"))}}else o=o.co;n=a.call(n,o)}else n=void 0}return n?n.data=n.data.concat(r.data):n=r,n},c=void 0,l=0;l<r.length;l++){var s=r[l];"cx"===s.keyIfEncoded?c=i(c,s.json):a(s.json,s.keyIfEncoded,s.keyIfNotEncoded)}r.length=0,o.length&&(c=i(c,r={schema:"iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0",data:n([],o,!0)}),o.length=0),c&&a(c,"cx","co")}}function o(e){if(!a(e))return!1;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n))return!0;return!1}function a(e){return null!=e&&(e.constructor==={}.constructor||e.constructor===[].constructor)}function i(){var e=[],n=[];return{getGlobalPrimitives:function(){return e},getConditionalProviders:function(){return n},addGlobalContexts:function(t){for(var r=[],o=[],a=0;a<t.length;a++){var i=t[a];_(i)?r.push(i):h(i)&&o.push(i)}e=e.concat(o),n=n.concat(r)},clearGlobalContexts:function(){n=[],e=[]},removeGlobalContexts:function(t){for(var r=function(t){_(t)?n=n.filter((function(e){return JSON.stringify(e)!==JSON.stringify(t)})):h(t)&&(e=e.filter((function(e){return JSON.stringify(e)!==JSON.stringify(t)})))},o=0;o<t.length;o++)r(t[o])},getApplicableContexts:function(t){e:{for(var r=0,o=t.getJson();r<o.length;r++){var a=o[r];if("ue_px"===a.keyIfEncoded&&"object"==typeof a.json.data&&"string"==typeof(a=a.json.data.schema)){r=a;break e}}r=""}a="string"==typeof(o=t.getPayload().e)?o:"",o=[];var i=j(e,t,a,r);return o.push.apply(o,i),t=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.getPayload(),eventType:t,eventSchema:r})}catch(e){a=!1}if(!0===a){e=j(e[1],n,t,r);break e}}else if(b(e)&&C(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)})))}(n,t,a,r),o.push.apply(o,t),o}}}function c(e){return{addPluginContexts:function(t){var r=t?n([],t,!0):[];return e.forEach((function(e){try{e.contexts&&r.push.apply(r,e.contexts())}catch(e){L.error("Error adding plugin contexts",e)}})),r}}}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 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 u(e){return!!((e=e.split("."))&&1<e.length)&&s(e)}function d(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))&&u(e[1]))return e.slice(1,6)}function f(e){if(e=d(e)){var n=e[0];return 5===e.length&&u(n)}return!1}function p(e){return Array.isArray(e)&&e.every((function(e){return"string"==typeof e}))}function m(e){return p(e)?e.every((function(e){return f(e)})):"string"==typeof e&&f(e)}function y(e){return!!(o(e)&&"schema"in e&&"data"in e)&&("string"==typeof e.schema&&"object"==typeof e.data)}function g(e){var n=0;if(null!=e&&"object"==typeof e&&!Array.isArray(e)){if(Object.prototype.hasOwnProperty.call(e,"accept")){if(!m(e.accept))return!1;n+=1}if(Object.prototype.hasOwnProperty.call(e,"reject")){if(!m(e.reject))return!1;n+=1}return 0<n&&2>=n}return!1}function v(e){return"function"==typeof e&&1>=e.length}function h(e){return v(e)||y(e)}function w(e){return!(!Array.isArray(e)||2!==e.length)&&(Array.isArray(e[1])?v(e[0])&&e[1].every(h):v(e[0])&&h(e[1]))}function b(e){return!(!Array.isArray(e)||2!==e.length)&&(!!g(e[0])&&(Array.isArray(e[1])?e[1].every(h):h(e[1])))}function _(e){return w(e)||b(e)}function C(e,n){var t=0,r=0,o=e.accept;return Array.isArray(o)?e.accept.some((function(e){return A(e,n)}))&&r++:"string"==typeof o&&A(o,n)&&r++,o=e.reject,Array.isArray(o)?e.reject.some((function(e){return A(e,n)}))&&t++:"string"==typeof o&&A(o,n)&&t++,0<r&&0===t}function A(e,n){if(!f(e))return!1;if(e=d(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(!x(n[t],e[t]))return!1;return!0}return!1}(e[0],n[0]))return!1;for(var t=1;5>t;t++)if(!x(e[t],n[t]))return!1;return!0}return!1}function x(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(y(e))e=[e];else{if(v(e)){n:{var o=void 0;try{if(o=e({event:n.getPayload(),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=t()).add("e","ue"),n.addJson("ue_px","ue_pr",e),n}function P(e,n){void 0===n&&(n={});var t,r={};for(t in e)(n[t]||null!==e[t]&&void 0!==e[t])&&(r[t]=e[t]);return r}var E,O=function(){return O=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},O.apply(this,arguments)},S="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";e.LOG_LEVEL=void 0,(E=e.LOG_LEVEL||(e.LOG_LEVEL={}))[E.none=0]="none",E[E.error=1]="error",E[E.warn=2]="warn",E[E.debug=3]="debug",E[E.info=4]="info";var L=function(t){return void 0===t&&(t=e.LOG_LEVEL.warn),{setLogLevel:function(n){t=e.LOG_LEVEL[n]?n:e.LOG_LEVEL.warn},warn:function(r,o){for(var a=[],i=2;i<arguments.length;i++)a[i-2]=arguments[i];t>=e.LOG_LEVEL.warn&&"undefined"!=typeof console&&(i="Snowplow: "+r,o?console.warn.apply(console,n([i+"\n",o],a,!1)):console.warn.apply(console,n([i],a,!1)))},error:function(r,o){for(var a=[],i=2;i<arguments.length;i++)a[i-2]=arguments[i];t>=e.LOG_LEVEL.error&&"undefined"!=typeof console&&(i="Snowplow: "+r+"\n",o?console.error.apply(console,n([i+"\n",o],a,!1)):console.error.apply(console,n([i],a,!1)))},debug:function(r){for(var o=[],a=1;a<arguments.length;a++)o[a-1]=arguments[a];t>=e.LOG_LEVEL.debug&&"undefined"!=typeof console&&console.debug.apply(console,n(["Snowplow: "+r],o,!1))},info:function(r){for(var o=[],a=1;a<arguments.length;a++)o[a-1]=arguments[a];t>=e.LOG_LEVEL.info&&"undefined"!=typeof console&&console.info.apply(console,n(["Snowplow: "+r],o,!1))}}}(),T={},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 V=new Uint8Array(16);T=function(){return N(V),V}}else{var G=Array(16);T=function(){for(var e,n=0;16>n;n++)0==(3&n)&&(e=4294967296*Math.random()),G[n]=e>>>((3&n)<<3)&255;return G}}for(var R=[],J=0;256>J;++J)R[J]=(J+256).toString(16).substr(1);var U,z,D=function(e,n){return n=n||0,[R[e[n++]],R[e[n++]],R[e[n++]],R[e[n++]],"-",R[e[n++]],R[e[n++]],"-",R[e[n++]],R[e[n++]],"-",R[e[n++]],R[e[n++]],"-",R[e[n++]],R[e[n++]],R[e[n++]],R[e[n++]],R[e[n++]],R[e[n++]]].join("")},q=T,M=0,B=0,F=T,Z=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||F)())[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||D(e)};Z.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=q();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:B+1,l=i-M+(c-B)/1e4;if(0>l&&void 0===e.clockseq&&(a=a+1&16383),(0>l||i>M)&&void 0===e.nsecs&&(c=0),1e4<=c)throw Error("uuid.v1(): Can't create more than 10M uuids/sec");for(M=i,B=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||D(r)},Z.v4=Z,e.LOG=L,e.buildAdClick=function(e){return k({event:e={schema:"iglu:com.snowplowanalytics.snowplow/ad_click/jsonschema/1-0-0",data:P({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:P({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:P({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:P({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:P({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:P({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:P({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:P({all:n})}}),context:[e]}},e.buildEcommerceTransaction=function(e){var n=e.orderId,r=e.total,o=e.affiliation,a=e.tax,i=e.shipping,c=e.city,l=e.state,s=e.country;e=e.currency;var u=t();return u.add("e","tr"),u.add("tr_id",n),u.add("tr_af",o),u.add("tr_tt",r),u.add("tr_tx",a),u.add("tr_sh",i),u.add("tr_ci",c),u.add("tr_st",l),u.add("tr_co",s),u.add("tr_cu",e),u},e.buildEcommerceTransactionItem=function(e){var n=e.orderId,r=e.sku,o=e.price,a=e.name,i=e.category,c=e.quantity;e=e.currency;var l=t();return l.add("e","ti"),l.add("ti_id",n),l.add("ti_sk",r),l.add("ti_nm",a),l.add("ti_ca",i),l.add("ti_pr",o),l.add("ti_qu",c),l.add("ti_cu",e),l},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:P(e,{value:!0})}})},e.buildFormSubmission=function(e){return k({event:{schema:"iglu:com.snowplowanalytics.snowplow/submit_form/jsonschema/1-0-0",data:P({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:P({targetUrl:e.targetUrl,elementId:e.elementId,elementClasses:e.elementClasses,elementTarget:e.elementTarget,elementContent:e.elementContent})}})},e.buildPagePing=function(e){var n=e.pageUrl,r=e.pageTitle,o=e.referrer,a=e.minXOffset,i=e.maxXOffset,c=e.minYOffset;e=e.maxYOffset;var l=t();return l.add("e","pp"),l.add("url",n),l.add("page",r),l.add("refr",o),a&&!isNaN(Number(a))&&l.add("pp_mix",a.toString()),i&&!isNaN(Number(i))&&l.add("pp_max",i.toString()),c&&!isNaN(Number(c))&&l.add("pp_miy",c.toString()),e&&!isNaN(Number(e))&&l.add("pp_may",e.toString()),l},e.buildPageView=function(e){var n=e.pageUrl,r=e.pageTitle;e=e.referrer;var o=t();return o.add("e","pv"),o.add("url",n),o.add("page",r),o.add("refr",e),o},e.buildRemoveFromCart=function(e){return k({event:{schema:"iglu:com.snowplowanalytics.snowplow/remove_from_cart/jsonschema/1-0-0",data:P({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:P({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:P({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:P({action:e.action,network:e.network,target:e.target})}})},e.buildStructEvent=function(e){var n=e.category,r=e.action,o=e.label,a=e.property;e=e.value;var i=t();return i.add("e","se"),i.add("se_ca",n),i.add("se_ac",r),i.add("se_la",o),i.add("se_pr",a),i.add("se_va",null==e?void 0:e.toString()),i},e.getRuleParts=d,e.getSchemaParts=l,e.globalContexts=i,e.isConditionalContextProvider=_,e.isContextCallbackFunction=v,e.isContextPrimitive=h,e.isFilterProvider=w,e.isJson=a,e.isNonEmptyJson=o,e.isRuleSet=g,e.isRuleSetProvider=b,e.isSelfDescribingJson=y,e.isStringArray=p,e.isValidRule=f,e.isValidRuleSetArg=m,e.matchSchemaAgainstRule=A,e.matchSchemaAgainstRuleSet=C,e.payloadBuilder=t,e.payloadJsonProcessor=r,e.pluginContexts=c,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,t,o,l,s,u,d,f=e.base64,p=e.corePlugins,m=null!=p?p:[];n=null==f||f,t=m,o=e.callback,l=c(t),s=i(),u=n,d={};var y=O(O({},e={track:function(e,n,a){e.withJsonProcessor(r(u)),e.add("eid",Z.v4()),e.addDict(d),a=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()}}(a),e.add(a.type,a.value.toString()),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,l.addPluginContexts(n)),void 0!==(n=n&&n.length?{schema:"iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-0",data:n}:void 0)&&e.addJson("cx","co",n),t.forEach((function(n){try{n.beforeTrack&&n.beforeTrack(e)}catch(e){L.error("Plugin beforeTrack",e)}})),"function"==typeof o&&o(e);var i=e.build();return t.forEach((function(e){try{e.afterTrack&&e.afterTrack(i)}catch(e){L.error("Plugin afterTrack",e)}})),i},addPayloadPair:function(e,n){d[e]=n},getBase64Encoding:function(){return u},setBase64Encoding:function(e){u=e},addPayloadDict:function(e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(d[n]=e[n])},resetPayloadPairs:function(e){d=a(e)?e:{}},setTrackerVersion:function(e){d.tv=e},setTrackerNamespace:function(e){d.tna=e},setAppId:function(e){d.aid=e},setPlatform:function(e){d.p=e},setUserId:function(e){d.uid=e},setScreenResolution:function(e,n){d.res=e+"x"+n},setViewport:function(e,n){d.vp=e+"x"+n},setColorDepth:function(e){d.cd=e},setTimezone:function(e){d.tz=e},setLang:function(e){d.lang=e},setIpAddress:function(e){d.ip=e},setUseragent:function(e){d.ua=e},addGlobalContexts:function(e){s.addGlobalContexts(e)},clearGlobalContexts:function(){s.clearGlobalContexts()},removeGlobalContexts:function(e){s.removeGlobalContexts(e)}}),{addPlugin:function(e){var n,t;e=e.plugin,m.push(e),null===(n=e.logger)||void 0===n||n.call(e,L),null===(t=e.activateCorePlugin)||void 0===t||t.call(e,y)}});return null==m||m.forEach((function(e){var n,t;null===(n=e.logger)||void 0===n||n.call(e,L),null===(t=e.activateCorePlugin)||void 0===t||t.call(e,y)})),y},e.validateVendor=u,e.validateVendorParts=s,e.version="3.6.0",Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "@snowplow/tracker-core", | ||
"version": "3.5.0", | ||
"version": "3.6.0", | ||
"description": "Core functionality for Snowplow JavaScript trackers", | ||
@@ -70,3 +70,3 @@ "keywords": [ | ||
}, | ||
"readme": "# Snowplow Tracker Core\n\n[![npm version][npm-image]][npm-url]\n[![License][license-image]](LICENSE)\n\nCore module to be used by Snowplow JavaScript based trackers.\n\n## Maintainer quick start\n\nPart of the Snowplow JavaScript Tracker monorepo. \nBuild with [Node.js](https://nodejs.org/en/) (12 LTS or 14 LTS) 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### Building Tracker Core\n\n```bash\ncd libraries/tracker-core\nrushx build\n```\n\n### Running tests\n\n```bash\nrushx test\n```\n\n## Package Installation\n\nWith npm:\n\n```bash\nnpm install @snowplow/tracker-core\n```\n\n## Usage\n\n### CommonJS Example\n\n```js\nconst trackerCore = require('@snowplow/tracker-core').trackerCore;\n\n// Create an instance with base 64 encoding set to false (it defaults to true)\nconst core = trackerCore(false);\n```\n\n### ES Module Example\n\n```js\nimport { trackerCore } from '@snowplow/tracker-core';\n\n// Create an instance with base 64 encoding set to false (it defaults to true)\nconst core = trackerCore(false)\n```\n\n### Example\n\n```js\n// Add a name-value pair to all payloads\ncore.addPayloadPair('vid', 2);\n\n// Add each name-value pair in a dictionary to all payloads\ncore.addPayloadDict({\n 'ds': '1160x620',\n 'fp': 4070134789\n});\n\n// Add name-value pairs to all payloads using convenience methods\ncore.setTrackerVersion('js-3.0.0');\ncore.setPlatform('web');\ncore.setUserId('user-321');\ncore.setColorDepth(24);\ncore.setViewport(600, 400);\ncore.setUseragent('Snowplow/0.0.1');\n\n// Track a page view with URL and title\nconst pageViewPayload = core.track(buildPageView({ pageUrl: 'http://www.example.com', pageTitle: 'landing page'});\n\nconsole.log(pageViewPayload.build());\n/*\n{\n 'e': 'pv',\n 'url': 'http://www.example.com',\n 'page': 'landing page',\n 'uid': 'user-321',\n 'vd': 2,\n 'ds': '1160x620',\n 'fp': 4070134789\n 'tv': 'js-3.0.0',\n 'p': 'web',\n 'cd': 24,\n 'vp': '600x400',\n 'ua': 'Snowplow/0.0.1',\n 'dtm': 1406879959702, // timestamp\n 'eid': '0718a85a-45dc-4f71-a949-27870442ed7d' // UUID\n}\n*/\n\n// Stop automatically adding tv, p, and dtm to the payload\ncore.resetPayloadPairs();\n\n// Track an unstructured event\nconst selfDescribingEventPayload = core.track(buildSelfDescribingEvent({ \n event: {\n 'schema': 'iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-0',\n 'data': {\n 'targetUrl': 'http://www.destination.com',\n 'elementId': 'bannerLink'\n }\n }\n});\n\nconsole.log(selfDescribingEventPayload.build());\n/*\n{\n 'e': 'ue',\n 'ue_pr': {\n 'schema': 'iglu:com.snowplowanalytics.snowplow/unstruct_even/jsonschema/1-0-0',\n 'data': {\n 'schema': 'iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-0',\n 'data': {\n 'targetUrl': 'http://www.destination.com',\n 'elementId': 'bannerLink'\n }\n }\n },\n 'dtm': 1406879973439,\n 'eid': '956c6670-cbf6-460b-9f96-143e0320fdf6'\n}\n*/\n```\n\n## Other features\n\nCore instances can be initialized with three parameters. The first is a boolean and determines whether custom contexts and unstructured events will be base 64 encoded. The second are optional Core Plugins, these can be used to intercept payload creation and add contexts on every event. The third is an optional callback function which gets applied to every payload created by the instance.\n\n```js\nconst core = trackerCore(true, [], console.log);\n```\n\nThe above example would base 64 encode all unstructured events and custom contexts and would log each payload to the console.\n\nUse the `setBase64Encoding` method to turn base 64 encoding on or off after initializing a core instance:\n\n```js\nconst core = trackerCore(); // Base 64 encoding on by default\n\ncore.setBase64Encoding(false); // Base 64 encoding is now off\n```\n\n## Documentation\n\nFor more information on the Snowplow JavaScript Tracker Core's API, view its [docs page][docs].\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/tracker-core\n[npm-image]: https://img.shields.io/npm/v/@snowplow/tracker-core\n[docs]: https://docs.snowplowanalytics.com/docs/collecting-data/collecting-from-own-applications/node-js-tracker/javascript-tracker-core/\n[osi]: https://opensource.org/licenses/BSD-3-Clause\n[license-image]: https://img.shields.io/npm/l/@snowplow/tracker-core\n" | ||
"readme": "# Snowplow Tracker Core\n\n[![npm version][npm-image]][npm-url]\n[![License][license-image]](LICENSE)\n\nCore module to be used by Snowplow JavaScript based trackers.\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### Building Tracker Core\n\n```bash\ncd libraries/tracker-core\nrushx build\n```\n\n### Running tests\n\n```bash\nrushx test\n```\n\n## Package Installation\n\nWith npm:\n\n```bash\nnpm install @snowplow/tracker-core\n```\n\n## Usage\n\n### CommonJS Example\n\n```js\nconst trackerCore = require('@snowplow/tracker-core').trackerCore;\n\n// Create an instance with base 64 encoding set to false (it defaults to true)\nconst core = trackerCore({\n base64: false\n});\n```\n\n### ES Module Example\n\n```js\nimport { trackerCore } from '@snowplow/tracker-core';\n\n// Create an instance with base 64 encoding set to false (it defaults to true)\nconst core = trackerCore({\n base64: false\n})\n```\n\n### Example\n\n```js\n// Add a name-value pair to all payloads\ncore.addPayloadPair('vid', 2);\n\n// Add each name-value pair in a dictionary to all payloads\ncore.addPayloadDict({\n 'ds': '1160x620',\n 'fp': 4070134789\n});\n\n// Add name-value pairs to all payloads using convenience methods\ncore.setTrackerVersion('js-3.6.0');\ncore.setPlatform('web');\ncore.setUserId('user-321');\ncore.setColorDepth('24');\ncore.setViewport('600', '400');\ncore.setUseragent('Snowplow/0.0.1');\n\n// Track a page view with URL and title\nconst pageViewPayload = core.track(\n buildPageView({\n pageUrl: 'http://www.example.com',\n pageTitle: 'landing page',\n })\n);\n\nconsole.log(pageViewPayload);\n/*\n{\n 'e': 'pv',\n 'url': 'http://www.example.com',\n 'page': 'landing page',\n 'uid': 'user-321',\n 'vid': 2,\n 'ds': '1160x620',\n 'fp': 4070134789,\n 'tv': 'js-3.6.0',\n 'p': 'web',\n 'cd': '24',\n 'vp': '600x400',\n 'ua': 'Snowplow/0.0.1',\n 'dtm': '1406879959702', // timestamp\n 'eid': 'cd39f493-dd3c-4838-b096-6e6f31015409' // UUID\n}\n*/\n\n// Stop automatically adding tv, p, and dtm to the payload.\ncore.resetPayloadPairs({});\n\n// Track an unstructured event\nconst selfDescribingEventPayload = core.track(\n buildSelfDescribingEvent({\n event: {\n 'schema': 'iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-0',\n 'data': {\n 'targetUrl': 'http://www.destination.com',\n 'elementId': 'bannerLink'\n }\n }\n })\n);\n\nconsole.log(selfDescribingEventPayload);\n/*\n{\n 'e': 'ue',\n 'eid': '4ed5da6b-7fff-4f24-a8a9-21bc749881c6',\n 'dtm': '1659086693634',\n 'ue_pr': \"{\\\"schema\\\":\\\"iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0\\\",\\\"data\\\":{\\\"schema\\\":\\\"iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-0\\\",\\\"data\\\":{\\\"targetUrl\\\":\\\"http://www.destination.com\\\",\\\"elementId\\\":\\\"bannerLink\\\"}}}\"\n}\n*/\n```\n\n## Other features\n\nCore instances can be initialized with a configuration object. `base64` Determines whether custom contexts and unstructured events will be base 64 encoded. `corePlugins` are used to intercept payload creation and add contexts on every event. `callback` is an optional callback function which gets applied to every payload created by the instance.\n\n```js\nconst core = trackerCore({\n base64: true,\n corePlugins: [/* Your plugins here*/],\n callback: console.log\n});\n```\n\nThe above example would base 64 encode all unstructured events and custom contexts and would log each payload to the console.\n\nUse the `setBase64Encoding` method to turn base 64 encoding on or off after initializing a core instance:\n\n```js\nconst core = trackerCore(); // Base 64 encoding on by default\n\ncore.setBase64Encoding(false); // Base 64 encoding is now off\n```\n\n## Documentation\n\nFor more information on the Snowplow JavaScript Tracker Core's API, view its [docs page][docs].\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/tracker-core\n[npm-image]: https://img.shields.io/npm/v/@snowplow/tracker-core\n[docs]: https://docs.snowplowanalytics.com/docs/collecting-data/collecting-from-own-applications/node-js-tracker/javascript-tracker-core/\n[osi]: https://opensource.org/licenses/BSD-3-Clause\n[license-image]: https://img.shields.io/npm/l/@snowplow/tracker-core\n" | ||
} |
@@ -11,3 +11,3 @@ # Snowplow Tracker Core | ||
Part of the Snowplow JavaScript Tracker monorepo. | ||
Build with [Node.js](https://nodejs.org/en/) (12 LTS or 14 LTS) and [Rush](https://rushjs.io/). | ||
Build with [Node.js](https://nodejs.org/en/) (14 or 16) and [Rush](https://rushjs.io/). | ||
@@ -51,3 +51,5 @@ ### Setup repository | ||
// Create an instance with base 64 encoding set to false (it defaults to true) | ||
const core = trackerCore(false); | ||
const core = trackerCore({ | ||
base64: false | ||
}); | ||
``` | ||
@@ -61,3 +63,5 @@ | ||
// Create an instance with base 64 encoding set to false (it defaults to true) | ||
const core = trackerCore(false) | ||
const core = trackerCore({ | ||
base64: false | ||
}) | ||
``` | ||
@@ -78,13 +82,18 @@ | ||
// Add name-value pairs to all payloads using convenience methods | ||
core.setTrackerVersion('js-3.0.0'); | ||
core.setTrackerVersion('js-3.6.0'); | ||
core.setPlatform('web'); | ||
core.setUserId('user-321'); | ||
core.setColorDepth(24); | ||
core.setViewport(600, 400); | ||
core.setColorDepth('24'); | ||
core.setViewport('600', '400'); | ||
core.setUseragent('Snowplow/0.0.1'); | ||
// Track a page view with URL and title | ||
const pageViewPayload = core.track(buildPageView({ pageUrl: 'http://www.example.com', pageTitle: 'landing page'}); | ||
const pageViewPayload = core.track( | ||
buildPageView({ | ||
pageUrl: 'http://www.example.com', | ||
pageTitle: 'landing page', | ||
}) | ||
); | ||
console.log(pageViewPayload.build()); | ||
console.log(pageViewPayload); | ||
/* | ||
@@ -96,36 +105,22 @@ { | ||
'uid': 'user-321', | ||
'vd': 2, | ||
'vid': 2, | ||
'ds': '1160x620', | ||
'fp': 4070134789 | ||
'tv': 'js-3.0.0', | ||
'fp': 4070134789, | ||
'tv': 'js-3.6.0', | ||
'p': 'web', | ||
'cd': 24, | ||
'cd': '24', | ||
'vp': '600x400', | ||
'ua': 'Snowplow/0.0.1', | ||
'dtm': 1406879959702, // timestamp | ||
'eid': '0718a85a-45dc-4f71-a949-27870442ed7d' // UUID | ||
'dtm': '1406879959702', // timestamp | ||
'eid': 'cd39f493-dd3c-4838-b096-6e6f31015409' // UUID | ||
} | ||
*/ | ||
// Stop automatically adding tv, p, and dtm to the payload | ||
core.resetPayloadPairs(); | ||
// Stop automatically adding tv, p, and dtm to the payload. | ||
core.resetPayloadPairs({}); | ||
// Track an unstructured event | ||
const selfDescribingEventPayload = core.track(buildSelfDescribingEvent({ | ||
event: { | ||
'schema': 'iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-0', | ||
'data': { | ||
'targetUrl': 'http://www.destination.com', | ||
'elementId': 'bannerLink' | ||
} | ||
} | ||
}); | ||
console.log(selfDescribingEventPayload.build()); | ||
/* | ||
{ | ||
'e': 'ue', | ||
'ue_pr': { | ||
'schema': 'iglu:com.snowplowanalytics.snowplow/unstruct_even/jsonschema/1-0-0', | ||
'data': { | ||
const selfDescribingEventPayload = core.track( | ||
buildSelfDescribingEvent({ | ||
event: { | ||
'schema': 'iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-0', | ||
@@ -137,5 +132,12 @@ 'data': { | ||
} | ||
}, | ||
'dtm': 1406879973439, | ||
'eid': '956c6670-cbf6-460b-9f96-143e0320fdf6' | ||
}) | ||
); | ||
console.log(selfDescribingEventPayload); | ||
/* | ||
{ | ||
'e': 'ue', | ||
'eid': '4ed5da6b-7fff-4f24-a8a9-21bc749881c6', | ||
'dtm': '1659086693634', | ||
'ue_pr': "{\"schema\":\"iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0\",\"data\":{\"schema\":\"iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-0\",\"data\":{\"targetUrl\":\"http://www.destination.com\",\"elementId\":\"bannerLink\"}}}" | ||
} | ||
@@ -147,6 +149,10 @@ */ | ||
Core instances can be initialized with three parameters. The first is a boolean and determines whether custom contexts and unstructured events will be base 64 encoded. The second are optional Core Plugins, these can be used to intercept payload creation and add contexts on every event. The third is an optional callback function which gets applied to every payload created by the instance. | ||
Core instances can be initialized with a configuration object. `base64` Determines whether custom contexts and unstructured events will be base 64 encoded. `corePlugins` are used to intercept payload creation and add contexts on every event. `callback` is an optional callback function which gets applied to every payload created by the instance. | ||
```js | ||
const core = trackerCore(true, [], console.log); | ||
const core = trackerCore({ | ||
base64: true, | ||
corePlugins: [/* Your plugins here*/], | ||
callback: console.log | ||
}); | ||
``` | ||
@@ -153,0 +159,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
1042837
180