@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 E, EventTypes as m } from "../../shared-lib/index.js";
import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
export default class M {
constructor(t) {
(this.j = t), (this.j = t);
}
logClick(t) {
const n = new G();
if ((t.$t(), null == t.url || "" === t.url))
return (
E.info(`Card ${t.id} has no url. Not logging click to Braze servers.`),
n
);
if (t.id && this.j) {
const n = this.j.lt(s.ct.Et) || {};
(n[t.id] = !0), this.j.ft(s.ct.Et, n);
}
const r = this.Gt([t]);
if (null == r) return n;
const i = m.Ht;
return c.rt(i, r);
}
Jt(t) {
const n = new G();
if (!t.Kt())
return (
E.info(
`Card ${t.id} refused this dismissal. Ignoring analytics event.`,
),
n
);
if (t.id && this.j) {
const n = this.j.lt(s.ct.Lt) || {};
(n[t.id] = !0), this.j.ft(s.ct.Lt, n);
}
const r = this.Gt([t]);
return null == r ? n : c.rt(m.Mt, r);
}
Ot(t) {
const n = new G(!0),
r = [],
i = [];
let o = {};
this.j && (o = this.j.lt(s.ct.Pt) || {});
for (const s of t) {
s.Qt()
? (s instanceof ControlCard ? i.push(s) : r.push(s),
s.id && (o[s.id] = !0))
: E.info(
`Card ${s.id} logged an impression too recently. Ignoring analytics event.`,
);
}
const e = this.Gt(r),
l = this.Gt(i);
if (null == e && null == l) return (n.W = !1), n;
if ((this.j && this.j.ft(s.ct.Pt, o), null != e)) {
const t = m.Ut,
s = c.rt(t, e);
n.Vt(s);
}
if (null != l) {
const t = c.rt(m.Wt, l);
n.Vt(t);
}
return n;
}
Gt(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;
}
}