@braze/web-sdk
Version:
Braze SDK for web sites and other JS platforms.
86 lines (85 loc) • 2.53 kB
JavaScript
import ro from "../util/browser-detector.js";
import Gt from "../models/device.js";
import DeviceProperties from "../Core/device-properties.js";
import _t from "../models/identifier.js";
import { logger as N, Guid as G } from "../../shared-lib/index.js";
import { STORAGE_KEYS as s } from "../managers/storage-manager.js";
import { values as Rt } from "../util/code-utils.js";
import { getErrorMessage as si } from "../util/error-utils.js";
export default class Ot {
constructor(t, e) {
(this.C = t),
(this.Qa = e),
(this.C = t),
null == e && (e = Rt(DeviceProperties)),
(this.Qa = e);
}
ve(t = !0) {
let e = this.C.tu(s.iu.Ia);
null == e && ((e = new _t(G.ce())), t && this.C.uu(s.iu.Ia, e));
const r = new Gt(e.eu);
for (let t = 0; t < this.Qa.length; t++) {
switch (this.Qa[t]) {
case DeviceProperties.BROWSER:
r.browser = ro.browser;
break;
case DeviceProperties.BROWSER_VERSION:
r.Za = ro.version;
break;
case DeviceProperties.OS:
r.os = this.tc();
break;
case DeviceProperties.RESOLUTION:
r.ec = screen.width + "x" + screen.height;
break;
case DeviceProperties.LANGUAGE:
r.language = ro.language;
break;
case DeviceProperties.TIME_ZONE:
r.timeZone = this.rc(new Date());
break;
case DeviceProperties.USER_AGENT:
r.userAgent = ro.userAgent;
}
}
return r;
}
tc() {
if (ro.sc()) return ro.sc();
const t = this.C.ft(s.gt.ic);
return t && t.os_version ? t.os_version : ro.tc();
}
rc(t) {
let e = !1;
if ("undefined" != typeof Intl && "function" == typeof Intl.DateTimeFormat)
try {
if ("function" == typeof Intl.DateTimeFormat().resolvedOptions) {
const t = Intl.DateTimeFormat().resolvedOptions().timeZone;
if (null != t && "" !== t) return t;
}
} catch (t) {
N.info(
"Intl.DateTimeFormat threw an error, cannot detect user's time zone:" +
si(t),
),
(e = !0);
}
if (e) return "";
const r = t.getTimezoneOffset();
return this.oc(r);
}
oc(t) {
const e = Math.trunc(t / 60),
r = Math.trunc(t % 60);
let s = "GMT";
return (
0 !== t &&
((s += t < 0 ? "+" : "-"),
(s +=
("00" + Math.abs(e)).slice(-2) +
":" +
("00" + Math.abs(r)).slice(-2))),
s
);
}
}