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