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