@depict-ai/dpc 1.0.31 → 1.0.33
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/ES10/index.cjs +402 -224
- package/ES10/index.d.ts +1 -1
- package/ES10/index.js +394 -216
- package/dist/index.cjs +478 -0
- package/dist/index.d.ts +153 -0
- package/dist/index.js +468 -0
- package/latest/index.cjs +379 -234
- package/latest/index.d.ts +1 -1
- package/latest/index.js +373 -225
- package/package.json +9 -8
package/latest/index.cjs
CHANGED
|
@@ -1,295 +1,440 @@
|
|
|
1
|
-
var
|
|
2
|
-
t = require("@babel/runtime/helpers/classPrivateFieldLooseBase"),
|
|
3
|
-
i = require("@babel/runtime/helpers/classPrivateFieldLooseKey");
|
|
1
|
+
var $dwOGf$depictaiutilishared = require("@depict-ai/utilishared/latest");
|
|
4
2
|
require("../multi_import_deduplicator.cjs").register_es_version("performance-client", "latest");
|
|
5
|
-
function
|
|
6
|
-
Object.defineProperty(e,
|
|
7
|
-
get:
|
|
8
|
-
set:
|
|
9
|
-
enumerable:
|
|
10
|
-
configurable:
|
|
3
|
+
function $parcel$export(e, n, v, s) {
|
|
4
|
+
Object.defineProperty(e, n, {
|
|
5
|
+
get: v,
|
|
6
|
+
set: s,
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true
|
|
11
9
|
});
|
|
12
10
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
r(module.exports, "DPC", () => y), r(module.exports, "version", () => n);
|
|
11
|
+
$parcel$export(module.exports, "DPC", () => $15e3eebad2263636$export$820526014323765f);
|
|
12
|
+
$parcel$export(module.exports, "version", () => $9c6b4a5c4c4f318d$export$83d89fbfd8236492);
|
|
17
13
|
/*! Depict PerformanceClient */
|
|
18
|
-
const
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
14
|
+
const $9c6b4a5c4c4f318d$export$83d89fbfd8236492 = "1.0.33";
|
|
15
|
+
let $02e69dba644a2ef8$export$8ae64f3d447c14f7;
|
|
16
|
+
(function (ProductCardType) {
|
|
17
|
+
ProductCardType[ProductCardType["Recommendation"] = 0] = "Recommendation";
|
|
18
|
+
ProductCardType[ProductCardType["SnakeRecommendation"] = 1] = "SnakeRecommendation";
|
|
19
|
+
ProductCardType[ProductCardType["SearchResult"] = 2] = "SearchResult";
|
|
20
|
+
ProductCardType[ProductCardType["ProductListingResult"] = 3] = "ProductListingResult";
|
|
21
|
+
})($02e69dba644a2ef8$export$8ae64f3d447c14f7 || ($02e69dba644a2ef8$export$8ae64f3d447c14f7 = {}));
|
|
22
|
+
const $02e69dba644a2ef8$export$7c03f17546479d1d = {
|
|
23
|
+
[$02e69dba644a2ef8$export$8ae64f3d447c14f7.Recommendation]: "recommendation_id",
|
|
24
|
+
[$02e69dba644a2ef8$export$8ae64f3d447c14f7.SnakeRecommendation]: "recommendation_id",
|
|
25
|
+
[$02e69dba644a2ef8$export$8ae64f3d447c14f7.SearchResult]: "search_result_id",
|
|
26
|
+
[$02e69dba644a2ef8$export$8ae64f3d447c14f7.ProductListingResult]: "product_listing_result_id"
|
|
27
|
+
}; /**
|
|
28
|
+
* The Depict Queue function used to register events to be sent to depict.
|
|
29
|
+
*/ /**
|
|
30
|
+
* Depict Object containing everything depict-related on the page.
|
|
31
|
+
*/ /**
|
|
32
|
+
* Purchase format used by GA4 when sending a purchase event.
|
|
33
|
+
* See https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtag#make_a_purchase_or_issue_a_refund
|
|
34
|
+
*/ /**
|
|
35
|
+
* Product format used by GA4 when sending a purchase event.
|
|
36
|
+
* See https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtag#purchase_item
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
const $1e7b1f32e4f0380b$export$6f11e212918dbb31 = ".depict-add-to-cart";
|
|
40
|
+
const $1e7b1f32e4f0380b$export$79f7900b4eea40cf = {
|
|
41
|
+
// We sadly have customers in the wild using both _ and -
|
|
42
|
+
"data-recommendation_id": (0, $02e69dba644a2ef8$export$8ae64f3d447c14f7).SnakeRecommendation,
|
|
43
|
+
"data-recommendation-id": (0, $02e69dba644a2ef8$export$8ae64f3d447c14f7).Recommendation,
|
|
44
|
+
// All of these product cards are Depict rendered via js or react ui, so we know the data attribute
|
|
45
|
+
"data-search-result-id": (0, $02e69dba644a2ef8$export$8ae64f3d447c14f7).SearchResult,
|
|
46
|
+
"data-product-listing-result-id": (0, $02e69dba644a2ef8$export$8ae64f3d447c14f7).ProductListingResult
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Creates an event queue (depict queue)
|
|
51
|
+
*/
|
|
52
|
+
function $9ccf446d29413158$var$create_dpq() {
|
|
53
|
+
const fn = function () {
|
|
54
|
+
const args = arguments;
|
|
55
|
+
if (fn.send_event) fn.send_event.apply(this, args);else fn.queue.push(args);
|
|
34
56
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
fn.queue = [];
|
|
58
|
+
return fn;
|
|
59
|
+
}
|
|
60
|
+
const $9ccf446d29413158$var$string_guard = (eventName, eventData) => {
|
|
61
|
+
if (typeof eventData == "number" && !isNaN(eventData)) return eventData.toString();
|
|
62
|
+
if (typeof eventData !== "string") throw new Error(`${eventName} event requires a string as an argument`);
|
|
63
|
+
return eventData;
|
|
64
|
+
};
|
|
65
|
+
const $9ccf446d29413158$var$nullable_undefined_string_guard = (eventName, eventData) => {
|
|
66
|
+
if (eventData === null || eventData === undefined) return eventData;
|
|
67
|
+
return $9ccf446d29413158$var$string_guard(eventName, eventData);
|
|
68
|
+
};
|
|
69
|
+
const $9ccf446d29413158$var$ga4_purchase_guard = purchaseEvent => {
|
|
70
|
+
if (typeof purchaseEvent !== "object" || purchaseEvent === null) throw new Error("purchase event requires an object as an argument");
|
|
71
|
+
if (!Array.isArray(purchaseEvent.items)) throw new Error("purchase event requires an items array of purchased products");else if (!purchaseEvent.currency || typeof purchaseEvent.currency !== "string") throw new Error("purchase event requires a currency string");else if (!purchaseEvent.transaction_id || !(typeof purchaseEvent.transaction_id == "string" || typeof purchaseEvent.transaction_id == "number")) throw new Error("purchase event requires a transaction_id string");
|
|
72
|
+
// Transaction id could be either number or string at this point, automatically convert the latter
|
|
73
|
+
purchaseEvent.transaction_id = purchaseEvent.transaction_id.toString();
|
|
74
|
+
for (const item of purchaseEvent.items) {
|
|
75
|
+
if (item.item_id == "" || !(typeof item.item_id == "string" || typeof item.item_id == "number" && !isNaN(item.item_id))) throw new Error("purchased item requires an item_id of the purchased product");else if (isNaN(item.price))
|
|
76
|
+
// ^ 0 cost items are valid
|
|
77
|
+
throw new Error("purchase item requires a unit price for the product purchased");else if (!item.quantity || isNaN(item.quantity))
|
|
78
|
+
// ^ But 0 quantity items are not
|
|
79
|
+
throw new Error("purchase item requires a quantity of products purchased");
|
|
80
|
+
// Item id could be either number or string at this point, automatically convert the latter
|
|
81
|
+
item.item_id = item.item_id.toString();
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Handle events from dpq with the global dpc instance.
|
|
87
|
+
*/
|
|
88
|
+
const $9ccf446d29413158$var$event_handler = (dpc, eventName, eventData) => {
|
|
89
|
+
// take passed DPC since the window.depict object might have been overridden
|
|
90
|
+
if (eventName === "purchase") {
|
|
91
|
+
if (!$9ccf446d29413158$var$ga4_purchase_guard(eventData))
|
|
92
|
+
// Inaccessible since ga4_purchase_guard will throw an error, TS doesn't know that
|
|
93
|
+
return;
|
|
94
|
+
dpc.sendPurchaseEvent(eventData);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// All events below require strings as argument, accept numbers and automatically convert them
|
|
98
|
+
if (typeof eventData == "number") eventData = eventData.toString();
|
|
99
|
+
if (eventName === "addToCart") dpc.sendAddToCartEvent({
|
|
100
|
+
product_id: $9ccf446d29413158$var$string_guard(eventName, eventData)
|
|
101
|
+
});else if (eventName === "setMarket") dpc.setMarket($9ccf446d29413158$var$string_guard(eventName, eventData));else if (eventName === "setProductId") dpc.setProductId($9ccf446d29413158$var$string_guard(eventName, eventData));else if (eventName === "setUserId") dpc.setUserId($9ccf446d29413158$var$nullable_undefined_string_guard(eventName, eventData));else if (eventName === "setSessionId") dpc.setSessionId($9ccf446d29413158$var$nullable_undefined_string_guard(eventName, eventData));
|
|
102
|
+
};
|
|
103
|
+
const $9ccf446d29413158$export$7a1bb429756ced60 = dpc => {
|
|
104
|
+
const dpq = window.dpq ||= $9ccf446d29413158$var$create_dpq();
|
|
105
|
+
const depict = window.depict ||= {};
|
|
106
|
+
depict.dpq = dpq; // refrencing dpq into the depict object
|
|
107
|
+
depict.eventHistory = dpq.queue; // making this more visible in the depict object
|
|
108
|
+
depict.dpc = dpc;
|
|
109
|
+
// Hook up the depict queue to the PerformanceClient
|
|
110
|
+
if (!dpq.send_event) {
|
|
111
|
+
dpq.send_event = (eventName, eventData) => {
|
|
112
|
+
dpq.queue.push([eventName, eventData]); // push to queue as usual to keep history
|
|
113
|
+
$9ccf446d29413158$var$event_handler(dpc, eventName, eventData); // hand-over to the PerformanceClient
|
|
114
|
+
};
|
|
115
|
+
// Handle any events queued before this code ran.
|
|
116
|
+
dpq.queue.forEach(([eventName, eventData]) => {
|
|
117
|
+
$9ccf446d29413158$var$event_handler(dpc, eventName, eventData);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
class $15e3eebad2263636$export$820526014323765f {
|
|
122
|
+
auto_observe = true;
|
|
123
|
+
/** Latest product_id found in the DOM. Used in a2c & pageview events on PDPs. */ /** The value of location.pathname when latest_product_id was set */ /** Latest session_id set on the client. Used for all events. */ /** Latest user_id found in the DOM. Used for all events. */ /** if we've sent a page view event for the current href */
|
|
124
|
+
#has_sent_pageview_for_current_href = false;
|
|
125
|
+
constructor(merchant, options) {
|
|
126
|
+
// Make sure we do not construct dpc more than once.
|
|
127
|
+
if (window.depict?.dpc instanceof $15e3eebad2263636$export$820526014323765f) {
|
|
128
|
+
(0, $dwOGf$depictaiutilishared.dlog)("DPC already initialized. Returning existing instance.");
|
|
129
|
+
return window.depict.dpc;
|
|
60
130
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
131
|
+
(0, $9ccf446d29413158$export$7a1bb429756ced60)(this);
|
|
132
|
+
this.merchant = merchant;
|
|
133
|
+
this.#parseOptions(options);
|
|
134
|
+
this.#resetSentPageViewForCurrentHref();
|
|
135
|
+
if (this.auto_observe) {
|
|
136
|
+
this.observeRecommendations();
|
|
137
|
+
this.observePDPA2CButton();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
#resetSentPageViewForCurrentHref() {
|
|
141
|
+
let url = location.href;
|
|
142
|
+
(0, $dwOGf$depictaiutilishared.instant_exec_on_suspect_history_change).add((0, $dwOGf$depictaiutilishared.catchify)(() => {
|
|
143
|
+
const {
|
|
144
|
+
href: new_href
|
|
145
|
+
} = location;
|
|
146
|
+
if (url !== new_href) {
|
|
147
|
+
this.#has_sent_pageview_for_current_href = false;
|
|
148
|
+
url = new_href;
|
|
149
|
+
}
|
|
75
150
|
}));
|
|
76
|
-
};
|
|
77
|
-
var p = s(i)("has_sent_pageview_for_current_href"),
|
|
78
|
-
v = s(i)("resetSentPageViewForCurrentHref"),
|
|
79
|
-
f = s(i)("parseOptions"),
|
|
80
|
-
k = s(i)("getContextData"),
|
|
81
|
-
g = s(i)("sendTrackingEvent"),
|
|
82
|
-
b = s(i)("getProductId");
|
|
83
|
-
class y {
|
|
84
|
-
constructor(i, r) {
|
|
85
|
-
if (Object.defineProperty(this, b, {
|
|
86
|
-
value: S
|
|
87
|
-
}), Object.defineProperty(this, g, {
|
|
88
|
-
value: E
|
|
89
|
-
}), Object.defineProperty(this, k, {
|
|
90
|
-
value: P
|
|
91
|
-
}), Object.defineProperty(this, f, {
|
|
92
|
-
value: R
|
|
93
|
-
}), Object.defineProperty(this, v, {
|
|
94
|
-
value: w
|
|
95
|
-
}), 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, p, {
|
|
96
|
-
writable: !0,
|
|
97
|
-
value: !1
|
|
98
|
-
}), this.tracked_elements = new WeakSet(), window.depict?.dpc instanceof y) return (0, e.dlog)("DPC already initialized. Returning existing instance."), window.depict.dpc;
|
|
99
|
-
m(this), this.merchant = i, s(t)(this, f)[f](r), s(t)(this, v)[v](), this.auto_observe && (this.observeRecommendations(), this.observePDPA2CButton());
|
|
100
151
|
}
|
|
101
|
-
|
|
102
|
-
|
|
152
|
+
#parseOptions(options) {
|
|
153
|
+
if (options !== undefined) {
|
|
154
|
+
if (options.auto_observe !== undefined) this.auto_observe = options.auto_observe;
|
|
155
|
+
if (options.market !== undefined) this.market = options.market;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
#getContextData() {
|
|
159
|
+
const data = {
|
|
160
|
+
market: this.market,
|
|
161
|
+
tenant: this.merchant,
|
|
162
|
+
user_id: this.latest_user_id,
|
|
163
|
+
session_id: this.latest_session_id
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
...(0, $dwOGf$depictaiutilishared.get_tracking_event_context_data)(),
|
|
167
|
+
...data
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
tracked_elements = new WeakSet();
|
|
171
|
+
/**
|
|
172
|
+
* Make sure the tracking is not set up twice on the same element.
|
|
173
|
+
*/
|
|
174
|
+
checkIfTracked(element) {
|
|
175
|
+
if (this.tracked_elements.has(element)) {
|
|
176
|
+
(0, $dwOGf$depictaiutilishared.dlog)("Already tracked", element);
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
this.tracked_elements.add(element);
|
|
180
|
+
return false;
|
|
103
181
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
182
|
+
/**
|
|
183
|
+
* Adds click and impression tracking to a product card
|
|
184
|
+
*/
|
|
185
|
+
trackProductCard(card, tracking_id, type) {
|
|
186
|
+
if (this.checkIfTracked(card)) return;
|
|
187
|
+
switch (type) {
|
|
188
|
+
case (0, $02e69dba644a2ef8$export$8ae64f3d447c14f7).Recommendation:
|
|
189
|
+
case (0, $02e69dba644a2ef8$export$8ae64f3d447c14f7).SnakeRecommendation:
|
|
190
|
+
card.addEventListener("click", () => this.sendRecommendationClickEvent(tracking_id));
|
|
191
|
+
(0, $dwOGf$depictaiutilishared.impression_track_element)({
|
|
192
|
+
element: card,
|
|
111
193
|
data: {
|
|
112
|
-
recommendation_id:
|
|
113
|
-
...
|
|
194
|
+
recommendation_id: tracking_id,
|
|
195
|
+
...this.#getContextData()
|
|
114
196
|
}
|
|
115
197
|
});
|
|
116
198
|
break;
|
|
117
|
-
case
|
|
118
|
-
|
|
119
|
-
|
|
199
|
+
case (0, $02e69dba644a2ef8$export$8ae64f3d447c14f7).SearchResult:
|
|
200
|
+
card.addEventListener("click", () => this.sendSearchResultClickEvent(tracking_id));
|
|
201
|
+
(0, $dwOGf$depictaiutilishared.impression_track_element)({
|
|
202
|
+
element: card,
|
|
120
203
|
data: {
|
|
121
|
-
search_result_id:
|
|
122
|
-
...
|
|
204
|
+
search_result_id: tracking_id,
|
|
205
|
+
...this.#getContextData()
|
|
123
206
|
}
|
|
124
207
|
});
|
|
125
208
|
break;
|
|
126
|
-
case
|
|
127
|
-
|
|
128
|
-
|
|
209
|
+
case (0, $02e69dba644a2ef8$export$8ae64f3d447c14f7).ProductListingResult:
|
|
210
|
+
card.addEventListener("click", () => this.sendProductListingResultClickEvent(tracking_id));
|
|
211
|
+
(0, $dwOGf$depictaiutilishared.impression_track_element)({
|
|
212
|
+
element: card,
|
|
129
213
|
data: {
|
|
130
|
-
product_listing_result_id:
|
|
131
|
-
...
|
|
214
|
+
product_listing_result_id: tracking_id,
|
|
215
|
+
...this.#getContextData()
|
|
132
216
|
}
|
|
133
217
|
});
|
|
218
|
+
break;
|
|
134
219
|
}
|
|
135
|
-
|
|
136
|
-
|
|
220
|
+
// If the card has optional a2c buttons, we track those as well.
|
|
221
|
+
const a2c_buttons = card.querySelectorAll((0, $1e7b1f32e4f0380b$export$6f11e212918dbb31));
|
|
222
|
+
for (const a2c_button of a2c_buttons) this.trackAddToCartButton(a2c_button, card);
|
|
137
223
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
224
|
+
/**
|
|
225
|
+
* Adds tracking to an Add to cart button.
|
|
226
|
+
*/
|
|
227
|
+
trackAddToCartButton(button, productCard) {
|
|
228
|
+
if (this.checkIfTracked(button)) return;
|
|
229
|
+
button.addEventListener("click", () => {
|
|
230
|
+
if (!productCard) {
|
|
231
|
+
// If the button is not nested in a product card, it's a PDP button. Product ID set on the page is required.
|
|
232
|
+
const product_id = this.#getProductId();
|
|
233
|
+
if (!product_id) {
|
|
234
|
+
(0, $dwOGf$depictaiutilishared.derror)("No product ID set for add-to-cart click outside of product card", button);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
this.sendAddToCartEvent({
|
|
238
|
+
product_id: product_id
|
|
239
|
+
});
|
|
240
|
+
return;
|
|
145
241
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
242
|
+
// If the button is nested in a product card, we need to find the tracking ID. It can set in one of several attributes.
|
|
243
|
+
for (const [attribute, type] of Object.entries((0, $1e7b1f32e4f0380b$export$79f7900b4eea40cf))) {
|
|
244
|
+
const tracking_id = productCard.getAttribute(attribute);
|
|
245
|
+
if (!tracking_id) continue;
|
|
246
|
+
const tracking_data = {
|
|
247
|
+
[(0, $02e69dba644a2ef8$export$7c03f17546479d1d)[type]]: tracking_id
|
|
151
248
|
};
|
|
152
|
-
|
|
249
|
+
this.sendAddToCartEvent(tracking_data);
|
|
250
|
+
return;
|
|
153
251
|
}
|
|
154
|
-
(0,
|
|
252
|
+
(0, $dwOGf$depictaiutilishared.derror)("Could not find tracking data for add-to-cart click on button", button);
|
|
155
253
|
});
|
|
156
254
|
}
|
|
157
|
-
|
|
158
|
-
|
|
255
|
+
/**
|
|
256
|
+
* Sends a tracking event to depict
|
|
257
|
+
*/
|
|
258
|
+
#sendTrackingEvent(payload) {
|
|
259
|
+
// Todo. check consent. For some events, delay until consent decision, with possible timeout.
|
|
260
|
+
// For others, decide immediately based on current consent. (We shouldn't track a long history of events from before the user consented)
|
|
261
|
+
// If no consent, don't send at all, or send anonymous? I think the latter is valid, since no ID in cookie or localStorage.
|
|
262
|
+
(0, $dwOGf$depictaiutilishared.send_depict_unfiltered)([{
|
|
263
|
+
...payload,
|
|
264
|
+
...this.#getContextData()
|
|
265
|
+
}], true);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Sends an Add to Cart Event to depict
|
|
269
|
+
* 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.
|
|
270
|
+
*/
|
|
271
|
+
sendAddToCartEvent(data) {
|
|
272
|
+
this.#sendTrackingEvent({
|
|
159
273
|
type: "add_to_cart",
|
|
160
|
-
...
|
|
274
|
+
...data
|
|
161
275
|
});
|
|
162
276
|
}
|
|
163
|
-
|
|
164
|
-
|
|
277
|
+
/**
|
|
278
|
+
* Sends a recommendation impression event to Depict
|
|
279
|
+
*/
|
|
280
|
+
sendRecommendationImpressionEvent(recommendation_id) {
|
|
281
|
+
this.#sendTrackingEvent({
|
|
165
282
|
type: "element_visible",
|
|
166
|
-
recommendation_id:
|
|
283
|
+
recommendation_id: recommendation_id
|
|
167
284
|
});
|
|
168
285
|
}
|
|
169
|
-
|
|
170
|
-
|
|
286
|
+
/**
|
|
287
|
+
* Sends a search result impression event to Depict
|
|
288
|
+
*/
|
|
289
|
+
sendSearchResultImpressionEvent(search_result_id) {
|
|
290
|
+
this.#sendTrackingEvent({
|
|
171
291
|
type: "element_visible",
|
|
172
|
-
search_result_id:
|
|
292
|
+
search_result_id: search_result_id
|
|
173
293
|
});
|
|
174
294
|
}
|
|
175
|
-
|
|
176
|
-
|
|
295
|
+
/**
|
|
296
|
+
* Sends a product listing result impression event to Depict
|
|
297
|
+
*/
|
|
298
|
+
sendProductListingResultImpressionEvent(product_listing_result_id) {
|
|
299
|
+
this.#sendTrackingEvent({
|
|
177
300
|
type: "element_visible",
|
|
178
|
-
product_listing_result_id:
|
|
301
|
+
product_listing_result_id: product_listing_result_id
|
|
179
302
|
});
|
|
180
303
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
304
|
+
/**
|
|
305
|
+
* Sends a recommendation click event to Depict
|
|
306
|
+
*/
|
|
307
|
+
sendRecommendationClickEvent(recommendation_id) {
|
|
308
|
+
(0, $dwOGf$depictaiutilishared.depict_click)({
|
|
309
|
+
recommendation_id: recommendation_id,
|
|
310
|
+
...this.#getContextData()
|
|
185
311
|
});
|
|
186
312
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
313
|
+
/**
|
|
314
|
+
* Sends a search result click event to Depict
|
|
315
|
+
*/
|
|
316
|
+
sendSearchResultClickEvent(search_result_id) {
|
|
317
|
+
(0, $dwOGf$depictaiutilishared.depict_click)({
|
|
318
|
+
search_result_id: search_result_id,
|
|
319
|
+
...this.#getContextData()
|
|
191
320
|
});
|
|
192
321
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
322
|
+
/**
|
|
323
|
+
* Sends a product listing result click event to Depict
|
|
324
|
+
*/
|
|
325
|
+
sendProductListingResultClickEvent(product_listing_result_id) {
|
|
326
|
+
(0, $dwOGf$depictaiutilishared.depict_click)({
|
|
327
|
+
product_listing_result_id: product_listing_result_id,
|
|
328
|
+
...this.#getContextData()
|
|
197
329
|
});
|
|
198
330
|
}
|
|
199
|
-
|
|
331
|
+
/**
|
|
332
|
+
* Sends a Purchase Event to Depict
|
|
333
|
+
*/
|
|
334
|
+
sendPurchaseEvent(data) {
|
|
200
335
|
if (!this.market) throw Error("Market not set");
|
|
201
336
|
const {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
337
|
+
dsid: dsid,
|
|
338
|
+
user_id: user_id,
|
|
339
|
+
session_id: session_id
|
|
340
|
+
} = this.#getContextData();
|
|
341
|
+
const items = data.items.map(item => ({
|
|
342
|
+
sku: item.item_id,
|
|
343
|
+
price: item.price,
|
|
344
|
+
quantity: item.quantity
|
|
345
|
+
}));
|
|
346
|
+
const request = {
|
|
347
|
+
events: [{
|
|
348
|
+
event_type: "purchase",
|
|
349
|
+
dsid: dsid,
|
|
350
|
+
user_id: user_id,
|
|
351
|
+
session_id: session_id,
|
|
352
|
+
transaction_id: data.transaction_id,
|
|
353
|
+
currency: data.currency,
|
|
354
|
+
// This "At least one item" interface is too cumbersome to expose to end users, they get a plain array typing instead.
|
|
355
|
+
products: items
|
|
356
|
+
}],
|
|
357
|
+
tenant: this.merchant,
|
|
358
|
+
market: this.market
|
|
359
|
+
};
|
|
360
|
+
(0, $dwOGf$depictaiutilishared.foolproof_send_beacon)((0, $dwOGf$depictaiutilishared.base_url) + "/v2/create-events", request);
|
|
225
361
|
}
|
|
226
|
-
|
|
227
|
-
|
|
362
|
+
/**
|
|
363
|
+
* Update the market used for tracking events
|
|
364
|
+
*/
|
|
365
|
+
setMarket(market) {
|
|
366
|
+
this.market = market;
|
|
228
367
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
368
|
+
/**
|
|
369
|
+
* Update the product_id used for add-to-cart and pageview events on PDPs.
|
|
370
|
+
*/
|
|
371
|
+
setProductId(product_id) {
|
|
372
|
+
(0, $dwOGf$depictaiutilishared.dlog)("Setting product id", product_id);
|
|
373
|
+
this.latest_product_id = product_id;
|
|
374
|
+
this.latest_product_id_path = location.pathname;
|
|
375
|
+
if (!this.#has_sent_pageview_for_current_href) {
|
|
376
|
+
this.#sendTrackingEvent({
|
|
377
|
+
type: "page_view",
|
|
378
|
+
product_id: product_id
|
|
379
|
+
});
|
|
380
|
+
this.#has_sent_pageview_for_current_href = true;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
#getProductId() {
|
|
384
|
+
if (this.latest_product_id_path !== location.pathname) return undefined;
|
|
385
|
+
return this.latest_product_id;
|
|
234
386
|
}
|
|
235
|
-
|
|
236
|
-
|
|
387
|
+
/**
|
|
388
|
+
* Set the user_id for logged in users.
|
|
389
|
+
*
|
|
390
|
+
* https://docs.depict.ai/docs/performance-client#informing-depict-of-logged-in-users
|
|
391
|
+
*/
|
|
392
|
+
setUserId(user_id) {
|
|
393
|
+
(0, $dwOGf$depictaiutilishared.dlog)("Setting user id", user_id);
|
|
394
|
+
this.latest_user_id = user_id || undefined;
|
|
237
395
|
}
|
|
238
|
-
|
|
239
|
-
|
|
396
|
+
/**
|
|
397
|
+
* Set the current session_id.
|
|
398
|
+
*
|
|
399
|
+
* https://docs.depict.ai/docs/performance-client#browser-sessions
|
|
400
|
+
*/
|
|
401
|
+
setSessionId(session_id) {
|
|
402
|
+
(0, $dwOGf$depictaiutilishared.dlog)("Setting session id", session_id);
|
|
403
|
+
this.latest_session_id = session_id || undefined;
|
|
240
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* Observe the DOM for recommendations to track
|
|
407
|
+
*/
|
|
241
408
|
observeRecommendations() {
|
|
242
|
-
for (const [
|
|
243
|
-
const
|
|
244
|
-
(0,
|
|
245
|
-
|
|
409
|
+
for (const [attribute, type] of Object.entries((0, $1e7b1f32e4f0380b$export$79f7900b4eea40cf))) {
|
|
410
|
+
const selector = `[${attribute}]`;
|
|
411
|
+
(0, $dwOGf$depictaiutilishared.dlog)("Starting to observe product cards with selector", selector);
|
|
412
|
+
(0, $dwOGf$depictaiutilishared.observer).onexists(selector, ({
|
|
413
|
+
element: element
|
|
246
414
|
}) => {
|
|
247
|
-
const
|
|
248
|
-
|
|
415
|
+
const tracking_id = element.getAttribute(attribute);
|
|
416
|
+
if (!tracking_id) {
|
|
417
|
+
(0, $dwOGf$depictaiutilishared.derror)(`No tracking id found on element with attribute ${selector}`, element);
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
this.trackProductCard(element, tracking_id, type);
|
|
249
421
|
});
|
|
250
422
|
}
|
|
251
423
|
}
|
|
424
|
+
/**
|
|
425
|
+
* Observe the dom for add to cart buttons. Used on product detail pages.
|
|
426
|
+
*/
|
|
252
427
|
observePDPA2CButton() {
|
|
253
|
-
|
|
254
|
-
element:
|
|
428
|
+
const handler = ({
|
|
429
|
+
element: element
|
|
255
430
|
}) => {
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
431
|
+
const depict_card_selector = Object.keys((0, $1e7b1f32e4f0380b$export$79f7900b4eea40cf)).map(attribute => `[${attribute}]`).join(",");
|
|
432
|
+
// it's an add to cart button on a product card that possibly was added to the product card at a later point, if parent_depict_card is defined
|
|
433
|
+
const parent_depict_card = element.closest(depict_card_selector) || undefined;
|
|
434
|
+
(0, $dwOGf$depictaiutilishared.dlog)(`Found ${parent_depict_card ? "product card" : "pdp"} add-to-cart button`, element);
|
|
435
|
+
this.trackAddToCartButton(element, parent_depict_card);
|
|
436
|
+
};
|
|
437
|
+
(0, $dwOGf$depictaiutilishared.observer).onexists((0, $1e7b1f32e4f0380b$export$6f11e212918dbb31), handler);
|
|
260
438
|
}
|
|
261
439
|
}
|
|
262
|
-
|
|
263
|
-
let i = location.href;
|
|
264
|
-
e.instant_exec_on_suspect_history_change.add((0, e.catchify)(() => {
|
|
265
|
-
const {
|
|
266
|
-
href: e
|
|
267
|
-
} = location;
|
|
268
|
-
i !== e && (s(t)(this, p)[p] = !1, i = e);
|
|
269
|
-
}));
|
|
270
|
-
}
|
|
271
|
-
function R(e) {
|
|
272
|
-
void 0 !== e && (void 0 !== e.auto_observe && (this.auto_observe = e.auto_observe), void 0 !== e.market && (this.market = e.market));
|
|
273
|
-
}
|
|
274
|
-
function P() {
|
|
275
|
-
const t = {
|
|
276
|
-
market: this.market,
|
|
277
|
-
tenant: this.merchant,
|
|
278
|
-
user_id: this.latest_user_id,
|
|
279
|
-
session_id: this.latest_session_id
|
|
280
|
-
};
|
|
281
|
-
return {
|
|
282
|
-
...(0, e.get_tracking_event_context_data)(),
|
|
283
|
-
...t
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
function E(i) {
|
|
287
|
-
(0, e.send_depict_unfiltered)([{
|
|
288
|
-
...i,
|
|
289
|
-
...s(t)(this, k)[k]()
|
|
290
|
-
}], !0);
|
|
291
|
-
}
|
|
292
|
-
function S() {
|
|
293
|
-
if (this.latest_product_id_path === location.pathname) return this.latest_product_id;
|
|
294
|
-
}
|
|
295
|
-
(0, e.add_to_version_info)("dpc", n);
|
|
440
|
+
(0, $dwOGf$depictaiutilishared.add_to_version_info)("dpc", (0, $9c6b4a5c4c4f318d$export$83d89fbfd8236492));
|