UNPKG

@dotcms/analytics

Version:

Official JavaScript library for Content Analytics with DotCMS.

47 lines (46 loc) 1.59 kB
import i from "analytics"; import { EXPECTED_UTM_KEYS as a } from "./dot-content-analytics.constants.js"; import { dotAnalyticsEnricherPlugin as s } from "../plugin/dot-analytics.enricher.plugin.js"; import { dotAnalytics as c } from "../plugin/dot-analytics.plugin.js"; const h = (e) => ({ utc_time: (/* @__PURE__ */ new Date()).toISOString(), local_tz_offset: (/* @__PURE__ */ new Date()).getTimezoneOffset(), screen_resolution: `${window.screen.width}x${window.screen.height}`, vp_size: `${window.innerWidth}x${window.innerHeight}`, userAgent: navigator.userAgent, user_language: navigator.language, doc_encoding: document.characterSet, doc_path: e.pathname, doc_host: e.hostname, doc_protocol: e.protocol, doc_hash: e.hash, doc_search: e.search, referrer: document.referrer, page_title: document.title, utm: u(window.location) }), u = (e) => { const o = new URLSearchParams(e.search); return a.reduce( (t, r) => { const n = o.get(r); return n !== null && (t[r.replace("utm_", "")] = n), t; }, {} ); }, m = () => { try { return typeof window > "u" || !window.parent ? !1 : window.parent !== window; } catch { return !1; } }, p = (e) => e.apiKey ? e.server ? i({ app: "dotAnalytics", debug: e.debug, plugins: [s, c(e)] }) : (console.error('DotContentAnalytics: Missing "server" in configuration'), null) : (console.error('DotContentAnalytics: Missing "apiKey" in configuration'), null); export { p as createAnalyticsInstance, u as extractUTMParameters, h as getBrowserEventData, m as isInsideEditor };