@depict-ai/dpc 0.0.3 → 0.0.5

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 CHANGED
@@ -1,4 +1,5 @@
1
1
  import { PurchasedProduct } from "@depict-ai/types/api/TrackV2Request";
2
+ export const version = "0.0.5";
2
3
  /**
3
4
  * The Depict Queue function used to register events to be sent to depict.
4
5
  */
@@ -106,6 +107,5 @@ export class DPC {
106
107
  */
107
108
  observePDPA2CButton(): void;
108
109
  }
109
- export const version = "0.0.3";
110
110
 
111
111
  //# sourceMappingURL=index.d.ts.map
package/dist/main.js CHANGED
@@ -1,4 +1,4 @@
1
- var e=require("@depict-ai/utilishared");function t(e,t,r,n){Object.defineProperty(e,t,{get:r,set:n,enumerable:!0,configurable:!0})}t(module.exports,"DPC",(()=>_)),t(module.exports,"version",(()=>g));
1
+ var e=require("@depict-ai/utilishared");function t(e,t,r,n){Object.defineProperty(e,t,{get:r,set:n,enumerable:!0,configurable:!0})}t(module.exports,"DPC",(()=>l)),t(module.exports,"version",(()=>r));
2
2
  /*! Depict PerformanceClient */
3
- const r=".depict-add-to-cart",n="[data-recommendation_id],[data-recommendation-id]";const i=(e,t)=>{if("string"!=typeof t)throw new Error(`${e} event requires a string as an argument`)},o=(e,t)=>{const r=window.depict.dpc;if("purchase"===e){if("object"!=typeof t||null===t)throw new Error("purchase event requires an object as an argument");if(!Array.isArray(t.products))throw new Error("purchase event requires a products array");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)throw new Error("purchase event requires a transaction_id string");r.sendPurchaseEvent(t)}else"setMarket"===e?(i(e,t),r.setMarket(t)):"setProductId"===e?(i(e,t),r.setProductId(t)):"setUserId"===e&&(i(e,t),r.setUserId(t))},s=e=>{const t=window.dpq||=function(){const e=function(){const t=arguments;e.send_event?e.send_event.apply(this,t):e.queue.push(t)};return e.queue=[],e}(),r=window.depict||={};r.dpq=t,r.eventHistory=t.queue,r.dpc=e,t.send_event||(t.send_event=(e,r)=>{t.queue.push([e,r]),o(e,r)},t.queue.forEach((([e,t])=>{o(e,t)})))};function d(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var a=0;function c(e){return"__private_"+a+++"_"+e}var u=c("parseOptions"),h=c("getContextData"),m=c("sendTrackingEvent"),p=c("getProductId");class _{constructor(t,r){if(Object.defineProperty(this,p,{value:k}),Object.defineProperty(this,m,{value:f}),Object.defineProperty(this,h,{value:v}),Object.defineProperty(this,u,{value:l}),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_user_id=void 0,this.tracked_elements=new WeakSet,window.depict.dpc instanceof _)return(0,e.dlog)("DPC already initialized. Returning existing instance."),window.depict.dpc;s(this),this.merchant=t,d(this,u)[u](r),this.auto_observe&&(this.observeRecommendations(),this.observePDPA2CButton())}trackRecommendationCard(t){const n=t.dataset.recommendation_id;if(!n)return void(0,e.derror)("No recommendation_id found on card. Can't add tracking.",t);if(this.checkIfTracked(t))return;t.addEventListener("click",(()=>this.sendRecommendationClickEvent({recommendation_id:n}))),(0,e.impression_track_element)({element:t,data:{recommendation_id:n,...d(this,h)[h]()}});const i=t.querySelector(r);i&&this.trackAddToCartButton(i)}checkIfTracked(t){return this.tracked_elements.has(t)?((0,e.dlog)("Already tracked",t),!0):(this.tracked_elements.add(t),!1)}trackAddToCartButton(e){this.checkIfTracked(e)||e.addEventListener("click",(()=>{const t=e.closest(n)?.dataset.recommendation_id,r=d(this,p)[p]();this.sendAddToCartEvent({product_id:r,recommendation_id:t})}))}sendAddToCartEvent(e){d(this,m)[m]({type:"add_to_cart",...e})}sendRecommendationImpressionEvent({recommendation_id:e}){d(this,m)[m]({type:"element_visible",recommendation_id:e})}sendRecommendationClickEvent({recommendation_id:t}){(0,e.depict_click)({recommendation_id:t,...d(this,h)[h]()})}sendPurchaseEvent(t){if(!this.market)throw Error("Market not set");const r={events:[{event_type:"purchase",...t}],tenant:this.merchant,market:this.market};(0,e.foolproof_send_beacon)("https://api.depict.ai/v2/create-events",r)}setMarket(e){this.market=e}setProductId(t){(0,e.dlog)("Setting product id",t),this.latest_product_id=t,this.latest_product_id_path=location.pathname}setUserId(t){(0,e.dlog)("Setting user id",t),this.latest_user_id=t}observeRecommendations(){(0,e.dlog)("Starting to observe recommendations with selector",n),e.observer.onexists(n,(({element:t})=>{(0,e.dlog)("found recommendation",t),this.trackRecommendationCard(t)}))}observePDPA2CButton(){e.observer.onexists(r,(({element:t})=>{(0,e.dlog)("Found pdp add-to-cart button",t),this.trackAddToCartButton(t)}))}}function l(e){void 0!==e&&(void 0!==e.auto_observe&&(this.auto_observe=e.auto_observe),void 0!==e.market&&(this.market=e.market))}function v(){const t={market:this.market,tenant:this.merchant,user_id:this.latest_user_id};return{...(0,e.get_tracking_event_context_data)(),data:t}}function f(t){(0,e.send_depict_unfiltered)([{...t,...d(this,h)[h]()}],!0)}function k(){if(this.latest_product_id_path===location.pathname)return this.latest_product_id}const g="0.0.3";(0,e.dlog)("@depict-ai/dpc version",g);
3
+ const r="0.0.5",n=".depict-add-to-cart",i="[data-recommendation_id],[data-recommendation-id]";const o=(e,t)=>{if("string"!=typeof t)throw new Error(`${e} event requires a string as an argument`)},s=(e,t)=>{const r=window.depict.dpc;if("purchase"===e){if("object"!=typeof t||null===t)throw new Error("purchase event requires an object as an argument");if(!Array.isArray(t.products))throw new Error("purchase event requires a products array");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)throw new Error("purchase event requires a transaction_id string");r.sendPurchaseEvent(t)}else"setMarket"===e?(o(e,t),r.setMarket(t)):"setProductId"===e?(o(e,t),r.setProductId(t)):"setUserId"===e&&(o(e,t),r.setUserId(t))},d=e=>{const t=window.dpq||=function(){const e=function(){const t=arguments;e.send_event?e.send_event.apply(this,t):e.queue.push(t)};return e.queue=[],e}(),r=window.depict||={};r.dpq=t,r.eventHistory=t.queue,r.dpc=e,t.send_event||(t.send_event=(e,r)=>{t.queue.push([e,r]),s(e,r)},t.queue.forEach((([e,t])=>{s(e,t)})))};function a(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}var c=0;function u(e){return"__private_"+c+++"_"+e}var h=u("parseOptions"),m=u("getContextData"),p=u("sendTrackingEvent"),_=u("getProductId");class l{constructor(t,r){if(Object.defineProperty(this,_,{value:g}),Object.defineProperty(this,p,{value:k}),Object.defineProperty(this,m,{value:f}),Object.defineProperty(this,h,{value:v}),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_user_id=void 0,this.tracked_elements=new WeakSet,window.depict?.dpc instanceof l)return(0,e.dlog)("DPC already initialized. Returning existing instance."),window.depict.dpc;d(this),this.merchant=t,a(this,h)[h](r),this.auto_observe&&(this.observeRecommendations(),this.observePDPA2CButton())}trackRecommendationCard(t){const r=t.dataset.recommendation_id;if(!r)return void(0,e.derror)("No recommendation_id found on card. Can't add tracking.",t);if(this.checkIfTracked(t))return;t.addEventListener("click",(()=>this.sendRecommendationClickEvent({recommendation_id:r}))),(0,e.impression_track_element)({element:t,data:{recommendation_id:r,...a(this,m)[m]()}});const i=t.querySelector(n);i&&this.trackAddToCartButton(i)}checkIfTracked(t){return this.tracked_elements.has(t)?((0,e.dlog)("Already tracked",t),!0):(this.tracked_elements.add(t),!1)}trackAddToCartButton(e){this.checkIfTracked(e)||e.addEventListener("click",(()=>{const t=e.closest(i)?.dataset.recommendation_id,r=a(this,_)[_]();this.sendAddToCartEvent({product_id:r,recommendation_id:t})}))}sendAddToCartEvent(e){a(this,p)[p]({type:"add_to_cart",...e})}sendRecommendationImpressionEvent({recommendation_id:e}){a(this,p)[p]({type:"element_visible",recommendation_id:e})}sendRecommendationClickEvent({recommendation_id:t}){(0,e.depict_click)({recommendation_id:t,...a(this,m)[m]()})}sendPurchaseEvent(t){if(!this.market)throw Error("Market not set");const r={events:[{event_type:"purchase",...t}],tenant:this.merchant,market:this.market};(0,e.foolproof_send_beacon)("https://api.depict.ai/v2/create-events",r)}setMarket(e){this.market=e}setProductId(t){(0,e.dlog)("Setting product id",t),this.latest_product_id=t,this.latest_product_id_path=location.pathname}setUserId(t){(0,e.dlog)("Setting user id",t),this.latest_user_id=t}observeRecommendations(){(0,e.dlog)("Starting to observe recommendations with selector",i),e.observer.onexists(i,(({element:t})=>{(0,e.dlog)("found recommendation",t),this.trackRecommendationCard(t)}))}observePDPA2CButton(){e.observer.onexists(n,(({element:t})=>{(0,e.dlog)("Found pdp add-to-cart button",t),this.trackAddToCartButton(t)}))}}function v(e){void 0!==e&&(void 0!==e.auto_observe&&(this.auto_observe=e.auto_observe),void 0!==e.market&&(this.market=e.market))}function f(){const t={market:this.market,tenant:this.merchant,user_id:this.latest_user_id};return{...(0,e.get_tracking_event_context_data)(),...t}}function k(t){(0,e.send_depict_unfiltered)([{...t,...a(this,m)[m]()}],!0)}function g(){if(this.latest_product_id_path===location.pathname)return this.latest_product_id}(0,e.dlog)("@depict-ai/dpc version",r);
4
4
  //# sourceMappingURL=main.js.map
