@depict-ai/dpc 1.0.24 → 1.0.26
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 +8 -2
- package/dist/main.js +1 -1
- package/dist/module.js +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export const version = "1.0.
|
|
1
|
+
export const version = "1.0.26";
|
|
2
2
|
enum ProductCardType {
|
|
3
3
|
Recommendation = 0,
|
|
4
4
|
SnakeRecommendation = 1,
|
|
5
5
|
SearchResult = 2,
|
|
6
6
|
ProductListingResult = 3
|
|
7
7
|
}
|
|
8
|
+
type TrackingKey = "recommendation_id" | "search_result_id" | "product_listing_result_id";
|
|
8
9
|
/**
|
|
9
10
|
* The Depict Queue function used to register events to be sent to depict.
|
|
10
11
|
*/
|
|
@@ -89,8 +90,13 @@ export class DPC {
|
|
|
89
90
|
trackAddToCartButton(button: HTMLElement, productCard?: HTMLElement): void;
|
|
90
91
|
/**
|
|
91
92
|
* Sends an Add to Cart Event to depict
|
|
93
|
+
* If the add to cart unmistakably happened due to a click on a product card shown because of Depict (for example the add to cart button on a product card), set recommendation_id / search_result_id / product_listing_result_id (whatever applicable). If it happened on a PDP, set product_id instead.
|
|
92
94
|
*/
|
|
93
|
-
sendAddToCartEvent(data:
|
|
95
|
+
sendAddToCartEvent(data: {
|
|
96
|
+
product_id?: string;
|
|
97
|
+
} & {
|
|
98
|
+
[x in TrackingKey]?: string;
|
|
99
|
+
}): void;
|
|
94
100
|
/**
|
|
95
101
|
* Sends a recommendation impression event to Depict
|
|
96
102
|
*/
|
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",(()=>b)),e(module.exports,"version",(()=>i));
|
|
2
2
|
/*! Depict PerformanceClient */
|
|
3
|
-
const i="1.0.
|
|
3
|
+
const i="1.0.26";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||"string"!=typeof e.item_id&&("number"!=typeof e.item_id||isNaN(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("has_sent_pageview_for_current_href"),v=p("resetSentPageViewForCurrentHref"),f=p("parseOptions"),k=p("getContextData"),g=p("sendTrackingEvent"),y=p("getProductId");class b{constructor(e,i){if(Object.defineProperty(this,y,{value:S}),Object.defineProperty(this,g,{value:P}),Object.defineProperty(this,k,{value:E}),Object.defineProperty(this,f,{value:R}),Object.defineProperty(this,v,{value:w}),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,Object.defineProperty(this,m,{writable:!0,value:!1}),this.tracked_elements=new WeakSet,window.depict?.dpc instanceof b)return(0,t.dlog)("DPC already initialized. Returning existing instance."),window.depict.dpc;h(this),this.merchant=e,_(this,f)[f](i),_(this,v)[v](),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,k)[k]()}});break;case r.SearchResult:e.addEventListener("click",(()=>this.sendSearchResultClickEvent(i))),(0,t.impression_track_element)({element:e,data:{search_result_id:i,..._(this,k)[k]()}});break;case r.ProductListingResult:e.addEventListener("click",(()=>this.sendProductListingResultClickEvent(i))),(0,t.impression_track_element)({element:e,data:{product_listing_result_id:i,..._(this,k)[k]()}})}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,y)[y]();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,g)[g]({type:"add_to_cart",...t})}sendRecommendationImpressionEvent(t){_(this,g)[g]({type:"element_visible",recommendation_id:t})}sendSearchResultImpressionEvent(t){_(this,g)[g]({type:"element_visible",search_result_id:t})}sendProductListingResultImpressionEvent(t){_(this,g)[g]({type:"element_visible",product_listing_result_id:t})}sendRecommendationClickEvent(e){(0,t.depict_click)({recommendation_id:e,..._(this,k)[k]()})}sendSearchResultClickEvent(e){(0,t.depict_click)({search_result_id:e,..._(this,k)[k]()})}sendProductListingResultClickEvent(e){(0,t.depict_click)({product_listing_result_id:e,..._(this,k)[k]()})}sendPurchaseEvent(e){if(!this.market)throw Error("Market not set");const{dsid:i,user_id:r,session_id:n}=_(this,k)[k](),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,m)[m]||(_(this,g)[g]({type:"page_view",product_id:e}),_(this,m)[m]=!0)}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 w(){let e=location.href;t.instant_exec_on_suspect_history_change.add((0,t.catchify)((()=>{const{href:t}=location;e!==t&&(_(this,m)[m]=!1,e=t)})))}function R(t){void 0!==t&&(void 0!==t.auto_observe&&(this.auto_observe=t.auto_observe),void 0!==t.market&&(this.market=t.market))}function E(){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 P(e){(0,t.send_depict_unfiltered)([{...e,..._(this,k)[k]()}],!0)}function S(){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,instant_exec_on_suspect_history_change as a,catchify as d,get_tracking_event_context_data as c,send_depict_unfiltered as u}from"@depict-ai/utilishared";
|
|
2
|
-
/*! Depict PerformanceClient */const h="1.0.
|
|
2
|
+
/*! Depict PerformanceClient */const h="1.0.26";let _;var p;(p=_||(_={}))[p.Recommendation=0]="Recommendation",p[p.SnakeRecommendation=1]="SnakeRecommendation",p[p.SearchResult=2]="SearchResult",p[p.ProductListingResult=3]="ProductListingResult";const l={[_.Recommendation]:"recommendation_id",[_.SnakeRecommendation]:"recommendation_id",[_.SearchResult]:"search_result_id",[_.ProductListingResult]:"product_listing_result_id"},m=".depict-add-to-cart",v={"data-recommendation_id":_.SnakeRecommendation,"data-recommendation-id":_.Recommendation,"data-search-result-id":_.SearchResult,"data-product-listing-result-id":_.ProductListingResult};const f=(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},k=(t,e)=>null==e?e:f(t,e),g=(t,e,i)=>{if("purchase"!==e)"number"==typeof i&&(i=i.toString()),"addToCart"===e?t.sendAddToCartEvent({product_id:f(e,i)}):"setMarket"===e?t.setMarket(f(e,i)):"setProductId"===e?t.setProductId(f(e,i)):"setUserId"===e?t.setUserId(k(e,i)):"setSessionId"===e&&t.setSessionId(k(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||"string"!=typeof e.item_id&&("number"!=typeof e.item_id||isNaN(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)}},y=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]),g(t,i,r)},e.queue.forEach((([e,i])=>{g(t,e,i)})))};function b(t,e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var w=0;function R(t){return"__private_"+w+++"_"+t}var E=R("has_sent_pageview_for_current_href"),P=R("resetSentPageViewForCurrentHref"),S=R("parseOptions"),C=R("getContextData"),q=R("sendTrackingEvent"),I=R("getProductId");class A{constructor(t,i){if(Object.defineProperty(this,I,{value:N}),Object.defineProperty(this,q,{value:O}),Object.defineProperty(this,C,{value:j}),Object.defineProperty(this,S,{value:L}),Object.defineProperty(this,P,{value:T}),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,Object.defineProperty(this,E,{writable:!0,value:!1}),this.tracked_elements=new WeakSet,window.depict?.dpc instanceof A)return e("DPC already initialized. Returning existing instance."),window.depict.dpc;y(this),this.merchant=t,b(this,S)[S](i),b(this,P)[P](),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 _.Recommendation:case _.SnakeRecommendation:t.addEventListener("click",(()=>this.sendRecommendationClickEvent(e))),i({element:t,data:{recommendation_id:e,...b(this,C)[C]()}});break;case _.SearchResult:t.addEventListener("click",(()=>this.sendSearchResultClickEvent(e))),i({element:t,data:{search_result_id:e,...b(this,C)[C]()}});break;case _.ProductListingResult:t.addEventListener("click",(()=>this.sendProductListingResultClickEvent(e))),i({element:t,data:{product_listing_result_id:e,...b(this,C)[C]()}})}const s=t.querySelectorAll(m);for(const e of s)this.trackAddToCartButton(e,t)}trackAddToCartButton(t,e){this.checkIfTracked(t)||t.addEventListener("click",(()=>{if(!e){const e=b(this,I)[I]();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(v)){const r=e.getAttribute(t);if(!r)continue;const s={[l[i]]:r};return void this.sendAddToCartEvent(s)}r("Could not find tracking data for add-to-cart click on button",t)}))}sendAddToCartEvent(t){b(this,q)[q]({type:"add_to_cart",...t})}sendRecommendationImpressionEvent(t){b(this,q)[q]({type:"element_visible",recommendation_id:t})}sendSearchResultImpressionEvent(t){b(this,q)[q]({type:"element_visible",search_result_id:t})}sendProductListingResultImpressionEvent(t){b(this,q)[q]({type:"element_visible",product_listing_result_id:t})}sendRecommendationClickEvent(t){s({recommendation_id:t,...b(this,C)[C]()})}sendSearchResultClickEvent(t){s({search_result_id:t,...b(this,C)[C]()})}sendProductListingResultClickEvent(t){s({product_listing_result_id:t,...b(this,C)[C]()})}sendPurchaseEvent(t){if(!this.market)throw Error("Market not set");const{dsid:e,user_id:i,session_id:r}=b(this,C)[C](),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,b(this,E)[E]||(b(this,q)[q]({type:"page_view",product_id:t}),b(this,E)[E]=!0)}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(v)){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(m,(({element:t})=>{e("Found pdp add-to-cart button",t),this.trackAddToCartButton(t)}))}}function T(){let t=location.href;a.add(d((()=>{const{href:e}=location;t!==e&&(b(this,E)[E]=!1,t=e)})))}function L(t){void 0!==t&&(void 0!==t.auto_observe&&(this.auto_observe=t.auto_observe),void 0!==t.market&&(this.market=t.market))}function j(){const t={market:this.market,tenant:this.merchant,user_id:this.latest_user_id,session_id:this.latest_session_id};return{...c(),...t}}function O(t){u([{...t,...b(this,C)[C]()}],!0)}function N(){if(this.latest_product_id_path===location.pathname)return this.latest_product_id}t("dpc",h);export{A as DPC,h 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.26",
|
|
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.29",
|
|
41
|
+
"@depict-ai/utilishared": "^1.0.25"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@babel/core": "latest",
|