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 N, Guid as O } 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.C = t), (this.Ga = e), (this.C = t), null == e && (e = Pt(DeviceProperties)), (this.Ga = e); } ve(t = !0) { let e = this.C.tu(s.iu.Qh); null == e && ((e = new _t(O.ce())), t && this.C.uu(s.iu.Qh, e)); const r = new Qt(e.eu); for (let t = 0; t < this.Ga.length; t++) { switch (this.Ga[t]) { case DeviceProperties.BROWSER: r.browser = ro.browser; break; case DeviceProperties.BROWSER_VERSION: r.Ja = ro.version; break; case DeviceProperties.OS: r.os = this.Ha(); break; case DeviceProperties.RESOLUTION: r.Qa = screen.width + "x" + screen.height; break; case DeviceProperties.LANGUAGE: r.language = ro.language; break; case DeviceProperties.TIME_ZONE: r.timeZone = this.Xa(new Date()); break; case DeviceProperties.USER_AGENT: r.userAgent = ro.userAgent; } } return r; } Ha() { if (ro.Ya()) return ro.Ya(); const t = this.C.ft(s.gt.Za); return t && t.os_version ? t.os_version : ro.Ha(); } Xa(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.$a(r); } $a(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 ); } }