UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

81 lines (80 loc) 2.09 kB
import { ControlCard } from "./models/index.js"; import v from "../common/event-logger.js"; import L from "../models/request-result.js"; import { logger as b, 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.j = t), (this.j = t); } logClick(t) { const n = new L(); if ((t.Yt(), null == t.url || "" === t.url)) return ( b.info(`Card ${t.id} has no url. Not logging click to Braze servers.`), n ); if (t.id && this.j) { const n = this.j.St(s.It.Zt) || {}; (n[t.id] = !0), this.j.Pt(s.It.Zt, n); } const r = this.ls([t]); if (null == r) return n; const i = p.us; return v.Dt(i, r); } cs(t) { const n = new L(); if (!t.Ft()) return ( b.info( `Card ${t.id} refused this dismissal. Ignoring analytics event.`, ), n ); if (t.id && this.j) { const n = this.j.St(s.It.fs) || {}; (n[t.id] = !0), this.j.Pt(s.It.fs, n); } const r = this.ls([t]); return null == r ? n : v.Dt(p.gs, r); } ds(t) { const n = new L(!0), r = [], i = []; let o = {}; this.j && (o = this.j.St(s.It.ps) || {}); for (const s of t) { s.js() ? (s instanceof ControlCard ? i.push(s) : r.push(s), s.id && (o[s.id] = !0)) : b.info( `Card ${s.id} logged an impression too recently. Ignoring analytics event.`, ); } const e = this.ls(r), l = this.ls(i); if (null == e && null == l) return (n.lt = !1), n; if ((this.j && this.j.Pt(s.It.ps, o), null != e)) { const t = p.vs, s = v.Dt(t, e); n.Cs(s); } if (null != l) { const t = v.Dt(p.ws, l); n.Cs(t); } return n; } ls(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; } }