@financial-times/custom-code-component 1.9.4 → 1.9.5
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 +48 -47
- package/dist/tracking.d.ts +4 -2
- package/package.json +1 -1
- package/src/custom-code-component.ts +2 -2
- package/src/tracking.ts +9 -5
|
@@ -127,13 +127,13 @@ function Q(t) {
|
|
|
127
127
|
}
|
|
128
128
|
const C = kt, h = Ot;
|
|
129
129
|
let A = 0;
|
|
130
|
-
const H = 4,
|
|
130
|
+
const H = 4, N = 36, et = Math.pow(N, H), F = function(e, n) {
|
|
131
131
|
const o = "000000000" + e;
|
|
132
132
|
return o.substr(o.length - n);
|
|
133
133
|
}, U = function() {
|
|
134
|
-
return F((Math.random() * et << 0).toString(
|
|
134
|
+
return F((Math.random() * et << 0).toString(N), H);
|
|
135
135
|
}, nt = () => (A = A < et ? A : 0, A++, A - 1), p = function() {
|
|
136
|
-
const e = "c", n = (/* @__PURE__ */ new Date()).getTime().toString(
|
|
136
|
+
const e = "c", n = (/* @__PURE__ */ new Date()).getTime().toString(N), o = p.fingerprint(), r = U() + U(), i = F(nt().toString(N), H);
|
|
137
137
|
return e + n + i + o + r;
|
|
138
138
|
};
|
|
139
139
|
p.slug = function() {
|
|
@@ -203,7 +203,7 @@ function At(t, e) {
|
|
|
203
203
|
function R(t) {
|
|
204
204
|
return typeof t == "string" ? t.trim() : t;
|
|
205
205
|
}
|
|
206
|
-
function
|
|
206
|
+
function _(t, e) {
|
|
207
207
|
for (const n in t)
|
|
208
208
|
e[n] ? console.warn(`You can't set a custom property called ${n}`) : e[n] = t[n];
|
|
209
209
|
}
|
|
@@ -381,11 +381,11 @@ function Pt(t, e) {
|
|
|
381
381
|
function it(t) {
|
|
382
382
|
return O = t, O || (O = p()), B.write(O), O;
|
|
383
383
|
}
|
|
384
|
-
function
|
|
384
|
+
function _t() {
|
|
385
385
|
return O;
|
|
386
386
|
}
|
|
387
387
|
let $;
|
|
388
|
-
const
|
|
388
|
+
const Nt = {
|
|
389
389
|
storage: "best",
|
|
390
390
|
name: "session",
|
|
391
391
|
expires: 30 * 60 * 1e3
|
|
@@ -410,9 +410,9 @@ function st() {
|
|
|
410
410
|
isNew: n
|
|
411
411
|
};
|
|
412
412
|
}
|
|
413
|
-
function
|
|
413
|
+
function It(t) {
|
|
414
414
|
y(t, "string") && (t = { name: t }), y(t) && (t = {});
|
|
415
|
-
const e = m(
|
|
415
|
+
const e = m(Nt, t);
|
|
416
416
|
return e.storage === "cookie" && t.name && (e.nameOverride = e.name), $ = new S(e.name, e), st();
|
|
417
417
|
}
|
|
418
418
|
function b(t) {
|
|
@@ -473,7 +473,7 @@ b.prototype.shift = function() {
|
|
|
473
473
|
b.prototype.save = function() {
|
|
474
474
|
return this.storage.write(this.queue), this;
|
|
475
475
|
};
|
|
476
|
-
function
|
|
476
|
+
function Lt() {
|
|
477
477
|
const t = new window.XMLHttpRequest();
|
|
478
478
|
return {
|
|
479
479
|
name: "xhr",
|
|
@@ -522,7 +522,7 @@ function j(t) {
|
|
|
522
522
|
return G.transport;
|
|
523
523
|
switch (t) {
|
|
524
524
|
case "xhr":
|
|
525
|
-
return
|
|
525
|
+
return Lt;
|
|
526
526
|
case "sendBeacon":
|
|
527
527
|
return Dt;
|
|
528
528
|
case "image":
|
|
@@ -564,7 +564,7 @@ Here are the paths in the data which are circular:
|
|
|
564
564
|
function Mt(t) {
|
|
565
565
|
t.queueTime = (/* @__PURE__ */ new Date()).getTime(), at() ? ct(t) : g.add(t).save(), P("AddedToQueue", g);
|
|
566
566
|
}
|
|
567
|
-
function
|
|
567
|
+
function I(t = function() {
|
|
568
568
|
}) {
|
|
569
569
|
const e = g.all();
|
|
570
570
|
if (e.length > 200) {
|
|
@@ -584,24 +584,24 @@ function L(t = function() {
|
|
|
584
584
|
});
|
|
585
585
|
}
|
|
586
586
|
const n = function() {
|
|
587
|
-
|
|
587
|
+
I(), t();
|
|
588
588
|
}, o = g.shift();
|
|
589
589
|
return o ? ct(o, n) : t();
|
|
590
590
|
}
|
|
591
591
|
function Tt(t) {
|
|
592
|
-
Mt(t),
|
|
592
|
+
Mt(t), I();
|
|
593
593
|
}
|
|
594
594
|
function jt() {
|
|
595
595
|
return g = new b("requests"), z(window, "online", function() {
|
|
596
|
-
|
|
597
|
-
}),
|
|
596
|
+
I();
|
|
597
|
+
}), I(), g;
|
|
598
598
|
}
|
|
599
|
-
let
|
|
599
|
+
let L;
|
|
600
600
|
function ut() {
|
|
601
|
-
return
|
|
601
|
+
return L = p(), L;
|
|
602
602
|
}
|
|
603
603
|
function ft() {
|
|
604
|
-
return
|
|
604
|
+
return L || ut(), L;
|
|
605
605
|
}
|
|
606
606
|
function Jt(t, e = function() {
|
|
607
607
|
}) {
|
|
@@ -619,7 +619,7 @@ function Jt(t, e = function() {
|
|
|
619
619
|
device: {
|
|
620
620
|
spoor_session: n.id,
|
|
621
621
|
spoor_session_is_new: n.isNew,
|
|
622
|
-
spoor_id:
|
|
622
|
+
spoor_id: _t()
|
|
623
623
|
}
|
|
624
624
|
}, r = h("config") || {};
|
|
625
625
|
return r.context && m(o.context, r.context), r.user && m(o.user, r.user), r.device && m(o.device, r.device), m(o, t), P("Core.Track", o), Tt(o), o;
|
|
@@ -890,7 +890,7 @@ function dt(t) {
|
|
|
890
890
|
Zt(t, n, o)
|
|
891
891
|
)), r.push(s);
|
|
892
892
|
const u = re(c, a, t === n);
|
|
893
|
-
|
|
893
|
+
_(u, i), t = t.parentNode;
|
|
894
894
|
}
|
|
895
895
|
return { trace: r, customContext: i };
|
|
896
896
|
}
|
|
@@ -914,7 +914,7 @@ const ie = [
|
|
|
914
914
|
if (n.getAttribute("data-o-tracking-do-not-track") === "true")
|
|
915
915
|
return;
|
|
916
916
|
const o = se(e), { trace: r, customContext: i } = dt(n);
|
|
917
|
-
o.domPathTokens = r, o.url = window.document.location.href || null, o.source_id = x.getRootID(),
|
|
917
|
+
o.domPathTokens = r, o.url = window.document.location.href || null, o.source_id = x.getRootID(), _(i, o), t.context = o;
|
|
918
918
|
const a = m(h("config"), t);
|
|
919
919
|
x.track(a);
|
|
920
920
|
}, ce = (t, e) => {
|
|
@@ -950,7 +950,7 @@ const ue = {
|
|
|
950
950
|
i = At(a, fe);
|
|
951
951
|
} else
|
|
952
952
|
i = {};
|
|
953
|
-
i.domPathTokens = o, i.url = window.document.location.href || null,
|
|
953
|
+
i.domPathTokens = o, i.url = window.document.location.href || null, _(r, i), t.context = i;
|
|
954
954
|
}, de = (t = {}) => {
|
|
955
955
|
if (!window.IntersectionObserver) {
|
|
956
956
|
console.warn('o-tracking: Unable to track component view events as "window.IntersectionObserver" is not supported.');
|
|
@@ -992,7 +992,7 @@ function we(t = {}) {
|
|
|
992
992
|
return null;
|
|
993
993
|
C("version", W), C("source", pt), C("page_sent", !1);
|
|
994
994
|
const n = t ? t.cookieDomain : "";
|
|
995
|
-
return Pt("", n), mt(t),
|
|
995
|
+
return Pt("", n), mt(t), It(t.session), jt(), pe(), me(), k.initialised = !0, k;
|
|
996
996
|
}
|
|
997
997
|
function gt() {
|
|
998
998
|
return document.querySelector("script[data-o-tracking-config]");
|
|
@@ -1092,21 +1092,22 @@ function Se(t, e) {
|
|
|
1092
1092
|
Ee(t, n, o)
|
|
1093
1093
|
)), r.push(s);
|
|
1094
1094
|
const u = Ce(c, a, t === n);
|
|
1095
|
-
|
|
1095
|
+
_(u, i), t = t.parentNode;
|
|
1096
1096
|
}
|
|
1097
1097
|
return { trace: r, customContext: i };
|
|
1098
1098
|
}
|
|
1099
1099
|
const Ae = ["ctrlKey", "altKey", "shiftKey", "metaKey"];
|
|
1100
1100
|
class Pe {
|
|
1101
1101
|
constructor({
|
|
1102
|
-
id: e = "
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1102
|
+
id: e = "00000000-0000-0000-0000-000000000000",
|
|
1103
|
+
name: n = "ccc-component",
|
|
1104
|
+
subtype: o = "interactive",
|
|
1105
|
+
teamName: r = "djd",
|
|
1106
|
+
shadowRoot: i = null,
|
|
1107
|
+
category: a = "cta",
|
|
1108
|
+
elements: c = 'a, button, input, [role="button"]'
|
|
1108
1109
|
} = {}) {
|
|
1109
|
-
this.
|
|
1110
|
+
this.cccId = e, this.cccName = n, this.subtype = o, this.teamName = r, this.shadowRoot = i, this.category = a, this.elements = c, this.isInitialised = !1;
|
|
1110
1111
|
}
|
|
1111
1112
|
// Get properties for the event (as opposed to properties of the clicked element)
|
|
1112
1113
|
getEventProperties(e) {
|
|
@@ -1125,11 +1126,11 @@ class Pe {
|
|
|
1125
1126
|
return (o, r) => {
|
|
1126
1127
|
const i = this.getEventProperties(o), { trace: a, customContext: c } = Se(r, n);
|
|
1127
1128
|
i.custom = r.dataset && r.dataset.custom ? JSON.parse(r.dataset.custom) : null, i.domPathTokens = a, i.component = {
|
|
1128
|
-
id: this.
|
|
1129
|
+
id: this.cccId,
|
|
1129
1130
|
name: this.cccName,
|
|
1130
1131
|
type: "custom-code-component",
|
|
1131
1132
|
subtype: this.subtype
|
|
1132
|
-
}, i.teamName = this.teamName,
|
|
1133
|
+
}, i.teamName = this.teamName, _(c, i), e.context = i, e.method = "ftCustomAnalytics", document.body.dispatchEvent(
|
|
1133
1134
|
new CustomEvent("oTracking.event", {
|
|
1134
1135
|
detail: e,
|
|
1135
1136
|
bubbles: !0,
|
|
@@ -1144,7 +1145,7 @@ class Pe {
|
|
|
1144
1145
|
action: "act",
|
|
1145
1146
|
context: {
|
|
1146
1147
|
component: {
|
|
1147
|
-
id: this.
|
|
1148
|
+
id: this.cccId,
|
|
1148
1149
|
name: this.cccName,
|
|
1149
1150
|
type: "custom-code-component",
|
|
1150
1151
|
subtype: this.subtype
|
|
@@ -1163,24 +1164,24 @@ class Pe {
|
|
|
1163
1164
|
})
|
|
1164
1165
|
);
|
|
1165
1166
|
}
|
|
1166
|
-
init() {
|
|
1167
|
-
var
|
|
1167
|
+
init(e) {
|
|
1168
|
+
var n;
|
|
1168
1169
|
if (!this.isInitialised) {
|
|
1169
|
-
this.isInitialised = !0, k.init({ queue: !0, test: !0 });
|
|
1170
|
-
const
|
|
1170
|
+
this.isInitialised = !0, this.cccId = e || this.cccId, k.init({ queue: !0, test: !0 });
|
|
1171
|
+
const o = {
|
|
1171
1172
|
action: "click",
|
|
1172
1173
|
category: this.category
|
|
1173
|
-
},
|
|
1174
|
-
this.shadowRoot && new w(
|
|
1174
|
+
}, r = (n = this.shadowRoot) == null ? void 0 : n.querySelector("#component-root");
|
|
1175
|
+
this.shadowRoot && new w(r).on(
|
|
1175
1176
|
"click",
|
|
1176
1177
|
this.elements,
|
|
1177
|
-
this.handleClickEvent(
|
|
1178
|
+
this.handleClickEvent(o, r),
|
|
1178
1179
|
!0
|
|
1179
1180
|
);
|
|
1180
1181
|
}
|
|
1181
1182
|
}
|
|
1182
1183
|
}
|
|
1183
|
-
class
|
|
1184
|
+
class _e extends HTMLElement {
|
|
1184
1185
|
constructor() {
|
|
1185
1186
|
super(...arguments), this.RESERVED_ATTRS = /* @__PURE__ */ new Set([
|
|
1186
1187
|
"iframe",
|
|
@@ -1202,7 +1203,7 @@ class Ne extends HTMLElement {
|
|
|
1202
1203
|
[...this.attributes].filter((s) => !this.RESERVED_ATTRS.has(s.name)).map((s) => [s.name, s.value])
|
|
1203
1204
|
);
|
|
1204
1205
|
(c = this.shadowRoot) == null || c.replaceChildren(), this.tracking = new Pe({
|
|
1205
|
-
|
|
1206
|
+
name: `${this.getAttribute("path")}@${this.getAttribute("version")}`,
|
|
1206
1207
|
subtype: "interactive",
|
|
1207
1208
|
teamName: "djd",
|
|
1208
1209
|
shadowRoot: this.shadowRoot
|
|
@@ -1279,7 +1280,7 @@ class Ne extends HTMLElement {
|
|
|
1279
1280
|
), console.error(u), this.dispatchEvent(new ErrorEvent("error", u)), this.dataset.cccError = "mount-error", delete this.dataset.cccReady;
|
|
1280
1281
|
}
|
|
1281
1282
|
try {
|
|
1282
|
-
this.tracking.init();
|
|
1283
|
+
this.tracking.init(this.id);
|
|
1283
1284
|
} catch (u) {
|
|
1284
1285
|
console.info(
|
|
1285
1286
|
`Error initialising tracking on <custom-code-component> ${e}@${n}`
|
|
@@ -1298,13 +1299,13 @@ class Ne extends HTMLElement {
|
|
|
1298
1299
|
this.channel.port1.postMessage(e);
|
|
1299
1300
|
}
|
|
1300
1301
|
}
|
|
1301
|
-
const
|
|
1302
|
-
customElements && !customElements.get("custom-code-component") &&
|
|
1302
|
+
const Ne = () => customElements.define("custom-code-component", _e);
|
|
1303
|
+
customElements && !customElements.get("custom-code-component") && Ne();
|
|
1303
1304
|
class D extends Error {
|
|
1304
1305
|
constructor(...e) {
|
|
1305
1306
|
super(...e), Error.captureStackTrace && Error.captureStackTrace(this, D), this.name = "CCCImportError";
|
|
1306
1307
|
}
|
|
1307
1308
|
}
|
|
1308
1309
|
export {
|
|
1309
|
-
|
|
1310
|
+
Ne as init
|
|
1310
1311
|
};
|
package/dist/tracking.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
declare class Tracking {
|
|
2
|
+
cccId: string;
|
|
2
3
|
cccName: string;
|
|
3
4
|
subtype: string;
|
|
4
5
|
teamName: string;
|
|
@@ -6,8 +7,9 @@ declare class Tracking {
|
|
|
6
7
|
category: string;
|
|
7
8
|
elements: string | string[];
|
|
8
9
|
isInitialised: boolean;
|
|
9
|
-
constructor({ id, subtype, teamName, shadowRoot, category, elements, }?: {
|
|
10
|
+
constructor({ id, name, subtype, teamName, shadowRoot, category, elements, }?: {
|
|
10
11
|
id?: string;
|
|
12
|
+
name?: string;
|
|
11
13
|
subtype?: string;
|
|
12
14
|
teamName?: string;
|
|
13
15
|
shadowRoot?: any;
|
|
@@ -17,6 +19,6 @@ declare class Tracking {
|
|
|
17
19
|
getEventProperties(event: any): {};
|
|
18
20
|
handleClickEvent(eventData: any, root: any): (clickEvent: any, clickElement: any) => void;
|
|
19
21
|
sendSpoorEvent(triggerAction: any, extraDetail: any): void;
|
|
20
|
-
init(): void;
|
|
22
|
+
init(id: any): void;
|
|
21
23
|
}
|
|
22
24
|
export default Tracking;
|
package/package.json
CHANGED
|
@@ -48,7 +48,7 @@ class FTCustomCodeComponent extends HTMLElement {
|
|
|
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
54
|
shadowRoot: this.shadowRoot as ShadowRoot,
|
|
@@ -171,7 +171,7 @@ class FTCustomCodeComponent extends HTMLElement {
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
try {
|
|
174
|
-
this.tracking.init();
|
|
174
|
+
this.tracking.init(this.id);
|
|
175
175
|
} catch (e) {
|
|
176
176
|
console.info(
|
|
177
177
|
`Error initialising tracking on <custom-code-component> ${path}@${componentVersionRange}`
|
package/src/tracking.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
const eventPropertiesToCollect = ["ctrlKey", "altKey", "shiftKey", "metaKey"];
|
|
10
10
|
|
|
11
11
|
class Tracking {
|
|
12
|
+
cccId: string;
|
|
12
13
|
cccName: string;
|
|
13
14
|
subtype: string;
|
|
14
15
|
teamName: string;
|
|
@@ -18,14 +19,16 @@ class Tracking {
|
|
|
18
19
|
isInitialised: boolean;
|
|
19
20
|
|
|
20
21
|
constructor({
|
|
21
|
-
id = "
|
|
22
|
+
id = "00000000-0000-0000-0000-000000000000",
|
|
23
|
+
name = "ccc-component",
|
|
22
24
|
subtype = "interactive",
|
|
23
25
|
teamName = "djd",
|
|
24
26
|
shadowRoot = null,
|
|
25
27
|
category = "cta",
|
|
26
28
|
elements = 'a, button, input, [role="button"]',
|
|
27
29
|
} = {}) {
|
|
28
|
-
this.
|
|
30
|
+
this.cccId = id;
|
|
31
|
+
this.cccName = name;
|
|
29
32
|
this.subtype = subtype;
|
|
30
33
|
this.teamName = teamName;
|
|
31
34
|
this.shadowRoot = shadowRoot;
|
|
@@ -60,7 +63,7 @@ class Tracking {
|
|
|
60
63
|
: null;
|
|
61
64
|
context.domPathTokens = trace;
|
|
62
65
|
context.component = {
|
|
63
|
-
id: this.
|
|
66
|
+
id: this.cccId,
|
|
64
67
|
name: this.cccName,
|
|
65
68
|
type: "custom-code-component",
|
|
66
69
|
subtype: this.subtype,
|
|
@@ -89,7 +92,7 @@ class Tracking {
|
|
|
89
92
|
action: "act",
|
|
90
93
|
context: {
|
|
91
94
|
component: {
|
|
92
|
-
id: this.
|
|
95
|
+
id: this.cccId,
|
|
93
96
|
name: this.cccName,
|
|
94
97
|
type: "custom-code-component",
|
|
95
98
|
subtype: this.subtype,
|
|
@@ -111,9 +114,10 @@ class Tracking {
|
|
|
111
114
|
);
|
|
112
115
|
}
|
|
113
116
|
|
|
114
|
-
init() {
|
|
117
|
+
init(id) {
|
|
115
118
|
if (!this.isInitialised) {
|
|
116
119
|
this.isInitialised = true;
|
|
120
|
+
this.cccId = id ? id : this.cccId;
|
|
117
121
|
|
|
118
122
|
oTracking.init({ queue: true, test: true }); // @TODO: Flip this to false before using in production
|
|
119
123
|
|