package/dist/module.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import{dlog as t,derror as e,impression_track_element as r,depict_click as n,foolproof_send_beacon as i,observer as s,get_tracking_event_context_data as o,send_depict_unfiltered as a}from"@depict-ai/utilishared";
2
- /*! Depict PerformanceClient */const d=".depict-add-to-cart",c="[data-recommendation_id],[data-recommendation-id]";const u=(t,e)=>{if("string"!=typeof e)throw new Error(`${t} event requires a string as an argument`)},h=(t,e)=>{const r=window.depict.dpc;if("purchase"===t){if("object"!=typeof e||null===e)throw new Error("purchase event requires an object as an argument");if(!Array.isArray(e.products))throw new Error("purchase event requires a products array");if(!e.currency||"string"!=typeof e.currency)throw new Error("purchase event requires a currency string");if(!e.transaction_id||"string"!=typeof e.transaction_id)throw new Error("purchase event requires a transaction_id string");r.sendPurchaseEvent(e)}else"setMarket"===t?(u(t,e),r.setMarket(e)):"setProductId"===t?(u(t,e),r.setProductId(e)):"setUserId"===t&&(u(t,e),r.setUserId(e))},m=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}(),r=window.depict||={};r.dpq=e,r.eventHistory=e.queue,r.dpc=t,e.send_event||(e.send_event=(t,r)=>{e.queue.push([t,r]),h(t,r)},e.queue.forEach((([t,e])=>{h(t,e)})))};function p(t,e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var _=0;function v(t){return"__private_"+_+++"_"+t}var l=v("parseOptions"),f=v("getContextData"),k=v("sendTrackingEvent"),w=v("getProductId");class y{constructor(e,r){if(Object.defineProperty(this,w,{value:P}),Object.defineProperty(this,k,{value:E}),Object.defineProperty(this,f,{value:g}),Object.defineProperty(this,l,{value:b}),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_user_id=void 0,this.tracked_elements=new WeakSet,window.depict.dpc instanceof y)return t("DPC already initialized. Returning existing instance."),window.depict.dpc;m(this),this.merchant=e,p(this,l)[l](r),this.auto_observe&&(this.observeRecommendations(),this.observePDPA2CButton())}trackRecommendationCard(t){const n=t.dataset.recommendation_id;if(!n)return void e("No recommendation_id found on card. Can't add tracking.",t);if(this.checkIfTracked(t))return;t.addEventListener("click",(()=>this.sendRecommendationClickEvent({recommendation_id:n}))),r({element:t,data:{recommendation_id:n,...p(this,f)[f]()}});const i=t.querySelector(d);i&&this.trackAddToCartButton(i)}checkIfTracked(e){return this.tracked_elements.has(e)?(t("Already tracked",e),!0):(this.tracked_elements.add(e),!1)}trackAddToCartButton(t){this.checkIfTracked(t)||t.addEventListener("click",(()=>{const e=t.closest(c)?.dataset.recommendation_id,r=p(this,w)[w]();this.sendAddToCartEvent({product_id:r,recommendation_id:e})}))}sendAddToCartEvent(t){p(this,k)[k]({type:"add_to_cart",...t})}sendRecommendationImpressionEvent({recommendation_id:t}){p(this,k)[k]({type:"element_visible",recommendation_id:t})}sendRecommendationClickEvent({recommendation_id:t}){n({recommendation_id:t,...p(this,f)[f]()})}sendPurchaseEvent(t){if(!this.market)throw Error("Market not set");const e={events:[{event_type:"purchase",...t}],tenant:this.merchant,market:this.market};i("https://api.depict.ai/v2/create-events",e)}setMarket(t){this.market=t}setProductId(e){t("Setting product id",e),this.latest_product_id=e,this.latest_product_id_path=location.pathname}setUserId(e){t("Setting user id",e),this.latest_user_id=e}observeRecommendations(){t("Starting to observe recommendations with selector",c),s.onexists(c,(({element:e})=>{t("found recommendation",e),this.trackRecommendationCard(e)}))}observePDPA2CButton(){s.onexists(d,(({element:e})=>{t("Found pdp add-to-cart button",e),this.trackAddToCartButton(e)}))}}function b(t){void 0!==t&&(void 0!==t.auto_observe&&(this.auto_observe=t.auto_observe),void 0!==t.market&&(this.market=t.market))}function g(){const t={market:this.market,tenant:this.merchant,user_id:this.latest_user_id};return{...o(),data:t}}function E(t){a([{...t,...p(this,f)[f]()}],!0)}function P(){if(this.latest_product_id_path===location.pathname)return this.latest_product_id}const C="0.0.3";t("@depict-ai/dpc version",C);export{y as DPC,C as version};
2
+ /*! Depict PerformanceClient */const d="0.0.5",c=".depict-add-to-cart",u="[data-recommendation_id],[data-recommendation-id]";const h=(t,e)=>{if("string"!=typeof e)throw new Error(`${t} event requires a string as an argument`)},m=(t,e)=>{const r=window.depict.dpc;if("purchase"===t){if("object"!=typeof e||null===e)throw new Error("purchase event requires an object as an argument");if(!Array.isArray(e.products))throw new Error("purchase event requires a products array");if(!e.currency||"string"!=typeof e.currency)throw new Error("purchase event requires a currency string");if(!e.transaction_id||"string"!=typeof e.transaction_id)throw new Error("purchase event requires a transaction_id string");r.sendPurchaseEvent(e)}else"setMarket"===t?(h(t,e),r.setMarket(e)):"setProductId"===t?(h(t,e),r.setProductId(e)):"setUserId"===t&&(h(t,e),r.setUserId(e))},p=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}(),r=window.depict||={};r.dpq=e,r.eventHistory=e.queue,r.dpc=t,e.send_event||(e.send_event=(t,r)=>{e.queue.push([t,r]),m(t,r)},e.queue.forEach((([t,e])=>{m(t,e)})))};function _(t,e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var v=0;function l(t){return"__private_"+v+++"_"+t}var f=l("parseOptions"),k=l("getContextData"),w=l("sendTrackingEvent"),y=l("getProductId");class b{constructor(e,r){if(Object.defineProperty(this,y,{value:C}),Object.defineProperty(this,w,{value:P}),Object.defineProperty(this,k,{value:E}),Object.defineProperty(this,f,{value:g}),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_user_id=void 0,this.tracked_elements=new WeakSet,window.depict?.dpc instanceof b)return t("DPC already initialized. Returning existing instance."),window.depict.dpc;p(this),this.merchant=e,_(this,f)[f](r),this.auto_observe&&(this.observeRecommendations(),this.observePDPA2CButton())}trackRecommendationCard(t){const n=t.dataset.recommendation_id;if(!n)return void e("No recommendation_id found on card. Can't add tracking.",t);if(this.checkIfTracked(t))return;t.addEventListener("click",(()=>this.sendRecommendationClickEvent({recommendation_id:n}))),r({element:t,data:{recommendation_id:n,..._(this,k)[k]()}});const i=t.querySelector(c);i&&this.trackAddToCartButton(i)}checkIfTracked(e){return this.tracked_elements.has(e)?(t("Already tracked",e),!0):(this.tracked_elements.add(e),!1)}trackAddToCartButton(t){this.checkIfTracked(t)||t.addEventListener("click",(()=>{const e=t.closest(u)?.dataset.recommendation_id,r=_(this,y)[y]();this.sendAddToCartEvent({product_id:r,recommendation_id:e})}))}sendAddToCartEvent(t){_(this,w)[w]({type:"add_to_cart",...t})}sendRecommendationImpressionEvent({recommendation_id:t}){_(this,w)[w]({type:"element_visible",recommendation_id:t})}sendRecommendationClickEvent({recommendation_id:t}){n({recommendation_id:t,..._(this,k)[k]()})}sendPurchaseEvent(t){if(!this.market)throw Error("Market not set");const e={events:[{event_type:"purchase",...t}],tenant:this.merchant,market:this.market};i("https://api.depict.ai/v2/create-events",e)}setMarket(t){this.market=t}setProductId(e){t("Setting product id",e),this.latest_product_id=e,this.latest_product_id_path=location.pathname}setUserId(e){t("Setting user id",e),this.latest_user_id=e}observeRecommendations(){t("Starting to observe recommendations with selector",u),s.onexists(u,(({element:e})=>{t("found recommendation",e),this.trackRecommendationCard(e)}))}observePDPA2CButton(){s.onexists(c,(({element:e})=>{t("Found pdp add-to-cart button",e),this.trackAddToCartButton(e)}))}}function g(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 t={market:this.market,tenant:this.merchant,user_id:this.latest_user_id};return{...o(),...t}}function P(t){a([{...t,..._(this,k)[k]()}],!0)}function C(){if(this.latest_product_id_path===location.pathname)return this.latest_product_id}t("@depict-ai/dpc version",d);export{b as DPC,d as version};
3
3
  //# sourceMappingURL=module.js.map
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@depict-ai/dpc",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "packageManager": "yarn@3.2.2",
5
5
  "source": "index_npm.ts",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
8
  "types": "dist/index.d.ts",
9
9
  "license": "MIT",
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
10
13
  "scripts": {
11
14
  "serve": "yarn workspace depict-ai parcel serve --port 1234 --target dev --hmr-port 2345 ./packages/performance-client/index_cdn.ts",
12
15
  "build": "./scripts/build",
@@ -33,7 +36,7 @@
33
36
  }
34
37
  },
35
38
  "dependencies": {
36
- "@depict-ai/utilishared": "^0.0.32"
39
+ "@depict-ai/utilishared": "^0.0.46"
37
40
  },
38
41
  "devDependencies": {
39
42
  "@babel/core": "latest",