UNPKG

@braze/web-sdk

Version:

Braze SDK for web sites and other JS platforms.

86 lines (85 loc) 2.53 kB
import ro from "../util/browser-detector.js"; import Qt from "../models/device.js"; import DeviceProperties from "../Core/device-properties.js"; import _t from "../models/identifier.js"; import { logger as E, Guid as P } from "../../shared-lib/index.js"; import { STORAGE_KEYS as s } from "../managers/storage-manager.js"; import { values as Pt } from "../util/code-utils.js"; import { getErrorMessage as si } from "../util/error-utils.js"; export default class Ot { constructor(t, e) { (this.j = t), (this.Fa = e), (this.j = t), null == e && (e = Pt(DeviceProperties)), (this.Fa = e); } fe(t = !0) { let e = this.j.tu(s.iu.Jh); null == e && ((e = new _t(P.oe())), t && this.j.uu(s.iu.Jh, e)); const r = new Qt(e.eu); for (let t = 0; t < this.Fa.length; t++) { switch (this.Fa[t]) { case DeviceProperties.BROWSER: r.browser = ro.browser; break; case DeviceProperties.BROWSER_VERSION: r.Ga = ro.version; break; case DeviceProperties.OS: r.os = this.Ja(); break; case DeviceProperties.RESOLUTION: r.Ba = screen.width + "x" + screen.height; break; case DeviceProperties.LANGUAGE: r.language = ro.language; break; case DeviceProperties.TIME_ZONE: r.timeZone = this.Ha(new Date()); break; case DeviceProperties.USER_AGENT: r.userAgent = ro.userAgent; } } return r; } Ja() { if (ro.Ka()) return ro.Ka(); const t = this.j.lt(s.ct.Qa); return t && t.os_version ? t.os_version : ro.Ja(); } Ha(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) { E.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.Va(r); } Va(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 ); } }