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

@bcatalog/enhanced-ecommerce

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bcatalog/enhanced-ecommerce - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

2

package.json
{
"name": "@bcatalog/enhanced-ecommerce",
"version": "1.1.1",
"version": "1.1.2",
"description": "",

@@ -5,0 +5,0 @@ "source": "index.js",

@@ -242,4 +242,2 @@ (() => {

);
const handleCheckoutFormChange = $f57664131f4354de$export$61fc7d43ac8f84b0($f57664131f4354de$export$7851e0b8935b3476('checkout:formChange'), 1000);
bCatalog.events.appEvents('checkout:formChange', handleCheckoutFormChange);
}

@@ -246,0 +244,0 @@ /**

@@ -1,1 +0,1 @@

(()=>{const t=t=>t.toFixed(2),e=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o=(t,e)=>Array.isArray(e)?e.reduce(((e,o)=>(e[o[t]]=o,e)),{}):null;function r(o){const r={id:o.id,name:o.title,category:o?.category?.title};return e(o,"price")&&(r.price=t(o.price)),r}function a(e){const o={id:e.product.id,price:t(e.price),quantity:e.amount,name:e.product.title};return e.option&&(o.variant=e.option.title),o}class c{constructor(t){this.dataLayer=t}static create(t){return new this(t)}resetEcommerce(){this.dataLayer.push({ecommerce:null})}createEvent(t,e,o){return{event:t,ecommerce:{[e]:o}}}createAction(t,e){return{ecommerce:{[t]:e}}}addPositions(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createEvent("addToCart","add",{products:t.map(a)}))}dropPosition(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createEvent("removeFromCart","remove",{products:t.map(a)}))}updateCart({oldCart:t,newCart:r}){const a=(t&&o("id",t.positions))??{},c=(r&&o("id",r.positions))??{},s=Object.assign({},a,c),n=[],i=[];for(const t in c){if(!e(a,t)){i.push(t);break}if(a[t].amount!==c[t].amount){i.push(t);break}}for(const t in a)e(c,t)||n.push(t);i.length>0&&this.addPositions(i.map((t=>s[t]))),n.length>0&&this.dropPosition(n.map((t=>s[t])))}clickProduct(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createEvent("productClick","click",{products:[r(t)]}))}detailViewProduct(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createAction("detail",{products:[r(t)]}))}purchase({order:t}){this.resetEcommerce(),dataLayer.push(this.createAction("purchase",{actionField:{id:t.id,shipping:t.total-t.subtotal,revenue:t.total}}))}productsAppears({products:t}){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createAction("impressions",[t.map(((t,e)=>({...r(t),position:e+1})))]))}}const s="PRODUCT";function n({dataLayer:t,bCatalog:e}){const o=c.create(t);let r;e.events.onPageSwitch((function(t){if(t.type===s)o.clickProduct({id:t.params.productId})})),e.events.onPageLoaded((function(t){if(t.type===s)o.detailViewProduct(t.params.product)})),e.events.onCartChanged((t=>{o.updateCart({newCart:t,oldCart:r}),r=t})),e.events.appEvents("category:productAppears",(({products:t})=>o.productsAppears({products:t}))),e.events.appEvents("order:created",(({order:t})=>o.purchase({order:t})));const a=function(t,e=0){let o;const r=function(){clearTimeout(o),o=setTimeout(t.bind(this,...arguments),e)};return r.cancel=()=>clearTimeout(o),r}(((t,e=!1)=>o=>(e?console.groupCollapsed(t):console.group(t),console.log(o),console.groupEnd(),o))("checkout:formChange"),1e3);e.events.appEvents("checkout:formChange",a)}!function(t,e){t?e?n({bCatalog:e,dataLayer:t}):console.error("Can't find BCatalog storefront"):console.error("Can't find dataLayer")}(window.dataLayer,window.BCatalog)})();
(()=>{const t=t=>t.toFixed(2),e=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r=(t,e)=>Array.isArray(e)?e.reduce(((e,r)=>(e[r[t]]=r,e)),{}):null;function a(r){const a={id:r.id,name:r.title,category:r?.category?.title};return e(r,"price")&&(a.price=t(r.price)),a}function o(e){const r={id:e.product.id,price:t(e.price),quantity:e.amount,name:e.product.title};return e.option&&(r.variant=e.option.title),r}class c{constructor(t){this.dataLayer=t}static create(t){return new this(t)}resetEcommerce(){this.dataLayer.push({ecommerce:null})}createEvent(t,e,r){return{event:t,ecommerce:{[e]:r}}}createAction(t,e){return{ecommerce:{[t]:e}}}addPositions(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createEvent("addToCart","add",{products:t.map(o)}))}dropPosition(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createEvent("removeFromCart","remove",{products:t.map(o)}))}updateCart({oldCart:t,newCart:a}){const o=(t&&r("id",t.positions))??{},c=(a&&r("id",a.positions))??{},s=Object.assign({},o,c),i=[],n=[];for(const t in c){if(!e(o,t)){n.push(t);break}if(o[t].amount!==c[t].amount){n.push(t);break}}for(const t in o)e(c,t)||i.push(t);n.length>0&&this.addPositions(n.map((t=>s[t]))),i.length>0&&this.dropPosition(i.map((t=>s[t])))}clickProduct(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createEvent("productClick","click",{products:[a(t)]}))}detailViewProduct(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createAction("detail",{products:[a(t)]}))}purchase({order:t}){this.resetEcommerce(),dataLayer.push(this.createAction("purchase",{actionField:{id:t.id,shipping:t.total-t.subtotal,revenue:t.total}}))}productsAppears({products:t}){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createAction("impressions",[t.map(((t,e)=>({...a(t),position:e+1})))]))}}const s="PRODUCT";!function(t,e){t?e?function({dataLayer:t,bCatalog:e}){const r=c.create(t);let a;e.events.onPageSwitch((function(t){t.type===s&&r.clickProduct({id:t.params.productId})})),e.events.onPageLoaded((function(t){t.type===s&&r.detailViewProduct(t.params.product)})),e.events.onCartChanged((t=>{r.updateCart({newCart:t,oldCart:a}),a=t})),e.events.appEvents("category:productAppears",(({products:t})=>r.productsAppears({products:t}))),e.events.appEvents("order:created",(({order:t})=>r.purchase({order:t})))}({bCatalog:e,dataLayer:t}):console.error("Can't find BCatalog storefront"):console.error("Can't find dataLayer")}(window.dataLayer,window.BCatalog)})();
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