@financial-times/custom-code-component 1.9.6 → 1.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/custom-code-component.js +116 -117
- package/dist/tracking.d.ts +5 -5
- package/package.json +1 -1
- package/src/custom-code-component.ts +2 -2
- package/src/tracking.ts +10 -2
|
@@ -23,56 +23,56 @@ w.prototype.captureForType = function(t) {
|
|
|
23
23
|
return ["blur", "error", "focus", "load", "resize", "scroll"].indexOf(t) !== -1;
|
|
24
24
|
};
|
|
25
25
|
w.prototype.on = function(t, e, n, o) {
|
|
26
|
-
let r, i,
|
|
26
|
+
let r, i, s, c;
|
|
27
27
|
if (!t)
|
|
28
28
|
throw new TypeError("Invalid event type: " + t);
|
|
29
29
|
if (typeof e == "function" && (o = n, n = e, e = null), o === void 0 && (o = this.captureForType(t)), typeof n != "function")
|
|
30
30
|
throw new TypeError("Handler must be a type of Function");
|
|
31
|
-
return r = this.rootElement, i = this.listenerMap[o ? 1 : 0], i[t] || (r && r.addEventListener(t, this.handle, o), i[t] = []), e ? /^[a-z]+$/i.test(e) ? (c = e,
|
|
31
|
+
return r = this.rootElement, i = this.listenerMap[o ? 1 : 0], i[t] || (r && r.addEventListener(t, this.handle, o), i[t] = []), e ? /^[a-z]+$/i.test(e) ? (c = e, s = Et) : /^#[a-z0-9\-_]+$/i.test(e) ? (c = e.slice(1), s = xt) : (c = e, s = Element.prototype.matches) : (c = null, s = vt.bind(this)), i[t].push({
|
|
32
32
|
selector: e,
|
|
33
33
|
handler: n,
|
|
34
|
-
matcher:
|
|
34
|
+
matcher: s,
|
|
35
35
|
matcherParam: c
|
|
36
36
|
}), this;
|
|
37
37
|
};
|
|
38
38
|
w.prototype.off = function(t, e, n, o) {
|
|
39
|
-
let r, i,
|
|
39
|
+
let r, i, s, c, a;
|
|
40
40
|
if (typeof e == "function" && (o = n, n = e, e = null), o === void 0)
|
|
41
41
|
return this.off(t, e, n, !0), this.off(t, e, n, !1), this;
|
|
42
|
-
if (
|
|
43
|
-
for (
|
|
44
|
-
|
|
42
|
+
if (s = this.listenerMap[o ? 1 : 0], !t) {
|
|
43
|
+
for (a in s)
|
|
44
|
+
s.hasOwnProperty(a) && this.off(a, e, n);
|
|
45
45
|
return this;
|
|
46
46
|
}
|
|
47
|
-
if (c =
|
|
47
|
+
if (c = s[t], !c || !c.length)
|
|
48
48
|
return this;
|
|
49
49
|
for (r = c.length - 1; r >= 0; r--)
|
|
50
50
|
i = c[r], (!e || e === i.selector) && (!n || n === i.handler) && (this._removedListeners.push(i), c.splice(r, 1));
|
|
51
|
-
return c.length || (delete
|
|
51
|
+
return c.length || (delete s[t], this.rootElement && this.rootElement.removeEventListener(t, this.handle, o)), this;
|
|
52
52
|
};
|
|
53
53
|
w.prototype.handle = function(t) {
|
|
54
54
|
let e, n;
|
|
55
55
|
const o = t.type;
|
|
56
|
-
let r, i,
|
|
56
|
+
let r, i, s, c, a = [], u;
|
|
57
57
|
const l = "ftLabsDelegateIgnore";
|
|
58
58
|
if (t[l] === !0)
|
|
59
59
|
return;
|
|
60
60
|
switch (u = t.target, u.nodeType === 3 && (u = u.parentNode), u.correspondingUseElement && (u = u.correspondingUseElement), r = this.rootElement, i = t.eventPhase || (t.target !== t.currentTarget ? 3 : 2), i) {
|
|
61
61
|
case 1:
|
|
62
|
-
|
|
62
|
+
a = this.listenerMap[1][o];
|
|
63
63
|
break;
|
|
64
64
|
case 2:
|
|
65
|
-
this.listenerMap[0] && this.listenerMap[0][o] && (
|
|
65
|
+
this.listenerMap[0] && this.listenerMap[0][o] && (a = a.concat(this.listenerMap[0][o])), this.listenerMap[1] && this.listenerMap[1][o] && (a = a.concat(this.listenerMap[1][o]));
|
|
66
66
|
break;
|
|
67
67
|
case 3:
|
|
68
|
-
|
|
68
|
+
a = this.listenerMap[0][o];
|
|
69
69
|
break;
|
|
70
70
|
}
|
|
71
71
|
let f = [];
|
|
72
|
-
for (n =
|
|
73
|
-
for (e = 0; e < n && (
|
|
74
|
-
u.tagName && ["button", "input", "select", "textarea"].indexOf(u.tagName.toLowerCase()) > -1 && u.hasAttribute("disabled") ? f = [] :
|
|
75
|
-
if (u === r || (n =
|
|
72
|
+
for (n = a.length; u && n; ) {
|
|
73
|
+
for (e = 0; e < n && (s = a[e], !!s); e++)
|
|
74
|
+
u.tagName && ["button", "input", "select", "textarea"].indexOf(u.tagName.toLowerCase()) > -1 && u.hasAttribute("disabled") ? f = [] : s.matcher.call(u, s.matcherParam, u) && f.push([t, u, s]);
|
|
75
|
+
if (u === r || (n = a.length, u = u.parentElement || u.parentNode, u instanceof HTMLDocument))
|
|
76
76
|
break;
|
|
77
77
|
}
|
|
78
78
|
let d;
|
|
@@ -216,8 +216,8 @@ function ot(t) {
|
|
|
216
216
|
}
|
|
217
217
|
if (r instanceof Object) {
|
|
218
218
|
e.add(r);
|
|
219
|
-
for (const [
|
|
220
|
-
c instanceof Object && (Array.isArray(r) ? o(c, `${i}[${
|
|
219
|
+
for (const [s, c] of Object.entries(r))
|
|
220
|
+
c instanceof Object && (Array.isArray(r) ? o(c, `${i}[${s}]`) : o(c, `${i}.${s}`));
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
return o(t, ""), n;
|
|
@@ -276,51 +276,51 @@ function q(t, e) {
|
|
|
276
276
|
const S = function(t, e = {}) {
|
|
277
277
|
const n = "o-tracking";
|
|
278
278
|
if (typeof t != "string" || t === "") {
|
|
279
|
-
const
|
|
279
|
+
const a = new Error("You must specify a name for the store.");
|
|
280
280
|
throw v("oErrors", "log", {
|
|
281
|
-
error:
|
|
281
|
+
error: a.message,
|
|
282
282
|
info: { module: "o-tracking" }
|
|
283
|
-
}),
|
|
283
|
+
}), a;
|
|
284
284
|
}
|
|
285
285
|
this.config = Object.assign({}, e), this.data = null, this.storageKey = this.config.nameOverride ? this.config.nameOverride : [n, t].join("_"), this.storage = {
|
|
286
286
|
_type: "localStorage",
|
|
287
|
-
load: function(
|
|
288
|
-
return window.localStorage.getItem(
|
|
287
|
+
load: function(a) {
|
|
288
|
+
return window.localStorage.getItem(a);
|
|
289
289
|
},
|
|
290
|
-
save: function(
|
|
291
|
-
return window.localStorage.setItem(
|
|
290
|
+
save: function(a, u) {
|
|
291
|
+
return window.localStorage.setItem(a, u);
|
|
292
292
|
},
|
|
293
|
-
remove: function(
|
|
294
|
-
return i(
|
|
293
|
+
remove: function(a) {
|
|
294
|
+
return i(a), window.localStorage.removeItem(a);
|
|
295
295
|
}
|
|
296
296
|
};
|
|
297
|
-
function o(
|
|
298
|
-
|
|
297
|
+
function o(a) {
|
|
298
|
+
a = a + "=";
|
|
299
299
|
const u = window.document.cookie.split(";");
|
|
300
300
|
let l, f;
|
|
301
301
|
for (l = 0; l < u.length; l = l + 1)
|
|
302
|
-
if (f = u[l].replace(/^\s+|\s+$/g, ""), f.indexOf(
|
|
303
|
-
return Ct(f.substring(
|
|
302
|
+
if (f = u[l].replace(/^\s+|\s+$/g, ""), f.indexOf(a) === 0)
|
|
303
|
+
return Ct(f.substring(a.length, f.length));
|
|
304
304
|
return null;
|
|
305
305
|
}
|
|
306
|
-
function r(
|
|
306
|
+
function r(a, u, l) {
|
|
307
307
|
let f, d = "";
|
|
308
308
|
y(l, "number") && (f = /* @__PURE__ */ new Date(), f.setTime(f.getTime() + l), d = "expires=" + f.toUTCString() + ";");
|
|
309
|
-
const bt = V(
|
|
309
|
+
const bt = V(a) + "=" + V(u) + ";" + d + "path=/;" + (e.domain ? "domain=." + e.domain + ";" : "");
|
|
310
310
|
window.document.cookie = bt;
|
|
311
311
|
}
|
|
312
|
-
function i(
|
|
313
|
-
r(
|
|
312
|
+
function i(a) {
|
|
313
|
+
r(a, "", -1);
|
|
314
314
|
}
|
|
315
|
-
const
|
|
316
|
-
if (
|
|
315
|
+
const s = this.storage.load(this.storageKey);
|
|
316
|
+
if (s)
|
|
317
317
|
try {
|
|
318
|
-
this.data = JSON.parse(
|
|
319
|
-
} catch (
|
|
318
|
+
this.data = JSON.parse(s);
|
|
319
|
+
} catch (a) {
|
|
320
320
|
v("oErrors", "log", {
|
|
321
|
-
error:
|
|
321
|
+
error: a.message,
|
|
322
322
|
module: "o-tracking"
|
|
323
|
-
}), this.data =
|
|
323
|
+
}), this.data = s;
|
|
324
324
|
}
|
|
325
325
|
const c = o(this.storageKey);
|
|
326
326
|
if (c)
|
|
@@ -328,16 +328,16 @@ const S = function(t, e = {}) {
|
|
|
328
328
|
if (this.storageKey === "spoor-id")
|
|
329
329
|
this.data = c;
|
|
330
330
|
else {
|
|
331
|
-
const
|
|
332
|
-
this.data ? Object.assign(this.data,
|
|
333
|
-
for (const u of Object.keys(
|
|
331
|
+
const a = JSON.parse(c);
|
|
332
|
+
this.data ? Object.assign(this.data, a) : this.data = a;
|
|
333
|
+
for (const u of Object.keys(a))
|
|
334
334
|
u !== "spoor-id" && i(u);
|
|
335
335
|
}
|
|
336
|
-
} catch (
|
|
336
|
+
} catch (a) {
|
|
337
337
|
v("oErrors", "log", {
|
|
338
|
-
error:
|
|
338
|
+
error: a.message,
|
|
339
339
|
module: "o-tracking"
|
|
340
|
-
}), this.data =
|
|
340
|
+
}), this.data = s;
|
|
341
341
|
}
|
|
342
342
|
return this;
|
|
343
343
|
};
|
|
@@ -536,7 +536,7 @@ function at() {
|
|
|
536
536
|
return (h("config") || {}).queue === !0 ? !1 : !!navigator.sendBeacon;
|
|
537
537
|
}
|
|
538
538
|
function ct(t, e) {
|
|
539
|
-
const n = t.queueTime, o = (/* @__PURE__ */ new Date()).getTime() - n, r = at() ? j("sendBeacon")() : window.XMLHttpRequest && "withCredentials" in new window.XMLHttpRequest() ? j("xhr")() : j("image")(), i = t.callback,
|
|
539
|
+
const n = t.queueTime, o = (/* @__PURE__ */ new Date()).getTime() - n, r = at() ? j("sendBeacon")() : window.XMLHttpRequest && "withCredentials" in new window.XMLHttpRequest() ? j("xhr")() : j("image")(), i = t.callback, s = h("config") && h("config").system || {}, c = m(s, {
|
|
540
540
|
version: h("version"),
|
|
541
541
|
// Version of the tracking client e.g. '1.2'
|
|
542
542
|
source: h("source"),
|
|
@@ -551,7 +551,7 @@ Here are the paths in the data which are circular:
|
|
|
551
551
|
` + JSON.stringify(ot(t), void 0, 4);
|
|
552
552
|
throw new Error(l);
|
|
553
553
|
}
|
|
554
|
-
const
|
|
554
|
+
const a = JSON.stringify(t);
|
|
555
555
|
r.complete(function(l) {
|
|
556
556
|
y(i, "function") && (i.call(t), P("calling user_callback")), l ? (t.queueTime = n, g.add(t).save(), v("oErrors", "log", {
|
|
557
557
|
error: l.message,
|
|
@@ -559,7 +559,7 @@ Here are the paths in the data which are circular:
|
|
|
559
559
|
})) : e && e();
|
|
560
560
|
});
|
|
561
561
|
let u = "https://spoor-api.ft.com/ingest";
|
|
562
|
-
t && t.category && t.action && (u += `?type=${t.category}:${t.action}`), r.send(u,
|
|
562
|
+
t && t.category && t.action && (u += `?type=${t.category}:${t.action}`), r.send(u, a);
|
|
563
563
|
}
|
|
564
564
|
function Mt(t) {
|
|
565
565
|
t.queueTime = (/* @__PURE__ */ new Date()).getTime(), at() ? ct(t) : g.add(t).save(), P("AddedToQueue", g);
|
|
@@ -570,8 +570,8 @@ function I(t = function() {
|
|
|
570
570
|
if (e.length > 200) {
|
|
571
571
|
const r = {};
|
|
572
572
|
e.forEach(function(i) {
|
|
573
|
-
const
|
|
574
|
-
Object.prototype.hasOwnProperty.call(r,
|
|
573
|
+
const s = [i.category, i.action].join(":");
|
|
574
|
+
Object.prototype.hasOwnProperty.call(r, s) || (r[s] = 0), r[s] += 1;
|
|
575
575
|
}), g.replace([]), g.add({
|
|
576
576
|
category: "o-tracking",
|
|
577
577
|
action: "queue-bug",
|
|
@@ -661,21 +661,21 @@ function qt(t) {
|
|
|
661
661
|
const e = Bt(t);
|
|
662
662
|
if (typeof e > "u")
|
|
663
663
|
return;
|
|
664
|
-
const n = e[0], o = function(
|
|
665
|
-
const c =
|
|
664
|
+
const n = e[0], o = function(s) {
|
|
665
|
+
const c = s.parentElement;
|
|
666
666
|
if (c) {
|
|
667
|
-
for (let
|
|
668
|
-
if (c.childNodes[
|
|
669
|
-
return
|
|
667
|
+
for (let a = 0; a < c.childNodes.length; a++)
|
|
668
|
+
if (c.childNodes[a] === n)
|
|
669
|
+
return a;
|
|
670
670
|
return -1;
|
|
671
671
|
} else
|
|
672
672
|
return 0;
|
|
673
|
-
}(n), r = e.reduceRight(function(i,
|
|
674
|
-
if (!
|
|
675
|
-
return i + " - " +
|
|
673
|
+
}(n), r = e.reduceRight(function(i, s) {
|
|
674
|
+
if (!s.nodeName)
|
|
675
|
+
return i + " - " + s.constructor.name + `
|
|
676
676
|
`;
|
|
677
|
-
const c =
|
|
678
|
-
return c.indexOf("#") === 0 ? i + "<" + c + ">" : i + "<" + c + ' id="' + (
|
|
677
|
+
const c = s.nodeName.toLowerCase();
|
|
678
|
+
return c.indexOf("#") === 0 ? i + "<" + c + ">" : i + "<" + c + ' id="' + (s.id || "") + '">';
|
|
679
679
|
}, "");
|
|
680
680
|
return Kt(r + "_siblingIndex=" + o);
|
|
681
681
|
}
|
|
@@ -759,56 +759,56 @@ E.prototype.captureForType = function(t) {
|
|
|
759
759
|
return ["blur", "error", "focus", "load", "resize", "scroll"].indexOf(t) !== -1;
|
|
760
760
|
};
|
|
761
761
|
E.prototype.on = function(t, e, n, o) {
|
|
762
|
-
let r, i,
|
|
762
|
+
let r, i, s, c;
|
|
763
763
|
if (!t)
|
|
764
764
|
throw new TypeError("Invalid event type: " + t);
|
|
765
765
|
if (typeof e == "function" && (o = n, n = e, e = null), o === void 0 && (o = this.captureForType(t)), typeof n != "function")
|
|
766
766
|
throw new TypeError("Handler must be a type of Function");
|
|
767
|
-
return r = this.rootElement, i = this.listenerMap[o ? 1 : 0], i[t] || (r && r.addEventListener(t, this.handle, o), i[t] = []), e ? /^[a-z]+$/i.test(e) ? (c = e,
|
|
767
|
+
return r = this.rootElement, i = this.listenerMap[o ? 1 : 0], i[t] || (r && r.addEventListener(t, this.handle, o), i[t] = []), e ? /^[a-z]+$/i.test(e) ? (c = e, s = Xt) : /^#[a-z0-9\-_]+$/i.test(e) ? (c = e.slice(1), s = Gt) : (c = e, s = Element.prototype.matches) : (c = null, s = Yt.bind(this)), i[t].push({
|
|
768
768
|
selector: e,
|
|
769
769
|
handler: n,
|
|
770
|
-
matcher:
|
|
770
|
+
matcher: s,
|
|
771
771
|
matcherParam: c
|
|
772
772
|
}), this;
|
|
773
773
|
};
|
|
774
774
|
E.prototype.off = function(t, e, n, o) {
|
|
775
|
-
let r, i,
|
|
775
|
+
let r, i, s, c, a;
|
|
776
776
|
if (typeof e == "function" && (o = n, n = e, e = null), o === void 0)
|
|
777
777
|
return this.off(t, e, n, !0), this.off(t, e, n, !1), this;
|
|
778
|
-
if (
|
|
779
|
-
for (
|
|
780
|
-
|
|
778
|
+
if (s = this.listenerMap[o ? 1 : 0], !t) {
|
|
779
|
+
for (a in s)
|
|
780
|
+
s.hasOwnProperty(a) && this.off(a, e, n);
|
|
781
781
|
return this;
|
|
782
782
|
}
|
|
783
|
-
if (c =
|
|
783
|
+
if (c = s[t], !c || !c.length)
|
|
784
784
|
return this;
|
|
785
785
|
for (r = c.length - 1; r >= 0; r--)
|
|
786
786
|
i = c[r], (!e || e === i.selector) && (!n || n === i.handler) && (this._removedListeners.push(i), c.splice(r, 1));
|
|
787
|
-
return c.length || (delete
|
|
787
|
+
return c.length || (delete s[t], this.rootElement && this.rootElement.removeEventListener(t, this.handle, o)), this;
|
|
788
788
|
};
|
|
789
789
|
E.prototype.handle = function(t) {
|
|
790
790
|
let e, n;
|
|
791
791
|
const o = t.type;
|
|
792
|
-
let r, i,
|
|
792
|
+
let r, i, s, c, a = [], u;
|
|
793
793
|
const l = "ftLabsDelegateIgnore";
|
|
794
794
|
if (t[l] === !0)
|
|
795
795
|
return;
|
|
796
796
|
switch (u = t.target, u.nodeType === 3 && (u = u.parentNode), u.correspondingUseElement && (u = u.correspondingUseElement), r = this.rootElement, i = t.eventPhase || (t.target !== t.currentTarget ? 3 : 2), i) {
|
|
797
797
|
case 1:
|
|
798
|
-
|
|
798
|
+
a = this.listenerMap[1][o];
|
|
799
799
|
break;
|
|
800
800
|
case 2:
|
|
801
|
-
this.listenerMap[0] && this.listenerMap[0][o] && (
|
|
801
|
+
this.listenerMap[0] && this.listenerMap[0][o] && (a = a.concat(this.listenerMap[0][o])), this.listenerMap[1] && this.listenerMap[1][o] && (a = a.concat(this.listenerMap[1][o]));
|
|
802
802
|
break;
|
|
803
803
|
case 3:
|
|
804
|
-
|
|
804
|
+
a = this.listenerMap[0][o];
|
|
805
805
|
break;
|
|
806
806
|
}
|
|
807
807
|
let f = [];
|
|
808
|
-
for (n =
|
|
809
|
-
for (e = 0; e < n && (
|
|
810
|
-
u.tagName && ["button", "input", "select", "textarea"].indexOf(u.tagName.toLowerCase()) > -1 && u.hasAttribute("disabled") ? f = [] :
|
|
811
|
-
if (u === r || (n =
|
|
808
|
+
for (n = a.length; u && n; ) {
|
|
809
|
+
for (e = 0; e < n && (s = a[e], !!s); e++)
|
|
810
|
+
u.tagName && ["button", "input", "select", "textarea"].indexOf(u.tagName.toLowerCase()) > -1 && u.hasAttribute("disabled") ? f = [] : s.matcher.call(u, s.matcherParam, u) && f.push([t, u, s]);
|
|
811
|
+
if (u === r || (n = a.length, u = u.parentElement || u.parentNode, u instanceof HTMLDocument))
|
|
812
812
|
break;
|
|
813
813
|
}
|
|
814
814
|
let d;
|
|
@@ -883,13 +883,13 @@ const Zt = (t, e, n) => {
|
|
|
883
883
|
function dt(t) {
|
|
884
884
|
const e = document, n = t, o = n.getAttribute("data-trackable") ? `[data-trackable="${n.getAttribute("data-trackable")}"]` : n.nodeName, r = [], i = {};
|
|
885
885
|
for (; t && t !== e; ) {
|
|
886
|
-
const
|
|
887
|
-
let
|
|
888
|
-
|
|
889
|
-
|
|
886
|
+
const s = te(t), c = Array.from(t.attributes);
|
|
887
|
+
let a = oe(c, s);
|
|
888
|
+
a["data-trackable"] && (a = Object.assign(
|
|
889
|
+
a,
|
|
890
890
|
Zt(t, n, o)
|
|
891
|
-
)), r.push(
|
|
892
|
-
const u = re(c,
|
|
891
|
+
)), r.push(a);
|
|
892
|
+
const u = re(c, s, t === n);
|
|
893
893
|
_(u, i), t = t.parentNode;
|
|
894
894
|
}
|
|
895
895
|
return { trace: r, customContext: i };
|
|
@@ -915,8 +915,8 @@ const ie = [
|
|
|
915
915
|
return;
|
|
916
916
|
const o = se(e), { trace: r, customContext: i } = dt(n);
|
|
917
917
|
o.domPathTokens = r, o.url = window.document.location.href || null, o.source_id = x.getRootID(), _(i, o), t.context = o;
|
|
918
|
-
const
|
|
919
|
-
x.track(
|
|
918
|
+
const s = m(h("config"), t);
|
|
919
|
+
x.track(s);
|
|
920
920
|
}, ce = (t, e) => {
|
|
921
921
|
e = e || 'a, button, input, [role="button"]';
|
|
922
922
|
const n = {
|
|
@@ -944,10 +944,10 @@ const ue = {
|
|
|
944
944
|
if (n.getContextData) {
|
|
945
945
|
if (typeof n.getContextData != "function")
|
|
946
946
|
throw new Error("opts.getContextData is not a function");
|
|
947
|
-
const
|
|
948
|
-
if (typeof
|
|
947
|
+
const s = n.getContextData(e);
|
|
948
|
+
if (typeof s != "object")
|
|
949
949
|
throw new Error("opts.getContextData function should return {object}");
|
|
950
|
-
i = At(
|
|
950
|
+
i = At(s, fe);
|
|
951
951
|
} else
|
|
952
952
|
i = {};
|
|
953
953
|
i.domPathTokens = o, i.url = window.document.location.href || null, _(r, i), t.context = i;
|
|
@@ -960,13 +960,13 @@ const ue = {
|
|
|
960
960
|
if (!n.length)
|
|
961
961
|
return;
|
|
962
962
|
function o(i) {
|
|
963
|
-
i.forEach((
|
|
964
|
-
if (
|
|
963
|
+
i.forEach((s) => {
|
|
964
|
+
if (s.isIntersecting || s.intersectionRatio > 0) {
|
|
965
965
|
const c = {
|
|
966
966
|
action: t.action || "view",
|
|
967
967
|
category: t.category || "component"
|
|
968
|
-
},
|
|
969
|
-
le(c,
|
|
968
|
+
}, a = s.target;
|
|
969
|
+
le(c, a, t), x.track(c), r.unobserve(a);
|
|
970
970
|
}
|
|
971
971
|
});
|
|
972
972
|
}
|
|
@@ -1085,13 +1085,13 @@ const Ee = (t, e, n) => {
|
|
|
1085
1085
|
function Se(t, e) {
|
|
1086
1086
|
const n = t, o = n.getAttribute("data-trackable") ? `[data-trackable="${n.getAttribute("data-trackable")}"]` : n.nodeName, r = [], i = {};
|
|
1087
1087
|
for (; t && t !== e; ) {
|
|
1088
|
-
const
|
|
1089
|
-
let
|
|
1090
|
-
|
|
1091
|
-
|
|
1088
|
+
const s = ve(t), c = Array.from(t.attributes);
|
|
1089
|
+
let a = Oe(c, s);
|
|
1090
|
+
a["data-trackable"] && (a = Object.assign(
|
|
1091
|
+
a,
|
|
1092
1092
|
Ee(t, n, o)
|
|
1093
|
-
)), r.push(
|
|
1094
|
-
const u = Ce(c,
|
|
1093
|
+
)), r.push(a);
|
|
1094
|
+
const u = Ce(c, s, t === n);
|
|
1095
1095
|
_(u, i), t = t.parentNode;
|
|
1096
1096
|
}
|
|
1097
1097
|
return { trace: r, customContext: i };
|
|
@@ -1104,10 +1104,10 @@ class Pe {
|
|
|
1104
1104
|
subtype: o = "interactive",
|
|
1105
1105
|
teamName: r = "djd",
|
|
1106
1106
|
shadowRoot: i = null,
|
|
1107
|
-
category:
|
|
1107
|
+
category: s = "cta",
|
|
1108
1108
|
elements: c = 'a, button, input, [role="button"]'
|
|
1109
|
-
}
|
|
1110
|
-
this.cccId = e, this.cccName = n, this.subtype = o, this.teamName = r, this.shadowRoot = i, this.category =
|
|
1109
|
+
}) {
|
|
1110
|
+
this.cccId = e, this.cccName = n, this.subtype = o, this.teamName = r, this.shadowRoot = i, this.category = s, this.elements = c, this.isInitialised = !1;
|
|
1111
1111
|
}
|
|
1112
1112
|
// Get properties for the event (as opposed to properties of the clicked element)
|
|
1113
1113
|
getEventProperties(e) {
|
|
@@ -1124,8 +1124,8 @@ class Pe {
|
|
|
1124
1124
|
// Controller for handling click events
|
|
1125
1125
|
handleClickEvent(e, n) {
|
|
1126
1126
|
return (o, r) => {
|
|
1127
|
-
const i = this.getEventProperties(o), { trace:
|
|
1128
|
-
i.custom = r.dataset && r.dataset.custom ? JSON.parse(r.dataset.custom) : null, i.domPathTokens =
|
|
1127
|
+
const i = this.getEventProperties(o), { trace: s, customContext: c } = Se(r, n);
|
|
1128
|
+
i.custom = r.dataset && r.dataset.custom ? JSON.parse(r.dataset.custom) : null, i.domPathTokens = s, i.component = {
|
|
1129
1129
|
id: this.cccId,
|
|
1130
1130
|
name: this.cccName,
|
|
1131
1131
|
type: "custom-code-component",
|
|
@@ -1171,7 +1171,7 @@ class Pe {
|
|
|
1171
1171
|
const o = {
|
|
1172
1172
|
action: "click",
|
|
1173
1173
|
category: this.category
|
|
1174
|
-
}, r = (n = this.shadowRoot) == null ? void 0 : n.querySelector("
|
|
1174
|
+
}, r = (n = this.shadowRoot) == null ? void 0 : n.querySelector("[data-component-root]");
|
|
1175
1175
|
this.shadowRoot && new w(r).on(
|
|
1176
1176
|
"click",
|
|
1177
1177
|
this.elements,
|
|
@@ -1196,19 +1196,18 @@ class _e extends HTMLElement {
|
|
|
1196
1196
|
}, this.channel = new MessageChannel();
|
|
1197
1197
|
}
|
|
1198
1198
|
async mount() {
|
|
1199
|
-
var c;
|
|
1200
1199
|
if (!this.app)
|
|
1201
1200
|
throw new Error("CCC mounted without App");
|
|
1202
1201
|
const e = this.shadowRoot ?? this.attachShadow({ mode: this.mode }), n = this.app, o = JSON.parse(this.getAttribute("data-component-props")), r = Object.fromEntries(
|
|
1203
|
-
[...this.attributes].filter((
|
|
1202
|
+
[...this.attributes].filter((c) => !this.RESERVED_ATTRS.has(c.name)).map((c) => [c.name, c.value])
|
|
1204
1203
|
);
|
|
1205
|
-
|
|
1204
|
+
this.tracking = new Pe({
|
|
1206
1205
|
name: `${this.getAttribute("path")}@${this.getAttribute("version")}`,
|
|
1207
1206
|
subtype: "interactive",
|
|
1208
1207
|
teamName: "djd",
|
|
1209
1208
|
shadowRoot: this.shadowRoot
|
|
1210
1209
|
});
|
|
1211
|
-
const { unmount: i, onmessage:
|
|
1210
|
+
const { unmount: i, onmessage: s } = n(
|
|
1212
1211
|
e,
|
|
1213
1212
|
{
|
|
1214
1213
|
...r,
|
|
@@ -1218,18 +1217,18 @@ class _e extends HTMLElement {
|
|
|
1218
1217
|
},
|
|
1219
1218
|
...this.children
|
|
1220
1219
|
) || {};
|
|
1221
|
-
i && (this.unmount = i),
|
|
1220
|
+
i && (this.unmount = i), s && (this.onmessage = s);
|
|
1222
1221
|
}
|
|
1223
1222
|
async connectedCallback() {
|
|
1224
|
-
var
|
|
1225
|
-
const e = this.getAttribute("path"), n = this.getAttribute("version"), o = this.getAttribute("load-timeout") ?? 2e3, r = (
|
|
1223
|
+
var a;
|
|
1224
|
+
const e = this.getAttribute("path"), n = this.getAttribute("version"), o = this.getAttribute("load-timeout") ?? 2e3, r = (a = this.getAttribute("env")) == null ? void 0 : a.toLowerCase().startsWith("d");
|
|
1226
1225
|
if (!e)
|
|
1227
1226
|
throw new Error(
|
|
1228
1227
|
"path attribute not specified in <custom-code-component>"
|
|
1229
1228
|
);
|
|
1230
|
-
const [i,
|
|
1231
|
-
if (!(!i || !
|
|
1232
|
-
this.source = r ? `http://localhost:5173/src/${i}/index.jsx` : `https://www.ft.com/__component/${c}/${
|
|
1229
|
+
const [i, s, c] = e.split("/").reverse();
|
|
1230
|
+
if (!(!i || !s || !c)) {
|
|
1231
|
+
this.source = r ? `http://localhost:5173/src/${i}/index.jsx` : `https://www.ft.com/__component/${c}/${s}${n ? `@${n}` : "@latest"}/${i}/${i}.js`;
|
|
1233
1232
|
try {
|
|
1234
1233
|
this.app = await new Promise((u, l) => {
|
|
1235
1234
|
const f = setTimeout(() => {
|
package/dist/tracking.d.ts
CHANGED
|
@@ -7,14 +7,14 @@ declare class Tracking {
|
|
|
7
7
|
category: string;
|
|
8
8
|
elements: string | string[];
|
|
9
9
|
isInitialised: boolean;
|
|
10
|
-
constructor({ id, name, subtype, teamName, shadowRoot, category, elements, }
|
|
10
|
+
constructor({ id, name, subtype, teamName, shadowRoot, category, elements, }: {
|
|
11
11
|
id?: string;
|
|
12
|
-
name
|
|
13
|
-
subtype
|
|
12
|
+
name: string;
|
|
13
|
+
subtype: string;
|
|
14
14
|
teamName?: string;
|
|
15
|
-
shadowRoot
|
|
15
|
+
shadowRoot: ShadowRoot | null;
|
|
16
16
|
category?: string;
|
|
17
|
-
elements?: string;
|
|
17
|
+
elements?: string | string[];
|
|
18
18
|
});
|
|
19
19
|
getEventProperties(event: any): {};
|
|
20
20
|
handleClickEvent(eventData: any, root: any): (clickEvent: any, clickElement: any) => void;
|
package/package.json
CHANGED
|
@@ -44,14 +44,14 @@ class FTCustomCodeComponent extends HTMLElement {
|
|
|
44
44
|
);
|
|
45
45
|
|
|
46
46
|
// Clear old children
|
|
47
|
-
this.shadowRoot?.replaceChildren();
|
|
47
|
+
// this.shadowRoot?.replaceChildren();
|
|
48
48
|
|
|
49
49
|
// Create tracking instance
|
|
50
50
|
this.tracking = new Tracking({
|
|
51
51
|
name: `${this.getAttribute("path")}@${this.getAttribute("version")}`,
|
|
52
52
|
subtype: "interactive",
|
|
53
53
|
teamName: "djd",
|
|
54
|
-
shadowRoot: this.shadowRoot
|
|
54
|
+
shadowRoot: this.shadowRoot,
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
const { unmount, onmessage } =
|
package/src/tracking.ts
CHANGED
|
@@ -26,7 +26,15 @@ class Tracking {
|
|
|
26
26
|
shadowRoot = null,
|
|
27
27
|
category = "cta",
|
|
28
28
|
elements = 'a, button, input, [role="button"]',
|
|
29
|
-
}
|
|
29
|
+
}: {
|
|
30
|
+
id?: string;
|
|
31
|
+
name: string;
|
|
32
|
+
subtype: string;
|
|
33
|
+
teamName?: string;
|
|
34
|
+
shadowRoot: ShadowRoot | null;
|
|
35
|
+
category?: string;
|
|
36
|
+
elements?: string | string[];
|
|
37
|
+
}) {
|
|
30
38
|
this.cccId = id;
|
|
31
39
|
this.cccName = name;
|
|
32
40
|
this.subtype = subtype;
|
|
@@ -126,7 +134,7 @@ class Tracking {
|
|
|
126
134
|
category: this.category,
|
|
127
135
|
};
|
|
128
136
|
|
|
129
|
-
const root = this.shadowRoot?.querySelector("
|
|
137
|
+
const root = this.shadowRoot?.querySelector("[data-component-root]");
|
|
130
138
|
|
|
131
139
|
if (this.shadowRoot) {
|
|
132
140
|
const shadowDelegate = new Delegate(root);
|