@vouchfor/embeds 0.0.0-experiment.4eb5f06 → 0.0.0-experiment.526750e
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/es/components/Embed/controllers/tracking.d.ts +2 -1
- package/dist/es/embeds.js +53 -55
- package/dist/es/embeds.js.map +1 -1
- package/dist/iife/embeds.iife.js +38 -38
- package/dist/iife/embeds.iife.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Embed/controllers/fetcher.ts +2 -2
- package/src/components/Embed/controllers/tracking.ts +37 -50
@@ -9,8 +9,9 @@ declare class TrackingController implements ReactiveController {
|
|
9
9
|
private _hasPlayed;
|
10
10
|
private _hasLoaded;
|
11
11
|
private _answersViewed;
|
12
|
-
private
|
12
|
+
private _streamStartTime;
|
13
13
|
private _streamLatestTime;
|
14
|
+
private _currentlyPlayingVideo;
|
14
15
|
constructor(host: EmbedHost);
|
15
16
|
private _findVouchId;
|
16
17
|
private _createVisitor;
|
package/dist/es/embeds.js
CHANGED
@@ -78,7 +78,7 @@ const { is: pe, defineProperty: ue, getOwnPropertyDescriptor: _e, getOwnProperty
|
|
78
78
|
return e;
|
79
79
|
} }, qt = (r, t) => !pe(r, t), At = { attribute: !0, type: String, converter: dt, reflect: !1, hasChanged: qt };
|
80
80
|
Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), E.litPropertyMetadata ?? (E.litPropertyMetadata = /* @__PURE__ */ new WeakMap());
|
81
|
-
let
|
81
|
+
let L = class extends HTMLElement {
|
82
82
|
static addInitializer(t) {
|
83
83
|
this._$Ei(), (this.l ?? (this.l = [])).push(t);
|
84
84
|
}
|
@@ -289,14 +289,14 @@ let M = class extends HTMLElement {
|
|
289
289
|
firstUpdated(t) {
|
290
290
|
}
|
291
291
|
};
|
292
|
-
|
292
|
+
L.elementStyles = [], L.shadowRootOptions = { mode: "open" }, L[I("elementProperties")] = /* @__PURE__ */ new Map(), L[I("finalized")] = /* @__PURE__ */ new Map(), rt == null || rt({ ReactiveElement: L }), (E.reactiveElementVersions ?? (E.reactiveElementVersions = [])).push("2.0.2");
|
293
293
|
/**
|
294
294
|
* @license
|
295
295
|
* Copyright 2017 Google LLC
|
296
296
|
* SPDX-License-Identifier: BSD-3-Clause
|
297
297
|
*/
|
298
298
|
const V = globalThis, Y = V.trustedTypes, Et = Y ? Y.createPolicy("lit-html", { createHTML: (r) => r }) : void 0, Xt = "$lit$", y = `lit$${(Math.random() + "").slice(9)}$`, Kt = "?" + y, ve = `<${Kt}>`, U = document, Q = () => U.createComment(""), B = (r) => r === null || typeof r != "object" && typeof r != "function", Jt = Array.isArray, ye = (r) => Jt(r) || typeof (r == null ? void 0 : r[Symbol.iterator]) == "function", nt = `[
|
299
|
-
\f\r]`,
|
299
|
+
\f\r]`, M = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, St = /-->/g, bt = />/g, b = RegExp(`>|${nt}(?:([^\\s"'>=/]+)(${nt}*=${nt}*(?:[^
|
300
300
|
\f\r"'\`<>=]|("|')|))|$)`, "g"), wt = /'/g, Pt = /"/g, Ft = /^(?:script|style|textarea|title)$/i, W = Symbol.for("lit-noChange"), _ = Symbol.for("lit-nothing"), Ct = /* @__PURE__ */ new WeakMap(), C = U.createTreeWalker(U, 129);
|
301
301
|
function Gt(r, t) {
|
302
302
|
if (!Array.isArray(r) || !r.hasOwnProperty("raw"))
|
@@ -305,14 +305,14 @@ function Gt(r, t) {
|
|
305
305
|
}
|
306
306
|
const Ae = (r, t) => {
|
307
307
|
const e = r.length - 1, i = [];
|
308
|
-
let s, n = t === 2 ? "<svg>" : "", o =
|
308
|
+
let s, n = t === 2 ? "<svg>" : "", o = M;
|
309
309
|
for (let a = 0; a < e; a++) {
|
310
310
|
const h = r[a];
|
311
311
|
let c, d, l = -1, p = 0;
|
312
312
|
for (; p < h.length && (o.lastIndex = p, d = o.exec(h), d !== null); )
|
313
|
-
p = o.lastIndex, o ===
|
314
|
-
const u = o ===
|
315
|
-
n += o ===
|
313
|
+
p = o.lastIndex, o === M ? d[1] === "!--" ? o = St : d[1] !== void 0 ? o = bt : d[2] !== void 0 ? (Ft.test(d[2]) && (s = RegExp("</" + d[2], "g")), o = b) : d[3] !== void 0 && (o = b) : o === b ? d[0] === ">" ? (o = s ?? M, l = -1) : d[1] === void 0 ? l = -2 : (l = o.lastIndex - d[2].length, c = d[1], o = d[3] === void 0 ? b : d[3] === '"' ? Pt : wt) : o === Pt || o === wt ? o = b : o === St || o === bt ? o = M : (o = b, s = void 0);
|
314
|
+
const u = o === b && r[a + 1].startsWith("/>") ? " " : "";
|
315
|
+
n += o === M ? h + ve : l >= 0 ? (i.push(c), h.slice(0, l) + Xt + h.slice(l) + y + u) : h + y + (l === -2 ? a : u);
|
316
316
|
}
|
317
317
|
return [Gt(r, n + (r[e] || "<?>") + (t === 2 ? "</svg>" : "")), i];
|
318
318
|
};
|
@@ -332,7 +332,7 @@ let pt = class Zt {
|
|
332
332
|
for (const l of s.getAttributeNames())
|
333
333
|
if (l.endsWith(Xt)) {
|
334
334
|
const p = d[o++], u = s.getAttribute(l).split(y), g = /([.?@])?(.*)/.exec(p);
|
335
|
-
h.push({ type: 1, index: n, name: g[2], strings: u, ctor: g[1] === "." ?
|
335
|
+
h.push({ type: 1, index: n, name: g[2], strings: u, ctor: g[1] === "." ? Se : g[1] === "?" ? be : g[1] === "@" ? we : it }), s.removeAttribute(l);
|
336
336
|
} else
|
337
337
|
l.startsWith(y) && (h.push({ type: 6, index: n }), s.removeAttribute(l));
|
338
338
|
if (Ft.test(s.tagName)) {
|
@@ -486,14 +486,14 @@ let Ee = class {
|
|
486
486
|
O(t) {
|
487
487
|
t === _ ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, t ?? "");
|
488
488
|
}
|
489
|
-
},
|
489
|
+
}, Se = class extends it {
|
490
490
|
constructor() {
|
491
491
|
super(...arguments), this.type = 3;
|
492
492
|
}
|
493
493
|
O(t) {
|
494
494
|
this.element[this.name] = t === _ ? void 0 : t;
|
495
495
|
}
|
496
|
-
},
|
496
|
+
}, be = class extends it {
|
497
497
|
constructor() {
|
498
498
|
super(...arguments), this.type = 4;
|
499
499
|
}
|
@@ -571,10 +571,10 @@ const Te = (r) => new Ce(typeof r == "string" ? r : r + "", void 0, te), Ue = (r
|
|
571
571
|
* Copyright 2017 Google LLC
|
572
572
|
* SPDX-License-Identifier: BSD-3-Clause
|
573
573
|
*/
|
574
|
-
const { is: Re, defineProperty: xe, getOwnPropertyDescriptor: He, getOwnPropertyNames: Oe, getOwnPropertySymbols: Ne, getPrototypeOf:
|
574
|
+
const { is: Re, defineProperty: xe, getOwnPropertyDescriptor: He, getOwnPropertyNames: Oe, getOwnPropertySymbols: Ne, getPrototypeOf: Le } = Object, S = globalThis, Rt = S.trustedTypes, Me = Rt ? Rt.emptyScript : "", ht = S.reactiveElementPolyfillSupport, D = (r, t) => r, ut = { toAttribute(r, t) {
|
575
575
|
switch (t) {
|
576
576
|
case Boolean:
|
577
|
-
r = r ?
|
577
|
+
r = r ? Me : null;
|
578
578
|
break;
|
579
579
|
case Object:
|
580
580
|
case Array:
|
@@ -600,7 +600,7 @@ const { is: Re, defineProperty: xe, getOwnPropertyDescriptor: He, getOwnProperty
|
|
600
600
|
}
|
601
601
|
return e;
|
602
602
|
} }, ee = (r, t) => !Re(r, t), xt = { attribute: !0, type: String, converter: ut, reflect: !1, hasChanged: ee };
|
603
|
-
Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")),
|
603
|
+
Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), S.litPropertyMetadata ?? (S.litPropertyMetadata = /* @__PURE__ */ new WeakMap());
|
604
604
|
class x extends HTMLElement {
|
605
605
|
static addInitializer(t) {
|
606
606
|
this._$Ei(), (this.l ?? (this.l = [])).push(t);
|
@@ -633,7 +633,7 @@ class x extends HTMLElement {
|
|
633
633
|
static _$Ei() {
|
634
634
|
if (this.hasOwnProperty(D("elementProperties")))
|
635
635
|
return;
|
636
|
-
const t =
|
636
|
+
const t = Le(this);
|
637
637
|
t.finalize(), t.l !== void 0 && (this.l = [...t.l]), this.elementProperties = new Map(t.elementProperties);
|
638
638
|
}
|
639
639
|
static finalize() {
|
@@ -812,7 +812,7 @@ class x extends HTMLElement {
|
|
812
812
|
firstUpdated(t) {
|
813
813
|
}
|
814
814
|
}
|
815
|
-
x.elementStyles = [], x.shadowRootOptions = { mode: "open" }, x[D("elementProperties")] = /* @__PURE__ */ new Map(), x[D("finalized")] = /* @__PURE__ */ new Map(), ht == null || ht({ ReactiveElement: x }), (
|
815
|
+
x.elementStyles = [], x.shadowRootOptions = { mode: "open" }, x[D("elementProperties")] = /* @__PURE__ */ new Map(), x[D("finalized")] = /* @__PURE__ */ new Map(), ht == null || ht({ ReactiveElement: x }), (S.reactiveElementVersions ?? (S.reactiveElementVersions = [])).push("2.0.2");
|
816
816
|
/**
|
817
817
|
* @license
|
818
818
|
* Copyright 2017 Google LLC
|
@@ -820,7 +820,7 @@ x.elementStyles = [], x.shadowRootOptions = { mode: "open" }, x[D("elementProper
|
|
820
820
|
*/
|
821
821
|
const z = globalThis, tt = z.trustedTypes, Ht = tt ? tt.createPolicy("lit-html", { createHTML: (r) => r }) : void 0, ie = "$lit$", A = `lit$${(Math.random() + "").slice(9)}$`, se = "?" + A, ke = `<${se}>`, R = document, q = () => R.createComment(""), X = (r) => r === null || typeof r != "object" && typeof r != "function", re = Array.isArray, Ie = (r) => re(r) || typeof (r == null ? void 0 : r[Symbol.iterator]) == "function", at = `[
|
822
822
|
\f\r]`, k = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, Ot = /-->/g, Nt = />/g, w = RegExp(`>|${at}(?:([^\\s"'>=/]+)(${at}*=${at}*(?:[^
|
823
|
-
\f\r"'\`<>=]|("|')|))|$)`, "g"),
|
823
|
+
\f\r"'\`<>=]|("|')|))|$)`, "g"), Lt = /'/g, Mt = /"/g, ne = /^(?:script|style|textarea|title)$/i, Ve = (r) => (t, ...e) => ({ _$litType$: r, strings: t, values: e }), De = Ve(1), O = Symbol.for("lit-noChange"), $ = Symbol.for("lit-nothing"), kt = /* @__PURE__ */ new WeakMap(), T = R.createTreeWalker(R, 129);
|
824
824
|
function oe(r, t) {
|
825
825
|
if (!Array.isArray(r) || !r.hasOwnProperty("raw"))
|
826
826
|
throw Error("invalid template strings array");
|
@@ -833,7 +833,7 @@ const ze = (r, t) => {
|
|
833
833
|
const h = r[a];
|
834
834
|
let c, d, l = -1, p = 0;
|
835
835
|
for (; p < h.length && (o.lastIndex = p, d = o.exec(h), d !== null); )
|
836
|
-
p = o.lastIndex, o === k ? d[1] === "!--" ? o = Ot : d[1] !== void 0 ? o = Nt : d[2] !== void 0 ? (ne.test(d[2]) && (s = RegExp("</" + d[2], "g")), o = w) : d[3] !== void 0 && (o = w) : o === w ? d[0] === ">" ? (o = s ?? k, l = -1) : d[1] === void 0 ? l = -2 : (l = o.lastIndex - d[2].length, c = d[1], o = d[3] === void 0 ? w : d[3] === '"' ?
|
836
|
+
p = o.lastIndex, o === k ? d[1] === "!--" ? o = Ot : d[1] !== void 0 ? o = Nt : d[2] !== void 0 ? (ne.test(d[2]) && (s = RegExp("</" + d[2], "g")), o = w) : d[3] !== void 0 && (o = w) : o === w ? d[0] === ">" ? (o = s ?? k, l = -1) : d[1] === void 0 ? l = -2 : (l = o.lastIndex - d[2].length, c = d[1], o = d[3] === void 0 ? w : d[3] === '"' ? Mt : Lt) : o === Mt || o === Lt ? o = w : o === Ot || o === Nt ? o = k : (o = w, s = void 0);
|
837
837
|
const u = o === w && r[a + 1].startsWith("/>") ? " " : "";
|
838
838
|
n += o === k ? h + ke : l >= 0 ? (i.push(c), h.slice(0, l) + ie + h.slice(l) + A + u) : h + A + (l === -2 ? a : u);
|
839
839
|
}
|
@@ -1168,9 +1168,7 @@ class ri {
|
|
1168
1168
|
["X-Cache-Check", o]
|
1169
1169
|
]
|
1170
1170
|
}), h = await a.json();
|
1171
|
-
this.host.dispatchEvent(new CustomEvent("vouch:loaded", { detail: s }))
|
1172
|
-
const c = (d = a == null ? void 0 : a.headers) == null ? void 0 : d.get("X-Cache-Check");
|
1173
|
-
return c && c !== o && fetch(`${n}/vouches/${s}`, {
|
1171
|
+
return this.host.dispatchEvent(new CustomEvent("vouch:loaded", { detail: s })), ((d = a == null ? void 0 : a.headers) == null ? void 0 : d.get("X-Cache-Check")) !== o && fetch(`${n}/vouches/${s}`, {
|
1174
1172
|
method: "GET",
|
1175
1173
|
headers: [
|
1176
1174
|
["X-Api-Key", i],
|
@@ -1185,8 +1183,8 @@ class ri {
|
|
1185
1183
|
["X-Api-Key", i],
|
1186
1184
|
["X-Cache-Check", o]
|
1187
1185
|
]
|
1188
|
-
}), h = await a.json()
|
1189
|
-
return
|
1186
|
+
}), h = await a.json();
|
1187
|
+
return ((d = a == null ? void 0 : a.headers) == null ? void 0 : d.get("X-Cache-Check")) !== o && fetch(`${n}/templates/${s}`, {
|
1190
1188
|
method: "GET",
|
1191
1189
|
headers: [
|
1192
1190
|
["X-Api-Key", i],
|
@@ -1226,7 +1224,7 @@ class ri {
|
|
1226
1224
|
const ni = 10;
|
1227
1225
|
class oi {
|
1228
1226
|
constructor(t) {
|
1229
|
-
this._tabId = void 0, this._clientId = void 0, this._visitorId = void 0, this._hasPlayed = !1, this._hasLoaded = {}, this._answersViewed = {}, this.
|
1227
|
+
this._tabId = void 0, this._clientId = void 0, this._visitorId = void 0, this._hasPlayed = !1, this._hasLoaded = {}, this._answersViewed = {}, this._streamStartTime = {}, this._streamLatestTime = {}, this._currentlyPlayingVideo = null, this._createVisitor = (e) => {
|
1230
1228
|
var s, n;
|
1231
1229
|
const { publicApiUrl: i } = et(this.host.env);
|
1232
1230
|
return (n = (s = window.localStorage) == null ? void 0 : s.setItem) == null || n.call(s, "vouch-uid-visitor", e), navigator.sendBeacon(`${i}/api/visitor`, JSON.stringify({ visitorId: e })), e;
|
@@ -1250,56 +1248,48 @@ class oi {
|
|
1250
1248
|
...s
|
1251
1249
|
};
|
1252
1250
|
}, this._sendTrackingEvent = (e, i) => {
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1251
|
+
if (!this._findVouchId() || this.host.disableTracking)
|
1252
|
+
return;
|
1253
|
+
const { publicApiUrl: n } = et(this.host.env), { client: o, tab: a, request: h, visitor: c } = this._getUids();
|
1254
|
+
navigator.sendBeacon(
|
1255
|
+
`${n}/api/events`,
|
1256
1256
|
JSON.stringify({
|
1257
1257
|
event: e,
|
1258
1258
|
payload: i,
|
1259
1259
|
context: {
|
1260
|
-
"x-uid-client":
|
1261
|
-
"x-uid-tab":
|
1262
|
-
"x-uid-request":
|
1263
|
-
"x-uid-visitor":
|
1260
|
+
"x-uid-client": o,
|
1261
|
+
"x-uid-tab": a,
|
1262
|
+
"x-uid-request": h,
|
1263
|
+
"x-uid-visitor": c,
|
1264
1264
|
"x-reporting-metadata": this._getReportingMetadata()
|
1265
1265
|
}
|
1266
1266
|
})
|
1267
1267
|
);
|
1268
1268
|
}, this._handleVouchLoaded = ({ detail: e }) => {
|
1269
|
-
e && (this._hasLoaded[e] || (this._sendTrackingEvent("VOUCH_LOADED",
|
1270
|
-
vouchId: e
|
1271
|
-
}), this._hasLoaded[e] = !0));
|
1269
|
+
e && (this._hasLoaded[e] || (this._sendTrackingEvent("VOUCH_LOADED"), this._hasLoaded[e] = !0));
|
1272
1270
|
}, this._handlePlay = () => {
|
1273
|
-
|
1274
|
-
e && (this._hasPlayed || (this._sendTrackingEvent("VIDEO_PLAYED", {
|
1275
|
-
vouchId: e,
|
1271
|
+
this._hasPlayed || (this._sendTrackingEvent("VIDEO_PLAYED", {
|
1276
1272
|
streamStart: this.host.currentTime
|
1277
|
-
}), this._hasPlayed = !0)
|
1273
|
+
}), this._hasPlayed = !0);
|
1278
1274
|
}, this._handleVideoPlay = ({ detail: { id: e, key: i, node: s } }) => {
|
1279
|
-
|
1280
|
-
n && (this._answersViewed[i] || (this._sendTrackingEvent("VOUCH_RESPONSE_VIEWED", {
|
1281
|
-
vouchId: n,
|
1275
|
+
this._answersViewed[i] || (this._sendTrackingEvent("VOUCH_RESPONSE_VIEWED", {
|
1282
1276
|
answerId: e
|
1283
|
-
}), this._answersViewed[i] = !0), this.
|
1277
|
+
}), this._answersViewed[i] = !0), this._streamStartTime[i] = s.currentTime, this._streamLatestTime[i] = s.currentTime;
|
1284
1278
|
}, this._handleVideoTimeUpdate = ({ detail: { id: e, key: i, node: s } }) => {
|
1285
|
-
var
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
s.currentTime - this._streamedTime[i] > ni && (this._sendTrackingEvent("VIDEO_STREAMED", {
|
1290
|
-
vouchId: n,
|
1279
|
+
var n, o;
|
1280
|
+
this.host.paused || (this._currentlyPlayingVideo = { id: e, key: i, node: s }, this._streamLatestTime[i] = s.currentTime), !s.paused && !this.host.paused && // Only fire the video seeked event when this video is the active one
|
1281
|
+
e === ((o = (n = this.host.scene) == null ? void 0 : n.video) == null ? void 0 : o.id) && // Throttle the frequency that we send streamed events while playing
|
1282
|
+
this._streamLatestTime[i] - this._streamStartTime[i] > ni && (this._sendTrackingEvent("VIDEO_STREAMED", {
|
1291
1283
|
answerId: e,
|
1292
|
-
streamStart: this.
|
1293
|
-
streamEnd:
|
1294
|
-
}), this.
|
1284
|
+
streamStart: this._streamStartTime[i],
|
1285
|
+
streamEnd: this._streamLatestTime[i]
|
1286
|
+
}), this._streamStartTime[i] = s.currentTime);
|
1295
1287
|
}, this._handleVideoPause = ({ detail: { id: e, key: i } }) => {
|
1296
|
-
|
1297
|
-
s && (this._streamLatestTime[i] > this._streamedTime[i] + 0.5 && this._sendTrackingEvent("VIDEO_STREAMED", {
|
1298
|
-
vouchId: s,
|
1288
|
+
this._streamLatestTime[i] > this._streamStartTime[i] && this._sendTrackingEvent("VIDEO_STREAMED", {
|
1299
1289
|
answerId: e,
|
1300
|
-
streamStart: this.
|
1290
|
+
streamStart: this._streamStartTime[i],
|
1301
1291
|
streamEnd: this._streamLatestTime[i]
|
1302
|
-
}), delete this.
|
1292
|
+
}), this._currentlyPlayingVideo = null, delete this._streamStartTime[i], delete this._streamLatestTime[i];
|
1303
1293
|
}, this.host = t, t.addController(this);
|
1304
1294
|
}
|
1305
1295
|
_findVouchId() {
|
@@ -1330,6 +1320,14 @@ class oi {
|
|
1330
1320
|
}
|
1331
1321
|
hostDisconnected() {
|
1332
1322
|
var t, e, i, s;
|
1323
|
+
if (this._currentlyPlayingVideo) {
|
1324
|
+
const { id: n, key: o } = this._currentlyPlayingVideo;
|
1325
|
+
this._streamLatestTime[o] > this._streamStartTime[o] && this._sendTrackingEvent("VIDEO_STREAMED", {
|
1326
|
+
answerId: n,
|
1327
|
+
streamStart: this._streamStartTime[o],
|
1328
|
+
streamEnd: this._streamLatestTime[o]
|
1329
|
+
});
|
1330
|
+
}
|
1333
1331
|
this.host.removeEventListener("vouch:loaded", this._handleVouchLoaded), (t = this.host.mediaPlayer) == null || t.removeEventListener("play", this._handlePlay), (e = this.host.mediaPlayer) == null || e.removeEventListener("video:play", this._handleVideoPlay), (i = this.host.mediaPlayer) == null || i.removeEventListener("video:pause", this._handleVideoPause), (s = this.host.mediaPlayer) == null || s.removeEventListener("video:timeupdate", this._handleVideoTimeUpdate);
|
1334
1332
|
}
|
1335
1333
|
}
|