@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 v from "../common/event-logger.js";
import L from "../models/request-result.js";
import { logger as E, EventTypes as p } 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 L();
if ((t.ss(), 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.C) {
const n = this.C.Rt(s.Tt.ns) || {};
(n[t.id] = !0), this.C.It(s.Tt.ns, n);
}
const r = this.rs([t]);
if (null == r) return n;
const i = p.os;
return v.wt(i, r);
}
es(t) {
const n = new L();
if (!t.ls())
return (
E.info(
`Card ${t.id} refused this dismissal. Ignoring analytics event.`,
),
n
);
if (t.id && this.C) {
const n = this.C.Rt(s.Tt.us) || {};
(n[t.id] = !0), this.C.It(s.Tt.us, n);
}
const r = this.rs([t]);
return null == r ? n : v.wt(p.cs, r);
}
fs(t) {
const n = new L(!0),
r = [],
i = [];
let o = {};
this.C && (o = this.C.Rt(s.Tt.hs) || {});
for (const s of t) {
s.gs()
? (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.rs(r),
l = this.rs(i);
if (null == e && null == l) return (n.lt = !1), n;
if ((this.C && this.C.It(s.Tt.hs, o), null != e)) {
const t = p.ds,
s = v.wt(t, e);
n.ps(s);
}
if (null != l) {
const t = v.wt(p.js, l);
n.ps(t);
}
return n;
}
rs(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;
}
}