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 Se from "../models/device.js"; import DeviceProperties from "../Core/device-properties.js"; import _t from "../models/identifier.js"; import { logger as E, Guid as V } from "../../shared-lib/index.js"; import { STORAGE_KEYS as s } from "../managers/storage-manager.js"; import { values as Wt } from "../util/code-utils.js"; import { getErrorMessage as ai } from "../util/error-utils.js"; export default class Pt { constructor(t, e) { (this.C = t), (this.Da = e), (this.C = t), null == e && (e = Wt(DeviceProperties)), (this.Da = e); } ve(t = !0) { let e = this.C.$u(s.Ou.Wh); null == e && ((e = new _t(V.de())), t && this.C.Iu(s.Ou.Wh, e)); const r = new Se(e.Tu); for (let t = 0; t < this.Da.length; t++) { switch (this.Da[t]) { case DeviceProperties.BROWSER: r.browser = ro.browser; break; case DeviceProperties.BROWSER_VERSION: r.Oa = ro.version; break; case DeviceProperties.OS: r.os = this.Fa(); break; case DeviceProperties.RESOLUTION: r.Ga = screen.width + "x" + screen.height; break; case DeviceProperties.LANGUAGE: r.language = ro.language; break; case DeviceProperties.TIME_ZONE: r.timeZone = this.Ja(new Date()); break; case DeviceProperties.USER_AGENT: r.userAgent = ro.userAgent; } } return r; } Fa() { if (ro.Aa()) return ro.Aa(); const t = this.C.Rt(s.Tt.Ba); return t && t.os_version ? t.os_version : ro.Fa(); } Ja(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:" + ai(t), ), (e = !0); } if (e) return ""; const r = t.getTimezoneOffset(); return this.Ha(r); } Ha(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 ); } }