@braze/web-sdk
Version:
Braze SDK for web sites and other JS platforms.
39 lines (38 loc) • 1.22 kB
JavaScript
import r from "../managers/braze-instance.js";
import c from "../common/event-logger.js";
import { logger as N, EventTypes as d } from "../../shared-lib/index.js";
import ot from "../triggers/models/trigger-events.js";
import { TriggersProviderFactory as rt } from "../triggers/triggers-provider-factory.js";
import {
validateCustomProperties as nt,
validateCustomString as mt,
} from "../util/validation-utils.js";
import { LOG_CUSTOM_EVENT_STRING as gt } from "../common/constants.js";
export function logCustomEvent(t, e) {
if (!r.rr()) return !1;
if (null == t || t.length <= 0)
return (
N.error(
`logCustomEvent requires a non-empty eventName, got "${t}". Ignoring event.`,
),
!1
);
if (!mt(t, "log custom event", "the event name")) return !1;
const [o, n] = nt(
e,
gt,
"eventProperties",
`log custom event "${t}"`,
"event",
);
if (!o) return !1;
const i = r.v();
if (i && i.je(t))
return N.info(`Custom Event "${t}" is blocklisted, ignoring.`), !1;
const s = c.ut(d.CustomEvent, { n: t, p: n });
if (s.tt) {
N.info(`Logged custom event "${t}".`);
for (const o of s.$e) rt.m().Ce(ot.Ee, [t, e], o);
}
return s.tt;
}