@jitsu/js 0.0.0-alpha.110 → 0.0.0-alpha.115

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": "0.0.0-alpha.110",
3
+ "version": "0.0.0-alpha.115",
4
4
  "description": "",
5
5
  "author": "Jitsu Dev Team <dev@jitsu.com>",
6
6
  "main": "dist/jitsu.cjs.js",
@@ -12,7 +12,6 @@
12
12
  "license": "MIT",
13
13
  "private": false,
14
14
  "devDependencies": {
15
- "seedrandom": "^3.0.5",
16
15
  "@playwright/test": "^1.28.1",
17
16
  "@rollup/plugin-commonjs": "^23.0.2",
18
17
  "@rollup/plugin-json": "^5.0.1",
@@ -34,7 +33,7 @@
34
33
  "raw-loader": "^4.0.2",
35
34
  "rollup": "^3.2.5",
36
35
  "ts-jest": "^29.0.3",
37
- "@jitsu/types": "0.0.0-alpha.110"
36
+ "@jitsu/types": "0.0.0-alpha.115"
38
37
  },
39
38
  "dependencies": {
40
39
  "analytics": "^0.8.1"
@@ -4,7 +4,6 @@ import { JitsuOptions, PersistentStorage, RuntimeFacade } from "./jitsu";
4
4
  import { AnalyticsClientEvent } from "@jitsu/types/analytics";
5
5
  import parse from "./index";
6
6
  import { AnalyticsPlugin } from "analytics";
7
- import seedrandom from "seedrandom";
8
7
 
9
8
  const config: JitsuOptions = {
10
9
  /* Your segment writeKey */
@@ -14,7 +13,6 @@ const config: JitsuOptions = {
14
13
  debug: false,
15
14
  fetch: null,
16
15
  };
17
- const autoSeedRandom = seedrandom();
18
16
 
19
17
  export const parseQuery = (qs?: string): Record<string, string> => {
20
18
  if (!qs) {
@@ -274,7 +272,7 @@ function adjustPayload(payload: any, config: JitsuOptions, storage: PersistentSt
274
272
  ...payload,
275
273
  timestamp: new Date().toISOString(),
276
274
  sentAt: new Date().toISOString(),
277
- messageId: randomId(),
275
+ messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)),
278
276
  context: deepMerge(context, customContext),
279
277
  };
280
278
  delete withContext.meta;
@@ -375,22 +373,34 @@ const jitsuAnalyticsPlugin = (pluginConfig: JitsuOptions = {}): AnalyticsPlugin
375
373
  },
376
374
  };
377
375
  };
378
- export function randomId(digits: number = 24): string {
379
- let id = "";
380
- for (let i = 0; i < digits; i++) {
381
- id += randomChar(i === 0, autoSeedRandom);
382
- }
383
- return id;
376
+
377
+ export function randomId(hashString: string | undefined = ""): string {
378
+ const d = new Date().getTime();
379
+ return (
380
+ (
381
+ (Math.random() * d * hash(hashString ?? "", window?.performance?.now() || d % 2147483647)) %
382
+ Number.MAX_SAFE_INTEGER
383
+ ).toString(36) +
384
+ (
385
+ (Math.random() * d * hash(hashString ?? "", window?.performance?.now() || d % 2147483647)) %
386
+ Number.MAX_SAFE_INTEGER
387
+ ).toString(36)
388
+ );
384
389
  }
385
390
 
386
- function randomChar(noDigits?: boolean, rng: () => number = Math.random): string {
387
- const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
388
- while (true) {
389
- const index = Math.floor(rng() * chars.length);
390
- if (!noDigits || index > 9) {
391
- return chars[index];
392
- }
391
+ function hash(str: string, seed: number = 0): number {
392
+ let h1 = 0xdeadbeef ^ seed,
393
+ h2 = 0x41c6ce57 ^ seed;
394
+ for (let i = 0, ch; i < str.length; i++) {
395
+ ch = str.charCodeAt(i);
396
+ h1 = Math.imul(h1 ^ ch, 2654435761);
397
+ h2 = Math.imul(h2 ^ ch, 1597334677);
393
398
  }
399
+
400
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
401
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
402
+
403
+ return 4294967296 * (2097151 & h2) + (h1 >>> 0);
394
404
  }
395
405
 
396
406
  export default jitsuAnalyticsPlugin;
package/src/jitsu.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { AnalyticsInterface } from "@jitsu/types/analytics";
1
+ import { AnalyticsInterface as ai } from "@jitsu/types/analytics";
2
2
  import type { AnalyticsPlugin } from "analytics";
3
3
 
4
+ export type AnalyticsInterface = ai;
5
+
4
6
  export type JitsuOptions = {
5
7
  /**
6
8
  * API Key. Optional. If not set, Jitsu will send event to the server without auth, and server