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