@jitsu/js 1.9.4 → 1.9.6

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.
@@ -214,8 +214,8 @@ test("jitsu-queue-callbacks", async ({ browser }) => {
214
214
  expect(requestLog.length).toBe(3);
215
215
  });
216
216
 
217
- test("url-bug", async ({ browser }) => {
218
- clearRequestLog();
217
+ // Skip this test because jitsu-js no longer relies on canonical URL
218
+ test.skip("url-bug", async ({ browser, context }) => {
219
219
  //tests a bug in getanalytics.io where the url without slash provided by
220
220
  //<link rel="canonical" ../> causes incorrect page path
221
221
  const browserContext = await browser.newContext();
@@ -26,6 +26,5 @@ export type DeviceOptions = AnalyticsPluginDescriptor | InternalPluginDescriptor
26
26
  export type JitsuPluginConfig = JitsuOptions & {
27
27
  storageWrapper?: (persistentStorage: PersistentStorage) => PersistentStorage;
28
28
  };
29
- declare const jitsuAnalyticsPlugin: (pluginConfig?: JitsuPluginConfig) => AnalyticsPlugin;
29
+ export declare const jitsuAnalyticsPlugin: (pluginConfig?: JitsuPluginConfig) => AnalyticsPlugin;
30
30
  export declare function randomId(hashString?: string | undefined): string;
31
- export default jitsuAnalyticsPlugin;
package/dist/jitsu.cjs.js CHANGED
@@ -1328,6 +1328,17 @@ function fixPath(path) {
1328
1328
  }
1329
1329
  return path;
1330
1330
  }
1331
+ const hashRegex = /#.*$/;
1332
+ /**
1333
+ * for compatibility with path produced by analytics.js
1334
+ * @param url
1335
+ */
1336
+ function urlPath(url) {
1337
+ const regex = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/g;
1338
+ const matches = regex.exec(url);
1339
+ const pathMatch = matches && matches[3] ? matches[3].split("?")[0].replace(hashRegex, "") : "";
1340
+ return "/" + pathMatch;
1341
+ }
1331
1342
  function adjustPayload(payload, config, storage, s2s) {
1332
1343
  var _a, _b;
1333
1344
  const runtime = config.runtime || (isInBrowser() ? windowRuntime(config) : emptyRuntime(config));
@@ -1335,8 +1346,9 @@ function adjustPayload(payload, config, storage, s2s) {
1335
1346
  const parsedUrl = safeCall(() => new URL(url), undefined);
1336
1347
  const query = parsedUrl ? parseQuery(parsedUrl.search) : {};
1337
1348
  const properties = payload.properties || {};
1338
- if (properties.path) {
1339
- properties.path = fixPath(properties.path);
1349
+ if (payload.type === "page" && url) {
1350
+ properties.url = url.replace(hashRegex, "");
1351
+ properties.path = fixPath(urlPath(url));
1340
1352
  }
1341
1353
  const customContext = ((_a = payload.properties) === null || _a === void 0 ? void 0 : _a.context) || {};
1342
1354
  (_b = payload.properties) === null || _b === void 0 ? true : delete _b.context;
@@ -1831,6 +1843,7 @@ exports.emptyAnalytics = emptyAnalytics;
1831
1843
  exports.emptyRuntime = emptyRuntime;
1832
1844
  exports.isInBrowser = isInBrowser;
1833
1845
  exports.jitsuAnalytics = jitsuAnalytics;
1846
+ exports.jitsuAnalyticsPlugin = jitsuAnalyticsPlugin;
1834
1847
  exports.parseQuery = parseQuery;
1835
1848
  exports.randomId = randomId;
1836
1849
  exports.windowRuntime = windowRuntime;
package/dist/jitsu.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { AnalyticsInterface } from "@jitsu/protocols/analytics";
2
- import type { AnalyticsPlugin } from "analytics";
3
2
  type JitsuOptions = {
4
3
  /**
5
4
  * API Key. Optional. If not set, Jitsu will send event to the server without auth, and server
@@ -74,5 +73,4 @@ type RuntimeFacade = {
74
73
  pageTitle(): string | undefined;
75
74
  };
76
75
  export declare function jitsuAnalytics(opts: JitsuOptions): AnalyticsInterface;
77
- export declare const jitsuAnalyticsPlugin: AnalyticsPlugin;
78
76
  export { AnalyticsInterface, JitsuOptions, PersistentStorage, RuntimeFacade };
package/dist/jitsu.es.js CHANGED
@@ -1326,6 +1326,17 @@ function fixPath(path) {
1326
1326
  }
1327
1327
  return path;
1328
1328
  }
1329
+ const hashRegex = /#.*$/;
1330
+ /**
1331
+ * for compatibility with path produced by analytics.js
1332
+ * @param url
1333
+ */
1334
+ function urlPath(url) {
1335
+ const regex = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/g;
1336
+ const matches = regex.exec(url);
1337
+ const pathMatch = matches && matches[3] ? matches[3].split("?")[0].replace(hashRegex, "") : "";
1338
+ return "/" + pathMatch;
1339
+ }
1329
1340
  function adjustPayload(payload, config, storage, s2s) {
1330
1341
  var _a, _b;
1331
1342
  const runtime = config.runtime || (isInBrowser() ? windowRuntime(config) : emptyRuntime(config));
@@ -1333,8 +1344,9 @@ function adjustPayload(payload, config, storage, s2s) {
1333
1344
  const parsedUrl = safeCall(() => new URL(url), undefined);
1334
1345
  const query = parsedUrl ? parseQuery(parsedUrl.search) : {};
1335
1346
  const properties = payload.properties || {};
1336
- if (properties.path) {
1337
- properties.path = fixPath(properties.path);
1347
+ if (payload.type === "page" && url) {
1348
+ properties.url = url.replace(hashRegex, "");
1349
+ properties.path = fixPath(urlPath(url));
1338
1350
  }
1339
1351
  const customContext = ((_a = payload.properties) === null || _a === void 0 ? void 0 : _a.context) || {};
1340
1352
  (_b = payload.properties) === null || _b === void 0 ? true : delete _b.context;
@@ -1825,4 +1837,4 @@ function uuid() {
1825
1837
  return u;
1826
1838
  }
1827
1839
 
1828
- export { emptyAnalytics, emptyRuntime, isInBrowser, jitsuAnalytics, parseQuery, randomId, windowRuntime };
1840
+ export { emptyAnalytics, emptyRuntime, isInBrowser, jitsuAnalytics, jitsuAnalyticsPlugin, parseQuery, randomId, windowRuntime };
package/dist/web/p.js.txt CHANGED
@@ -1329,6 +1329,17 @@
1329
1329
  }
1330
1330
  return path;
1331
1331
  }
1332
+ const hashRegex = /#.*$/;
1333
+ /**
1334
+ * for compatibility with path produced by analytics.js
1335
+ * @param url
1336
+ */
1337
+ function urlPath(url) {
1338
+ const regex = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/g;
1339
+ const matches = regex.exec(url);
1340
+ const pathMatch = matches && matches[3] ? matches[3].split("?")[0].replace(hashRegex, "") : "";
1341
+ return "/" + pathMatch;
1342
+ }
1332
1343
  function adjustPayload(payload, config, storage, s2s) {
1333
1344
  var _a, _b;
1334
1345
  const runtime = config.runtime || (isInBrowser() ? windowRuntime(config) : emptyRuntime(config));
@@ -1336,8 +1347,9 @@
1336
1347
  const parsedUrl = safeCall(() => new URL(url), undefined);
1337
1348
  const query = parsedUrl ? parseQuery(parsedUrl.search) : {};
1338
1349
  const properties = payload.properties || {};
1339
- if (properties.path) {
1340
- properties.path = fixPath(properties.path);
1350
+ if (payload.type === "page" && url) {
1351
+ properties.url = url.replace(hashRegex, "");
1352
+ properties.path = fixPath(urlPath(url));
1341
1353
  }
1342
1354
  const customContext = ((_a = payload.properties) === null || _a === void 0 ? void 0 : _a.context) || {};
1343
1355
  (_b = payload.properties) === null || _b === void 0 ? true : delete _b.context;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jitsu/js",
3
- "version": "1.9.4",
3
+ "version": "1.9.6",
4
4
  "description": "",
5
5
  "author": "Jitsu Dev Team <dev@jitsu.com>",
6
6
  "main": "dist/jitsu.cjs.js",
@@ -34,8 +34,8 @@
34
34
  "rollup": "^3.2.5",
35
35
  "ts-jest": "29.0.5",
36
36
  "typescript": "^5.3.3",
37
- "@jitsu/protocols": "1.9.4",
38
- "jsondiffpatch": "1.9.4"
37
+ "@jitsu/protocols": "1.9.6",
38
+ "jsondiffpatch": "1.9.6"
39
39
  },
40
40
  "dependencies": {
41
41
  "analytics": "0.8.9"
@@ -334,6 +334,19 @@ function fixPath(path: string): string {
334
334
  return path;
335
335
  }
336
336
 
337
+ const hashRegex = /#.*$/;
338
+
339
+ /**
340
+ * for compatibility with path produced by analytics.js
341
+ * @param url
342
+ */
343
+ function urlPath(url) {
344
+ const regex = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/g;
345
+ const matches = regex.exec(url);
346
+ const pathMatch = matches && matches[3] ? matches[3].split("?")[0].replace(hashRegex, "") : "";
347
+ return "/" + pathMatch;
348
+ }
349
+
337
350
  function adjustPayload(
338
351
  payload: any,
339
352
  config: JitsuOptions,
@@ -346,8 +359,9 @@ function adjustPayload(
346
359
  const query = parsedUrl ? parseQuery(parsedUrl.search) : {};
347
360
  const properties = payload.properties || {};
348
361
 
349
- if (properties.path) {
350
- properties.path = fixPath(properties.path);
362
+ if (payload.type === "page" && url) {
363
+ properties.url = url.replace(hashRegex, "");
364
+ properties.path = fixPath(urlPath(url));
351
365
  }
352
366
 
353
367
  const customContext = payload.properties?.context || {};
@@ -646,7 +660,7 @@ async function send(
646
660
  export type JitsuPluginConfig = JitsuOptions & {
647
661
  storageWrapper?: (persistentStorage: PersistentStorage) => PersistentStorage;
648
662
  };
649
- const jitsuAnalyticsPlugin = (pluginConfig: JitsuPluginConfig = {}): AnalyticsPlugin => {
663
+ export const jitsuAnalyticsPlugin = (pluginConfig: JitsuPluginConfig = {}): AnalyticsPlugin => {
650
664
  const instanceConfig = {
651
665
  ...defaultConfig,
652
666
  ...pluginConfig,
@@ -761,5 +775,3 @@ function hash(str: string, seed: number = 0): number {
761
775
 
762
776
  return 4294967296 * (2097151 & h2) + (h1 >>> 0);
763
777
  }
764
-
765
- export default jitsuAnalyticsPlugin;
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import Analytics from "analytics";
2
2
  import { AnalyticsInterface, JitsuOptions, PersistentStorage, RuntimeFacade } from "./jitsu";
3
- import jitsuAnalyticsPlugin, { emptyRuntime, isInBrowser, windowRuntime } from "./analytics-plugin";
3
+ import { jitsuAnalyticsPlugin, emptyRuntime, isInBrowser, windowRuntime } from "./analytics-plugin";
4
4
  import { Callback, DispatchedEvent, ID, JSONObject, Options } from "@jitsu/protocols/analytics";
5
5
 
6
6
  export default function parse(input) {
package/src/jitsu.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { AnalyticsInterface } from "@jitsu/protocols/analytics";
2
- import type { AnalyticsPlugin } from "analytics";
3
2
 
4
3
  type JitsuOptions = {
5
4
  /**
@@ -84,6 +83,4 @@ type RuntimeFacade = {
84
83
 
85
84
  export declare function jitsuAnalytics(opts: JitsuOptions): AnalyticsInterface;
86
85
 
87
- export declare const jitsuAnalyticsPlugin: AnalyticsPlugin;
88
-
89
86
  export { AnalyticsInterface, JitsuOptions, PersistentStorage, RuntimeFacade };