export function getInitialSettings()

in products/userale/src/getInitialSettings.ts [28:77]


export function getInitialSettings(): Settings.Config {
  if (sessionId === null) {
    sessionId = getsessionId(
      "userAlesessionId",
      "session_" + String(Date.now()),
    );
  }

  if (httpSessionId === null) {
    httpSessionId = getsessionId(
      "userAleHttpSessionId",
      generatehttpSessionId(),
    );
  }

  const script =
    document.currentScript ||
    (function () {
      const scripts = document.getElementsByTagName("script");
      return scripts[scripts.length - 1];
    })();

  const get = script
    ? script.getAttribute.bind(script)
    : function () {
        return null;
      };
  const headers = get("data-headers");
  const settings: Settings.Config = {
    authHeader: get("data-auth") || null,
    autostart: get("data-autostart") === "false" ? false : true,
    browserSessionId: null,
    custIndex: get("data-index") || null,
    headers: headers ? JSON.parse(headers) : null,
    httpSessionId: httpSessionId,
    logCountThreshold: +(get("data-threshold") || 5),
    logDetails: get("data-log-details") === "true" ? true : false,
    resolution: +(get("data-resolution") || 500),
    sessionId: get("data-session") || sessionId,
    time: timeStampScale(document.createEvent("CustomEvent")),
    toolName: get("data-tool") || null,
    toolVersion: get("data-version") || null,
    transmitInterval: +(get("data-interval") || 5000),
    url: get("data-url") || "http://localhost:8000",
    useraleVersion: get("data-userale-version") || null,
    userFromParams: get("data-user-from-params") || null,
    userId: get("data-user") || null,
  };
  return settings;
}