@jitsu/js 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jitsu/js",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "",
5
5
  "author": "Jitsu Dev Team <dev@jitsu.com>",
6
6
  "main": "dist/jitsu.cjs.js",
@@ -12,6 +12,7 @@
12
12
  "license": "MIT",
13
13
  "private": false,
14
14
  "devDependencies": {
15
+ "tldts": "^6.0.15",
15
16
  "@playwright/test": "1.31.2",
16
17
  "@rollup/plugin-commonjs": "^23.0.2",
17
18
  "@rollup/plugin-json": "^5.0.1",
@@ -34,7 +35,7 @@
34
35
  "rollup": "^3.2.5",
35
36
  "ts-jest": "29.0.5",
36
37
  "typescript": "^4.9.5",
37
- "@jitsu/protocols": "1.2.0"
38
+ "@jitsu/protocols": "1.3.0"
38
39
  },
39
40
  "dependencies": {
40
41
  "analytics": "^0.8.1"
@@ -3,6 +3,7 @@
3
3
  import { JitsuOptions, PersistentStorage, RuntimeFacade } from "./jitsu";
4
4
  import { AnalyticsClientEvent, Callback, ID, JSONObject, Options } from "@jitsu/protocols/analytics";
5
5
  import parse from "./index";
6
+ import { parse as parseTLD } from "tldts";
6
7
  import { AnalyticsInstance, AnalyticsPlugin } from "analytics";
7
8
  import { loadScript } from "./script-loader";
8
9
  import { internalDestinationPlugins } from "./destination-plugins";
@@ -73,12 +74,11 @@ export function getTopLevelDomain(opts: JitsuOptions = {}) {
73
74
  if (opts.cookieDomain) {
74
75
  return opts.cookieDomain;
75
76
  }
76
- const [domain] = window.location.hostname.split(":");
77
- const parts = domain.split(".");
78
- if (parts[parts.length - 1] === "localhost" || parts.length < 2) {
79
- return parts[parts.length - 1];
77
+ const tld = parseTLD(window.location.hostname);
78
+ if (tld.domain === null) {
79
+ return tld.hostname;
80
80
  } else {
81
- return parts[parts.length - 2] + "." + parts[parts.length - 1];
81
+ return tld.domain;
82
82
  }
83
83
  }
84
84
 
@@ -409,7 +409,7 @@ function maskWriteKey(writeKey?: string): string | undefined {
409
409
  if (secret) {
410
410
  return `${id}:***`;
411
411
  } else {
412
- return id;
412
+ return "***";
413
413
  }
414
414
  }
415
415
  return writeKey;
package/src/browser.ts CHANGED
@@ -2,6 +2,7 @@ import { JitsuOptions } from "./jitsu";
2
2
  import { jitsuAnalytics } from "./index";
3
3
 
4
4
  export type JitsuBrowserOptions = {
5
+ namespace?: string;
5
6
  userId?: string;
6
7
  onload?: string;
7
8
  initOnly?: boolean;
@@ -40,9 +41,6 @@ function getScriptAttributes(scriptElement: HTMLScriptElement) {
40
41
  }
41
42
 
42
43
  (function () {
43
- if (window["jitsu"]) {
44
- console.log("Jitsu is already initialized");
45
- }
46
44
  function readJitsuOptions(): JitsuBrowserOptions {
47
45
  const scriptElement = window.document.currentScript as HTMLScriptElement;
48
46
  if (!scriptElement) {
@@ -54,6 +52,11 @@ function getScriptAttributes(scriptElement: HTMLScriptElement) {
54
52
  }
55
53
 
56
54
  const options = readJitsuOptions();
55
+ const JITSU_V2_ID: string = options.namespace || "jitsu";
56
+
57
+ if (window[JITSU_V2_ID]) {
58
+ console.log("Jitsu is already initialized");
59
+ }
57
60
  if (options.debug) {
58
61
  console.log(`Jitsu options: `, JSON.stringify(options));
59
62
  }
@@ -70,7 +73,7 @@ function getScriptAttributes(scriptElement: HTMLScriptElement) {
70
73
  console.warn(`onload function ${options.onload} is not callable: ${typeof onloadFunction}`);
71
74
  }
72
75
  }
73
- window["jitsu"] = jitsu;
76
+ window[JITSU_V2_ID] = jitsu;
74
77
 
75
78
  if (!options.initOnly) {
76
79
  jitsu.page();