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.2.1 to 1.2.2

3

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

@@ -18,2 +18,3 @@ "source": "index.js",

"build": "parcel build",
"publish": "npm run build && npm publish",
"pretty": "npx prettier --write \"src/**/*.js\"",

@@ -20,0 +21,0 @@ "test": "echo \"Error: no test specified\" && exit 1"

@@ -193,2 +193,6 @@ (() => {

id: item.product_id,
name: $f57664131f4354de$export$3988ae62b71be9a3(item, [
'product',
'title'
]),
price: item.price,

@@ -195,0 +199,0 @@ quantity: item.amount,

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

(()=>{const t=t=>t.toFixed(2),e=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r=t=>"object"==typeof t&&null!==t,o=(t,e)=>{let o=t;for(const t of e){if(!r(o))return;o=o[t]}return o},a=(t,e)=>Array.isArray(e)?e.reduce(((e,r)=>(e[r[t]]=r,e)),{}):null;function c(r){const o={id:r.id,name:r.title,category:r?.category?.title};return e(r,"price")&&(o.price=t(r.price)),o}function s(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 i{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(s)}))}dropPosition(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createEvent("removeFromCart","remove",{products:t.map(s)}))}updateCart({oldCart:t,newCart:r}){const o=(t&&a("id",t.positions))??{},c=(r&&a("id",r.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:[c(t)]}))}detailViewProduct(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createAction("detail",{products:[c(t)]}))}purchase({order:t}){this.resetEcommerce();const e={actionField:{id:t.id,shipping:t.total-t.subtotal,revenue:t.total}};Array.isArray(t.items)&&(e.products=t.items.map((t=>({id:t.product_id,price:t.price,quantity:t.amount,variant:o(t,["product_option","title"])})))),dataLayer.push(this.createAction("purchase",e))}productsAppears({products:t}){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createAction("impressions",[t.map(((t,e)=>({...c(t),position:e+1})))]))}}const n="PRODUCT";!function(t,e){t?e?function({dataLayer:t,bCatalog:e}){const r=i.create(t);e.events.onPageSwitch((function(t){t.type===n&&r.clickProduct({id:t.params.productId})})),e.events.onPageLoaded((function(t){t.type===n&&r.detailViewProduct(t.params.product)}));let o,a=null;e.events.appEvents("cart:actionSource",(({actionSource:t})=>{a=t})),e.events.onCartChanged((t=>{"user"===a&&r.updateCart({newCart:t,oldCart:o}),o=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)})();
(()=>{const t=t=>t.toFixed(2),e=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r=t=>"object"==typeof t&&null!==t,o=(t,e)=>{let o=t;for(const t of e){if(!r(o))return;o=o[t]}return o},a=(t,e)=>Array.isArray(e)?e.reduce(((e,r)=>(e[r[t]]=r,e)),{}):null;function c(r){const o={id:r.id,name:r.title,category:r?.category?.title};return e(r,"price")&&(o.price=t(r.price)),o}function s(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 i{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(s)}))}dropPosition(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createEvent("removeFromCart","remove",{products:t.map(s)}))}updateCart({oldCart:t,newCart:r}){const o=(t&&a("id",t.positions))??{},c=(r&&a("id",r.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:[c(t)]}))}detailViewProduct(t){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createAction("detail",{products:[c(t)]}))}purchase({order:t}){this.resetEcommerce();const e={actionField:{id:t.id,shipping:t.total-t.subtotal,revenue:t.total}};Array.isArray(t.items)&&(e.products=t.items.map((t=>({id:t.product_id,name:o(t,["product","title"]),price:t.price,quantity:t.amount,variant:o(t,["product_option","title"])})))),dataLayer.push(this.createAction("purchase",e))}productsAppears({products:t}){const{dataLayer:e}=this;this.resetEcommerce(),e.push(this.createAction("impressions",[t.map(((t,e)=>({...c(t),position:e+1})))]))}}const n="PRODUCT";!function(t,e){t?e?function({dataLayer:t,bCatalog:e}){const r=i.create(t);e.events.onPageSwitch((function(t){t.type===n&&r.clickProduct({id:t.params.productId})})),e.events.onPageLoaded((function(t){t.type===n&&r.detailViewProduct(t.params.product)}));let o,a=null;e.events.appEvents("cart:actionSource",(({actionSource:t})=>{a=t})),e.events.onCartChanged((t=>{"user"===a&&r.updateCart({newCart:t,oldCart:o}),o=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