UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

83 lines (82 loc) 2.2 kB
import { ControlCard } from "./models/index.js"; import c from "../common/event-logger.js"; import E 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, n) { const r = new E(); if ((t.$t(), null == t.url || "" === t.url)) return ( N.info(`Card ${t.id} has no url. Not logging click to Braze servers.`), r ); if (n && t.id && this.C) { const n = this.C.ft(s.gt.Kt) || {}; (n[t.id] = !0), this.C.Bt(s.gt.Kt, n); } const i = this.Lt([t]); if (null == i) return r; const o = n ? d.Mt : d.Ot; return c.ut(o, i); } Pt(t) { const n = new E(); if (!t.Qt()) 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.Vt) || {}; (n[t.id] = !0), this.C.Bt(s.gt.Vt, n); } const r = this.Lt([t]); return null == r ? n : c.ut(d.Wt, r); } Xt(t, n) { const r = new E(!0), i = [], o = []; let e = {}; this.C && (e = n ? this.C.ft(s.gt.Yt) || {} : this.C.ft(s.gt.Zt) || {}); for (const s of t) { s.ts() ? (s instanceof ControlCard ? o.push(s) : i.push(s), s.id && (e[s.id] = !0)) : N.info( `Card ${s.id} logged an impression too recently. Ignoring analytics event.`, ); } const l = this.Lt(i), a = this.Lt(o); if (null == l && null == a) return (r.tt = !1), r; if ( (this.C && (n ? this.C.Bt(s.gt.Yt, e) : this.C.Bt(s.gt.Zt, e)), null != l) ) { const t = n ? d.ss : d.ns, s = c.ut(t, l); r.rs(s); } if (null != a && n) { const t = c.ut(d.os, a); r.rs(t); } return r; } 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; } }