@financial-times/custom-code-component 1.10.5 → 1.11.1

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.
@@ -145,7 +145,7 @@ const k = (o, t, e) => {
145
145
  (e) => e.name.match(/^data-trackable|^data-o-|^aria-/i)
146
146
  ).forEach((e) => {
147
147
  t[e.name] = e.value;
148
- }), t), x = (o, t, e) => {
148
+ }), t), C = (o, t, e) => {
149
149
  const n = {};
150
150
  return e && E.forEach((s) => {
151
151
  typeof t[s] < "u" && s !== "id" && (n[s] = t[s]);
@@ -153,7 +153,7 @@ const k = (o, t, e) => {
153
153
  n[s.name.replace("data-trackable-context-", "")] = P(s.value);
154
154
  }), n;
155
155
  };
156
- function C(o, t) {
156
+ function L(o, t) {
157
157
  const e = o, n = e.getAttribute("data-trackable") ? `[data-trackable="${e.getAttribute("data-trackable")}"]` : e.nodeName, s = [], i = {};
158
158
  for (; o && o !== t; ) {
159
159
  const a = A(o), r = Array.from(o.attributes);
@@ -162,12 +162,12 @@ function C(o, t) {
162
162
  h,
163
163
  k(o, e, n)
164
164
  )), s.push(h);
165
- const c = x(r, a, o === e);
165
+ const c = C(r, a, o === e);
166
166
  b(c, i), o = o.parentNode;
167
167
  }
168
168
  return { trace: s, customContext: i };
169
169
  }
170
- const L = ["ctrlKey", "altKey", "shiftKey", "metaKey"];
170
+ const x = ["ctrlKey", "altKey", "shiftKey", "metaKey"];
171
171
  class M {
172
172
  constructor({
173
173
  id: t = "00000000-0000-0000-0000-000000000000",
@@ -183,7 +183,7 @@ class M {
183
183
  // Get properties for the event (as opposed to properties of the clicked element)
184
184
  getEventProperties(t) {
185
185
  const e = {};
186
- for (const n of L)
186
+ for (const n of x)
187
187
  if (t[n])
188
188
  try {
189
189
  e[n] = g(t[n]);
@@ -195,13 +195,13 @@ class M {
195
195
  // Controller for handling click events
196
196
  handleClickEvent(t, e) {
197
197
  return (n, s) => {
198
- const i = this.getEventProperties(n), { trace: a, customContext: r } = C(s, e);
198
+ const i = this.getEventProperties(n), { trace: a, customContext: r } = L(s, e);
199
199
  i.custom = s.dataset && s.dataset.custom ? JSON.parse(s.dataset.custom) : null, i.domPathTokens = a, i.component = {
200
200
  id: this.cccId,
201
201
  name: this.cccName,
202
202
  type: "custom-code-component",
203
203
  subtype: this.subtype
204
- }, i.teamName = this.teamName, b(r, i), t.context = i, t.method = "ftCustomAnalytics", document.body.dispatchEvent(
204
+ }, i.teamName = this.teamName, i.url = document.URL, b(r, i), i.method = "ftCustomAnalytics", t = { ...t, ...i }, document.body.dispatchEvent(
205
205
  new CustomEvent("oTracking.event", {
206
206
  detail: t,
207
207
  bubbles: !0,
@@ -214,17 +214,15 @@ class M {
214
214
  const n = {
215
215
  category: "component",
216
216
  action: "act",
217
- context: {
218
- component: {
219
- id: this.cccId,
220
- name: this.cccName,
221
- type: "custom-code-component",
222
- subtype: this.subtype
223
- },
224
- teamName: this.teamName,
225
- trigger_action: t,
226
- custom: e
217
+ component: {
218
+ id: this.cccId,
219
+ name: this.cccName,
220
+ type: "custom-code-component",
221
+ subtype: this.subtype
227
222
  },
223
+ teamName: this.teamName,
224
+ trigger_action: t,
225
+ custom: e,
228
226
  method: "ftCustomAnalytics"
229
227
  };
230
228
  document.body.dispatchEvent(
@@ -252,7 +250,7 @@ class M {
252
250
  }
253
251
  }
254
252
  }
255
- class O extends HTMLElement {
253
+ class R extends HTMLElement {
256
254
  constructor() {
257
255
  super(...arguments), this.RESERVED_ATTRS = /* @__PURE__ */ new Set([
258
256
  "iframe",
@@ -370,13 +368,13 @@ class O extends HTMLElement {
370
368
  this.channel.port1.postMessage(t);
371
369
  }
372
370
  }
373
- const R = () => customElements.define("custom-code-component", O);
374
- customElements && !customElements.get("custom-code-component") && R();
371
+ const O = () => customElements.define("custom-code-component", R);
372
+ customElements && !customElements.get("custom-code-component") && O();
375
373
  class f extends Error {
376
374
  constructor(...t) {
377
375
  super(...t), Error.captureStackTrace && Error.captureStackTrace(this, f), this.name = "CCCImportError";
378
376
  }
379
377
  }
380
378
  export {
381
- R as init
379
+ O as init
382
380
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/custom-code-component",
3
- "version": "1.10.5",
3
+ "version": "1.11.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
package/src/tracking.ts CHANGED
@@ -76,11 +76,12 @@ class Tracking {
76
76
  subtype: this.subtype,
77
77
  };
78
78
  context.teamName = this.teamName;
79
+ context.url = document.URL;
79
80
 
80
81
  assignIfUndefined(customContext, context);
81
82
 
82
- eventData.context = context;
83
- eventData.method = "ftCustomAnalytics";
83
+ context.method = "ftCustomAnalytics";
84
+ eventData = { ...eventData, ...context };
84
85
 
85
86
  // send spoor event
86
87
  document.body.dispatchEvent(
@@ -97,17 +98,15 @@ class Tracking {
97
98
  const eventData = {
98
99
  category: "component",
99
100
  action: "act",
100
- context: {
101
- component: {
102
- id: this.cccId,
103
- name: this.cccName,
104
- type: "custom-code-component",
105
- subtype: this.subtype,
106
- },
107
- teamName: this.teamName,
108
- trigger_action: triggerAction,
109
- custom: extraDetail,
101
+ component: {
102
+ id: this.cccId,
103
+ name: this.cccName,
104
+ type: "custom-code-component",
105
+ subtype: this.subtype,
110
106
  },
107
+ teamName: this.teamName,
108
+ trigger_action: triggerAction,
109
+ custom: extraDetail,
111
110
  method: "ftCustomAnalytics",
112
111
  };
113
112
 
@@ -135,7 +134,6 @@ class Tracking {
135
134
 
136
135
  if (this.shadowRoot) {
137
136
  const shadowDelegate = new Delegate(root);
138
-
139
137
  shadowDelegate.on(
140
138
  "click",
141
139
  this.elements,