@braze/web-sdk
Version:
Braze SDK for web sites and other JS platforms.
81 lines (80 loc) • 2.09 kB
JavaScript
import { ControlCard } from "./models/index.js";
import c from "../common/event-logger.js";
import G from "../models/request-result.js";
import { logger as N, EventTypes as d } from "../../shared-lib/index.js";
import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
export default class M {
constructor(t) {
(this.C = t), (this.C = t);
}
logClick(t) {
const n = new G();
if ((t.$t(), null == t.url || "" === t.url))
return (
N.info(`Card ${t.id} has no url. Not logging click to Braze servers.`),
n
);
if (t.id && this.C) {
const n = this.C.ft(s.gt.Kt) || {};
(n[t.id] = !0), this.C.Bt(s.gt.Kt, n);
}
const r = this.Lt([t]);
if (null == r) return n;
const i = d.Mt;
return c.ut(i, r);
}
Ot(t) {
const n = new G();
if (!t.Pt())
return (
N.info(
`Card ${t.id} refused this dismissal. Ignoring analytics event.`,
),
n
);
if (t.id && this.C) {
const n = this.C.ft(s.gt.Qt) || {};
(n[t.id] = !0), this.C.Bt(s.gt.Qt, n);
}
const r = this.Lt([t]);
return null == r ? n : c.ut(d.Vt, r);
}
Wt(t) {
const n = new G(!0),
r = [],
i = [];
let o = {};
this.C && (o = this.C.ft(s.gt.Xt) || {});
for (const s of t) {
s.Yt()
? (s instanceof ControlCard ? i.push(s) : r.push(s),
s.id && (o[s.id] = !0))
: N.info(
`Card ${s.id} logged an impression too recently. Ignoring analytics event.`,
);
}
const e = this.Lt(r),
l = this.Lt(i);
if (null == e && null == l) return (n.tt = !1), n;
if ((this.C && this.C.Bt(s.gt.Xt, o), null != e)) {
const t = d.Zt,
s = c.ut(t, e);
n._t(s);
}
if (null != l) {
const t = c.ut(d.ts, l);
n._t(t);
}
return n;
}
Lt(t) {
let s,
n = null;
for (let r = 0; r < t.length; r++)
(s = t[r].id),
null != s &&
"" !== s &&
((n = n || {}), (n.ids = n.ids || []), n.ids.push(s));
return n;
}
}