@depict-ai/dpc 1.0.15 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/main.js +1 -1
- package/dist/module.js +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
var t=require("@depict-ai/utilishared");function e(t,e,i,r){Object.defineProperty(t,e,{get:i,set:r,enumerable:!0,configurable:!0})}e(module.exports,"DPC",(()=>g)),e(module.exports,"version",(()=>i));
|
|
2
2
|
/*! Depict PerformanceClient */
|
|
3
|
-
const i="1.0.
|
|
3
|
+
const i="1.0.17";let r;var n;(n=r||(r={}))[n.Recommendation=0]="Recommendation",n[n.SnakeRecommendation=1]="SnakeRecommendation",n[n.SearchResult=2]="SearchResult",n[n.ProductListingResult=3]="ProductListingResult";const s={[r.Recommendation]:"recommendation_id",[r.SnakeRecommendation]:"recommendation_id",[r.SearchResult]:"search_result_id",[r.ProductListingResult]:"product_listing_result_id"},o=".depict-add-to-cart",d={"data-recommendation_id":r.SnakeRecommendation,"data-recommendation-id":r.Recommendation,"data-search-result-id":r.SearchResult,"data-product-listing-result-id":r.ProductListingResult};const a=(t,e)=>{if("number"==typeof e&&!isNaN(e))return e.toString();if("string"!=typeof e)throw new Error(`${t} event requires a string as an argument`);return e},c=(t,e)=>null==e?e:a(t,e),u=(t,e,i)=>{if("purchase"!==e)"number"==typeof i&&(i=i.toString()),"addToCart"===e?t.sendAddToCartEvent({product_id:a(e,i)}):"setMarket"===e?t.setMarket(a(e,i)):"setProductId"===e?t.setProductId(a(e,i)):"setUserId"===e?t.setUserId(c(e,i)):"setSessionId"===e&&t.setSessionId(c(e,i));else{if(!(t=>{if("object"!=typeof t||null===t)throw new Error("purchase event requires an object as an argument");if(!Array.isArray(t.items))throw new Error("purchase event requires an items array of purchased products");if(!t.currency||"string"!=typeof t.currency)throw new Error("purchase event requires a currency string");if(!t.transaction_id||"string"!=typeof t.transaction_id&&"number"!=typeof t.transaction_id)throw new Error("purchase event requires a transaction_id string");t.transaction_id=t.transaction_id.toString();for(const e of t.items){if(""==e.item_id||isNaN(e.item_id)||"string"!=typeof e.item_id&&"number"!=typeof e.item_id)throw new Error("purchased item requires an item_id of the purchased product");if(isNaN(e.price))throw new Error("purchase item requires a unit price for the product purchased");if(!e.quantity||isNaN(e.quantity))throw new Error("purchase item requires a quantity of products purchased");e.item_id=e.item_id.toString()}return!0})(i))return;t.sendPurchaseEvent(i)}},h=t=>{const e=window.dpq||=function(){const t=function(){const e=arguments;t.send_event?t.send_event.apply(this,e):t.queue.push(e)};return t.queue=[],t}(),i=window.depict||={};i.dpq=e,i.eventHistory=e.queue,i.dpc=t,e.send_event||(e.send_event=(i,r)=>{e.queue.push([i,r]),u(t,i,r)},e.queue.forEach((([e,i])=>{u(t,e,i)})))};function _(t,e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var l=0;function p(t){return"__private_"+l+++"_"+t}var m=p("parseOptions"),v=p("getContextData"),f=p("sendTrackingEvent"),k=p("getProductId");class g{constructor(e,i){if(Object.defineProperty(this,k,{value:R}),Object.defineProperty(this,f,{value:w}),Object.defineProperty(this,v,{value:b}),Object.defineProperty(this,m,{value:y}),this.merchant=void 0,this.auto_observe=!0,this.market=void 0,this.latest_product_id=void 0,this.latest_product_id_path=void 0,this.latest_session_id=void 0,this.latest_user_id=void 0,this.tracked_elements=new WeakSet,window.depict?.dpc instanceof g)return(0,t.dlog)("DPC already initialized. Returning existing instance."),window.depict.dpc;h(this),this.merchant=e,_(this,m)[m](i),this.auto_observe&&(this.observeRecommendations(),this.observePDPA2CButton())}checkIfTracked(e){return this.tracked_elements.has(e)?((0,t.dlog)("Already tracked",e),!0):(this.tracked_elements.add(e),!1)}trackProductCard(e,i,n){if(this.checkIfTracked(e))return;switch(n){case r.Recommendation:case r.SnakeRecommendation:e.addEventListener("click",(()=>this.sendRecommendationClickEvent(i))),(0,t.impression_track_element)({element:e,data:{recommendation_id:i,..._(this,v)[v]()}});break;case r.SearchResult:e.addEventListener("click",(()=>this.sendSearchResultClickEvent(i))),(0,t.impression_track_element)({element:e,data:{search_result_id:i,..._(this,v)[v]()}});break;case r.ProductListingResult:e.addEventListener("click",(()=>this.sendProductListingResultClickEvent(i))),(0,t.impression_track_element)({element:e,data:{product_listing_result_id:i,..._(this,v)[v]()}})}const s=e.querySelectorAll(o);for(const t of s)this.trackAddToCartButton(t,e)}trackAddToCartButton(e,i){this.checkIfTracked(e)||e.addEventListener("click",(()=>{if(!i){const i=_(this,k)[k]();return i?void this.sendAddToCartEvent({product_id:i}):void(0,t.derror)("No product ID set for add-to-cart click outside of product card",e)}for(const[t,e]of Object.entries(d)){const r=i.getAttribute(t);if(!r)continue;const n={[s[e]]:r};return void this.sendAddToCartEvent(n)}(0,t.derror)("Could not find tracking data for add-to-cart click on button",e)}))}sendAddToCartEvent(t){_(this,f)[f]({type:"add_to_cart",...t})}sendRecommendationImpressionEvent(t){_(this,f)[f]({type:"element_visible",recommendation_id:t})}sendSearchResultImpressionEvent(t){_(this,f)[f]({type:"element_visible",search_result_id:t})}sendProductListingResultImpressionEvent(t){_(this,f)[f]({type:"element_visible",product_listing_result_id:t})}sendRecommendationClickEvent(e){(0,t.depict_click)({recommendation_id:e,..._(this,v)[v]()})}sendSearchResultClickEvent(e){(0,t.depict_click)({search_result_id:e,..._(this,v)[v]()})}sendProductListingResultClickEvent(e){(0,t.depict_click)({product_listing_result_id:e,..._(this,v)[v]()})}sendPurchaseEvent(e){if(!this.market)throw Error("Market not set");const{dsid:i,user_id:r,session_id:n}=_(this,v)[v](),s=e.items.map((t=>({sku:t.item_id,price:t.price,quantity:t.quantity}))),o={events:[{event_type:"purchase",dsid:i,user_id:r,session_id:n,transaction_id:e.transaction_id,currency:e.currency,products:s}],tenant:this.merchant,market:this.market};(0,t.foolproof_send_beacon)("https://api.depict.ai/v2/create-events",o)}setMarket(t){this.market=t}setProductId(e){(0,t.dlog)("Setting product id",e),this.latest_product_id=e,this.latest_product_id_path=location.pathname,_(this,f)[f]({type:"page_view",product_id:e})}setUserId(e){(0,t.dlog)("Setting user id",e),this.latest_user_id=e||void 0}setSessionId(e){(0,t.dlog)("Setting session id",e),this.latest_session_id=e||void 0}observeRecommendations(){for(const[e,i]of Object.entries(d)){const r=`[${e}]`;(0,t.dlog)("Starting to observe product cards with selector",r),t.observer.onexists(r,(({element:n})=>{const s=n.getAttribute(e);s?this.trackProductCard(n,s,i):(0,t.derror)(`No tracking id found on element with attribute ${r}`,n)}))}}observePDPA2CButton(){t.observer.onexists(o,(({element:e})=>{(0,t.dlog)("Found pdp add-to-cart button",e),this.trackAddToCartButton(e)}))}}function y(t){void 0!==t&&(void 0!==t.auto_observe&&(this.auto_observe=t.auto_observe),void 0!==t.market&&(this.market=t.market))}function b(){const e={market:this.market,tenant:this.merchant,user_id:this.latest_user_id,session_id:this.latest_session_id};return{...(0,t.get_tracking_event_context_data)(),...e}}function w(e){(0,t.send_depict_unfiltered)([{...e,..._(this,v)[v]()}],!0)}function R(){if(this.latest_product_id_path===location.pathname)return this.latest_product_id}(0,t.add_to_version_info)("dpc",i);
|
|
4
4
|
//# sourceMappingURL=main.js.map
|
package/dist/module.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import{add_to_version_info as t,dlog as e,impression_track_element as i,derror as r,depict_click as s,foolproof_send_beacon as n,observer as o,get_tracking_event_context_data as d,send_depict_unfiltered as a}from"@depict-ai/utilishared";
|
|
2
|
-
/*! Depict PerformanceClient */const c="1.0.
|
|
2
|
+
/*! Depict PerformanceClient */const c="1.0.17";let u;var h;(h=u||(u={}))[h.Recommendation=0]="Recommendation",h[h.SnakeRecommendation=1]="SnakeRecommendation",h[h.SearchResult=2]="SearchResult",h[h.ProductListingResult=3]="ProductListingResult";const _={[u.Recommendation]:"recommendation_id",[u.SnakeRecommendation]:"recommendation_id",[u.SearchResult]:"search_result_id",[u.ProductListingResult]:"product_listing_result_id"},p=".depict-add-to-cart",m={"data-recommendation_id":u.SnakeRecommendation,"data-recommendation-id":u.Recommendation,"data-search-result-id":u.SearchResult,"data-product-listing-result-id":u.ProductListingResult};const l=(t,e)=>{if("number"==typeof e&&!isNaN(e))return e.toString();if("string"!=typeof e)throw new Error(`${t} event requires a string as an argument`);return e},v=(t,e)=>null==e?e:l(t,e),f=(t,e,i)=>{if("purchase"!==e)"number"==typeof i&&(i=i.toString()),"addToCart"===e?t.sendAddToCartEvent({product_id:l(e,i)}):"setMarket"===e?t.setMarket(l(e,i)):"setProductId"===e?t.setProductId(l(e,i)):"setUserId"===e?t.setUserId(v(e,i)):"setSessionId"===e&&t.setSessionId(v(e,i));else{if(!(t=>{if("object"!=typeof t||null===t)throw new Error("purchase event requires an object as an argument");if(!Array.isArray(t.items))throw new Error("purchase event requires an items array of purchased products");if(!t.currency||"string"!=typeof t.currency)throw new Error("purchase event requires a currency string");if(!t.transaction_id||"string"!=typeof t.transaction_id&&"number"!=typeof t.transaction_id)throw new Error("purchase event requires a transaction_id string");t.transaction_id=t.transaction_id.toString();for(const e of t.items){if(""==e.item_id||isNaN(e.item_id)||"string"!=typeof e.item_id&&"number"!=typeof e.item_id)throw new Error("purchased item requires an item_id of the purchased product");if(isNaN(e.price))throw new Error("purchase item requires a unit price for the product purchased");if(!e.quantity||isNaN(e.quantity))throw new Error("purchase item requires a quantity of products purchased");e.item_id=e.item_id.toString()}return!0})(i))return;t.sendPurchaseEvent(i)}},k=t=>{const e=window.dpq||=function(){const t=function(){const e=arguments;t.send_event?t.send_event.apply(this,e):t.queue.push(e)};return t.queue=[],t}(),i=window.depict||={};i.dpq=e,i.eventHistory=e.queue,i.dpc=t,e.send_event||(e.send_event=(i,r)=>{e.queue.push([i,r]),f(t,i,r)},e.queue.forEach((([e,i])=>{f(t,e,i)})))};function g(t,e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var y=0;function b(t){return"__private_"+y+++"_"+t}var w=b("parseOptions"),R=b("getContextData"),E=b("sendTrackingEvent"),P=b("getProductId");class S{constructor(t,i){if(Object.defineProperty(this,P,{value:A}),Object.defineProperty(this,E,{value:I}),Object.defineProperty(this,R,{value:q}),Object.defineProperty(this,w,{value:C}),this.merchant=void 0,this.auto_observe=!0,this.market=void 0,this.latest_product_id=void 0,this.latest_product_id_path=void 0,this.latest_session_id=void 0,this.latest_user_id=void 0,this.tracked_elements=new WeakSet,window.depict?.dpc instanceof S)return e("DPC already initialized. Returning existing instance."),window.depict.dpc;k(this),this.merchant=t,g(this,w)[w](i),this.auto_observe&&(this.observeRecommendations(),this.observePDPA2CButton())}checkIfTracked(t){return this.tracked_elements.has(t)?(e("Already tracked",t),!0):(this.tracked_elements.add(t),!1)}trackProductCard(t,e,r){if(this.checkIfTracked(t))return;switch(r){case u.Recommendation:case u.SnakeRecommendation:t.addEventListener("click",(()=>this.sendRecommendationClickEvent(e))),i({element:t,data:{recommendation_id:e,...g(this,R)[R]()}});break;case u.SearchResult:t.addEventListener("click",(()=>this.sendSearchResultClickEvent(e))),i({element:t,data:{search_result_id:e,...g(this,R)[R]()}});break;case u.ProductListingResult:t.addEventListener("click",(()=>this.sendProductListingResultClickEvent(e))),i({element:t,data:{product_listing_result_id:e,...g(this,R)[R]()}})}const s=t.querySelectorAll(p);for(const e of s)this.trackAddToCartButton(e,t)}trackAddToCartButton(t,e){this.checkIfTracked(t)||t.addEventListener("click",(()=>{if(!e){const e=g(this,P)[P]();return e?void this.sendAddToCartEvent({product_id:e}):void r("No product ID set for add-to-cart click outside of product card",t)}for(const[t,i]of Object.entries(m)){const r=e.getAttribute(t);if(!r)continue;const s={[_[i]]:r};return void this.sendAddToCartEvent(s)}r("Could not find tracking data for add-to-cart click on button",t)}))}sendAddToCartEvent(t){g(this,E)[E]({type:"add_to_cart",...t})}sendRecommendationImpressionEvent(t){g(this,E)[E]({type:"element_visible",recommendation_id:t})}sendSearchResultImpressionEvent(t){g(this,E)[E]({type:"element_visible",search_result_id:t})}sendProductListingResultImpressionEvent(t){g(this,E)[E]({type:"element_visible",product_listing_result_id:t})}sendRecommendationClickEvent(t){s({recommendation_id:t,...g(this,R)[R]()})}sendSearchResultClickEvent(t){s({search_result_id:t,...g(this,R)[R]()})}sendProductListingResultClickEvent(t){s({product_listing_result_id:t,...g(this,R)[R]()})}sendPurchaseEvent(t){if(!this.market)throw Error("Market not set");const{dsid:e,user_id:i,session_id:r}=g(this,R)[R](),s=t.items.map((t=>({sku:t.item_id,price:t.price,quantity:t.quantity}))),o={events:[{event_type:"purchase",dsid:e,user_id:i,session_id:r,transaction_id:t.transaction_id,currency:t.currency,products:s}],tenant:this.merchant,market:this.market};n("https://api.depict.ai/v2/create-events",o)}setMarket(t){this.market=t}setProductId(t){e("Setting product id",t),this.latest_product_id=t,this.latest_product_id_path=location.pathname,g(this,E)[E]({type:"page_view",product_id:t})}setUserId(t){e("Setting user id",t),this.latest_user_id=t||void 0}setSessionId(t){e("Setting session id",t),this.latest_session_id=t||void 0}observeRecommendations(){for(const[t,i]of Object.entries(m)){const s=`[${t}]`;e("Starting to observe product cards with selector",s),o.onexists(s,(({element:e})=>{const n=e.getAttribute(t);n?this.trackProductCard(e,n,i):r(`No tracking id found on element with attribute ${s}`,e)}))}}observePDPA2CButton(){o.onexists(p,(({element:t})=>{e("Found pdp add-to-cart button",t),this.trackAddToCartButton(t)}))}}function C(t){void 0!==t&&(void 0!==t.auto_observe&&(this.auto_observe=t.auto_observe),void 0!==t.market&&(this.market=t.market))}function q(){const t={market:this.market,tenant:this.merchant,user_id:this.latest_user_id,session_id:this.latest_session_id};return{...d(),...t}}function I(t){a([{...t,...g(this,R)[R]()}],!0)}function A(){if(this.latest_product_id_path===location.pathname)return this.latest_product_id}t("dpc",c);export{S as DPC,c as version};
|
|
3
3
|
//# sourceMappingURL=module.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@depict-ai/dpc",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"packageManager": "yarn@3.2.2",
|
|
5
5
|
"source": "index_npm.ts",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@depict-ai/types": "^1.0.
|
|
41
|
-
"@depict-ai/utilishared": "^1.0.
|
|
40
|
+
"@depict-ai/types": "^1.0.21",
|
|
41
|
+
"@depict-ai/utilishared": "^1.0.17"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@babel/core": "latest",
|