@jitsu/js 0.0.1-alpha.126 → 0.0.1-alpha.136
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/.turbo/turbo-build.log +3 -3
- package/.turbo/turbo-clean.log +1 -1
- package/dist/analytics-plugin.d.ts +1 -1
- package/dist/browser.d.ts +2 -2
- package/dist/jitsu.cjs.js +9 -4
- package/dist/jitsu.d.ts +26 -3
- package/dist/jitsu.es.js +9 -4
- package/dist/web/p.js.txt +9 -4
- package/package.json +2 -2
- package/src/analytics-plugin.ts +10 -3
- package/src/jitsu.ts +23 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@jitsu/js:build: cache hit, replaying output [
|
|
1
|
+
@jitsu/js:build: cache hit, replaying output [2m28c829c71eac02d2[0m
|
|
2
2
|
[35m@jitsu/js:build: [0m
|
|
3
3
|
[35m@jitsu/js:build: [0m> @jitsu/js@0.0.0 build /Users/ildarnurislamov/Projects/onetag/libs/jitsu-js
|
|
4
4
|
[35m@jitsu/js:build: [0m> tsc -p . && rollup -c && cp compiled/src/*.d.ts dist
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
[35m@jitsu/js:build: [0m[1m./compiled/src/browser.js[22m → [1mdist/web/p.js.txt[22m...[39m
|
|
8
8
|
[35m@jitsu/js:build: [0m[1m[33m(!) Circular dependency[39m[22m
|
|
9
9
|
[35m@jitsu/js:build: [0mcompiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
|
|
10
|
-
[35m@jitsu/js:build: [0m[32mcreated [1mdist/web/p.js.txt[22m in [
|
|
10
|
+
[35m@jitsu/js:build: [0m[32mcreated [1mdist/web/p.js.txt[22m in [1m321ms[22m[39m
|
|
11
11
|
[35m@jitsu/js:build: [0m[36m
|
|
12
12
|
[35m@jitsu/js:build: [0m[1m./compiled/src/index.js, ./compiled/src/jitsu.js, ./compiled/src/analytics-plugin.js[22m → [1mdist/jitsu.es.js, dist/jitsu.cjs.js[22m...[39m
|
|
13
13
|
[35m@jitsu/js:build: [0m[1m[33m(!) Circular dependency[39m[22m
|
|
14
14
|
[35m@jitsu/js:build: [0mcompiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
|
|
15
|
-
[35m@jitsu/js:build: [0m[32mcreated [1mdist/jitsu.es.js, dist/jitsu.cjs.js[22m in [
|
|
15
|
+
[35m@jitsu/js:build: [0m[32mcreated [1mdist/jitsu.es.js, dist/jitsu.cjs.js[22m in [1m169ms[22m[39m
|
package/.turbo/turbo-clean.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@jitsu/js:clean: cache hit, replaying output [
|
|
1
|
+
@jitsu/js:clean: cache hit, replaying output [2m4b09f8b5fadef595[0m
|
|
2
2
|
[35m@jitsu/js:clean: [0m
|
|
3
3
|
[35m@jitsu/js:clean: [0m> @jitsu/js@0.0.0 clean /Users/ildarnurislamov/Projects/onetag/libs/jitsu-js
|
|
4
4
|
[35m@jitsu/js:clean: [0m> rm -rf ./dist
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JitsuOptions, PersistentStorage, RuntimeFacade } from "./jitsu";
|
|
2
2
|
import { AnalyticsPlugin } from "analytics";
|
|
3
3
|
export declare const parseQuery: (qs?: string) => Record<string, string>;
|
|
4
|
-
export
|
|
4
|
+
export type StorageFactory = (cookieDomain: string, cookie2key: Record<string, string>) => PersistentStorage;
|
|
5
5
|
export declare function getTopLevelDomain(opts?: JitsuOptions): string;
|
|
6
6
|
export declare function windowRuntime(opts: JitsuOptions): RuntimeFacade;
|
|
7
7
|
export declare const emptyRuntime: (config: JitsuOptions) => RuntimeFacade;
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JitsuOptions } from "./jitsu";
|
|
2
|
-
export
|
|
2
|
+
export type JitsuBrowserOptions = {
|
|
3
3
|
userId?: string;
|
|
4
4
|
onload?: string;
|
|
5
5
|
initOnly?: boolean;
|
|
6
6
|
} & JitsuOptions;
|
|
7
|
-
export
|
|
7
|
+
export type Parser = (arg: string) => any;
|
package/dist/jitsu.cjs.js
CHANGED
|
@@ -75,6 +75,7 @@ const config = {
|
|
|
75
75
|
host: null,
|
|
76
76
|
debug: false,
|
|
77
77
|
fetch: null,
|
|
78
|
+
echoEvents: false,
|
|
78
79
|
};
|
|
79
80
|
const parseQuery = (qs) => {
|
|
80
81
|
if (!qs) {
|
|
@@ -311,18 +312,22 @@ function adjustPayload(payload, config, storage) {
|
|
|
311
312
|
},
|
|
312
313
|
campaign: parseUtms(query),
|
|
313
314
|
};
|
|
314
|
-
const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), context: deepMerge(context, customContext) });
|
|
315
|
+
const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), writeKey: config.writeKey, context: deepMerge(context, customContext) });
|
|
315
316
|
delete withContext.meta;
|
|
316
317
|
delete withContext.options;
|
|
317
318
|
return withContext;
|
|
318
319
|
}
|
|
319
320
|
function send(method, payload, jitsuConfig, store) {
|
|
321
|
+
if (jitsuConfig.echoEvents) {
|
|
322
|
+
console.log(`[JITSU] sending '${method}' event:`, payload);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
320
325
|
const url = `${jitsuConfig.host}/api/s/${method}`;
|
|
321
326
|
const fetch = jitsuConfig.fetch || globalThis.fetch;
|
|
322
327
|
if (!fetch) {
|
|
323
328
|
throw new Error("Please specify fetch function in jitsu plugin initialization, fetch isn't available in global scope");
|
|
324
329
|
}
|
|
325
|
-
const authHeader =
|
|
330
|
+
const authHeader = {};
|
|
326
331
|
const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
|
|
327
332
|
if (jitsuConfig.debug) {
|
|
328
333
|
console.log(`Sending jitsu event to ${url}: `, JSON.stringify(payload, null, 2));
|
|
@@ -370,8 +375,8 @@ const jitsuAnalyticsPlugin = (pluginConfig = {}) => {
|
|
|
370
375
|
if (config.debug) {
|
|
371
376
|
console.debug("Initializing Jitsu plugin with config: ", JSON.stringify(config));
|
|
372
377
|
}
|
|
373
|
-
if (!config.host) {
|
|
374
|
-
throw new Error("Please specify host variable in jitsu plugin initialization");
|
|
378
|
+
if (!config.host && !config.echoEvents) {
|
|
379
|
+
throw new Error("Please specify host variable in jitsu plugin initialization, or set echoEvents to true");
|
|
375
380
|
}
|
|
376
381
|
},
|
|
377
382
|
page: args => {
|
package/dist/jitsu.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AnalyticsInterface } from "@jitsu/protocols/analytics";
|
|
2
2
|
import type { AnalyticsPlugin } from "analytics";
|
|
3
|
-
|
|
3
|
+
type JitsuOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* API Key. Optional. If not set, Jitsu will send event to the server without auth, and server
|
|
6
6
|
* will link the call to configured source by domain name
|
|
@@ -10,17 +10,40 @@ declare type JitsuOptions = {
|
|
|
10
10
|
* API Host. Default value: same host as script origin
|
|
11
11
|
*/
|
|
12
12
|
host?: string;
|
|
13
|
+
/**
|
|
14
|
+
* To enable debug logging
|
|
15
|
+
*/
|
|
13
16
|
debug?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Explicitely specify cookie domain. If not set, cookie domain will be set to top level
|
|
19
|
+
* of the current domain. Example: if JS lives on "app.example.com", cookie domain will be
|
|
20
|
+
* set to ".example.com". If it lives on "example.com", cookie domain will be set to ".example.com" too
|
|
21
|
+
*/
|
|
14
22
|
cookieDomain?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Provide fetch implementation. It is required if you want to use Jitsu in NodeJS
|
|
25
|
+
*/
|
|
15
26
|
fetch?: typeof fetch;
|
|
27
|
+
/**
|
|
28
|
+
* Which runtime to use. Runtime is used for obtaining context of the event: cookes,
|
|
29
|
+
* url, etc. At the moment, Jitsu supports browser runtime and NodeJS runtime, but you
|
|
30
|
+
* can provide your own implementation.
|
|
31
|
+
*
|
|
32
|
+
* If it's not set, the runtime will be detected automatically by presense of `window` object
|
|
33
|
+
*/
|
|
16
34
|
runtime?: RuntimeFacade;
|
|
35
|
+
/**
|
|
36
|
+
* If set to true, jitsu will output events in console. In this case you don't need to set
|
|
37
|
+
* writeKey / host. It's useful for debugging development environment
|
|
38
|
+
*/
|
|
39
|
+
echoEvents?: boolean;
|
|
17
40
|
};
|
|
18
|
-
|
|
41
|
+
type PersistentStorage = {
|
|
19
42
|
getItem: (key: string, options?: any) => any;
|
|
20
43
|
setItem: (key: string, value: any, options?: any) => void;
|
|
21
44
|
removeItem: (key: string, options?: any) => void;
|
|
22
45
|
};
|
|
23
|
-
|
|
46
|
+
type RuntimeFacade = {
|
|
24
47
|
store(): PersistentStorage;
|
|
25
48
|
userAgent(): string | undefined;
|
|
26
49
|
language(): string | undefined;
|
package/dist/jitsu.es.js
CHANGED
|
@@ -73,6 +73,7 @@ const config = {
|
|
|
73
73
|
host: null,
|
|
74
74
|
debug: false,
|
|
75
75
|
fetch: null,
|
|
76
|
+
echoEvents: false,
|
|
76
77
|
};
|
|
77
78
|
const parseQuery = (qs) => {
|
|
78
79
|
if (!qs) {
|
|
@@ -309,18 +310,22 @@ function adjustPayload(payload, config, storage) {
|
|
|
309
310
|
},
|
|
310
311
|
campaign: parseUtms(query),
|
|
311
312
|
};
|
|
312
|
-
const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), context: deepMerge(context, customContext) });
|
|
313
|
+
const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), writeKey: config.writeKey, context: deepMerge(context, customContext) });
|
|
313
314
|
delete withContext.meta;
|
|
314
315
|
delete withContext.options;
|
|
315
316
|
return withContext;
|
|
316
317
|
}
|
|
317
318
|
function send(method, payload, jitsuConfig, store) {
|
|
319
|
+
if (jitsuConfig.echoEvents) {
|
|
320
|
+
console.log(`[JITSU] sending '${method}' event:`, payload);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
318
323
|
const url = `${jitsuConfig.host}/api/s/${method}`;
|
|
319
324
|
const fetch = jitsuConfig.fetch || globalThis.fetch;
|
|
320
325
|
if (!fetch) {
|
|
321
326
|
throw new Error("Please specify fetch function in jitsu plugin initialization, fetch isn't available in global scope");
|
|
322
327
|
}
|
|
323
|
-
const authHeader =
|
|
328
|
+
const authHeader = {};
|
|
324
329
|
const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
|
|
325
330
|
if (jitsuConfig.debug) {
|
|
326
331
|
console.log(`Sending jitsu event to ${url}: `, JSON.stringify(payload, null, 2));
|
|
@@ -368,8 +373,8 @@ const jitsuAnalyticsPlugin = (pluginConfig = {}) => {
|
|
|
368
373
|
if (config.debug) {
|
|
369
374
|
console.debug("Initializing Jitsu plugin with config: ", JSON.stringify(config));
|
|
370
375
|
}
|
|
371
|
-
if (!config.host) {
|
|
372
|
-
throw new Error("Please specify host variable in jitsu plugin initialization");
|
|
376
|
+
if (!config.host && !config.echoEvents) {
|
|
377
|
+
throw new Error("Please specify host variable in jitsu plugin initialization, or set echoEvents to true");
|
|
373
378
|
}
|
|
374
379
|
},
|
|
375
380
|
page: args => {
|
package/dist/web/p.js.txt
CHANGED
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
host: null,
|
|
77
77
|
debug: false,
|
|
78
78
|
fetch: null,
|
|
79
|
+
echoEvents: false,
|
|
79
80
|
};
|
|
80
81
|
const parseQuery = (qs) => {
|
|
81
82
|
if (!qs) {
|
|
@@ -312,18 +313,22 @@
|
|
|
312
313
|
},
|
|
313
314
|
campaign: parseUtms(query),
|
|
314
315
|
};
|
|
315
|
-
const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), context: deepMerge(context, customContext) });
|
|
316
|
+
const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), writeKey: config.writeKey, context: deepMerge(context, customContext) });
|
|
316
317
|
delete withContext.meta;
|
|
317
318
|
delete withContext.options;
|
|
318
319
|
return withContext;
|
|
319
320
|
}
|
|
320
321
|
function send(method, payload, jitsuConfig, store) {
|
|
322
|
+
if (jitsuConfig.echoEvents) {
|
|
323
|
+
console.log(`[JITSU] sending '${method}' event:`, payload);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
321
326
|
const url = `${jitsuConfig.host}/api/s/${method}`;
|
|
322
327
|
const fetch = jitsuConfig.fetch || globalThis.fetch;
|
|
323
328
|
if (!fetch) {
|
|
324
329
|
throw new Error("Please specify fetch function in jitsu plugin initialization, fetch isn't available in global scope");
|
|
325
330
|
}
|
|
326
|
-
const authHeader =
|
|
331
|
+
const authHeader = {};
|
|
327
332
|
const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
|
|
328
333
|
if (jitsuConfig.debug) {
|
|
329
334
|
console.log(`Sending jitsu event to ${url}: `, JSON.stringify(payload, null, 2));
|
|
@@ -371,8 +376,8 @@
|
|
|
371
376
|
if (config.debug) {
|
|
372
377
|
console.debug("Initializing Jitsu plugin with config: ", JSON.stringify(config));
|
|
373
378
|
}
|
|
374
|
-
if (!config.host) {
|
|
375
|
-
throw new Error("Please specify host variable in jitsu plugin initialization");
|
|
379
|
+
if (!config.host && !config.echoEvents) {
|
|
380
|
+
throw new Error("Please specify host variable in jitsu plugin initialization, or set echoEvents to true");
|
|
376
381
|
}
|
|
377
382
|
},
|
|
378
383
|
page: args => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jitsu/js",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.136",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Jitsu Dev Team <dev@jitsu.com>",
|
|
6
6
|
"main": "dist/jitsu.cjs.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"analytics": "^0.8.1",
|
|
39
|
-
"@jitsu/protocols": "0.0.1-alpha.
|
|
39
|
+
"@jitsu/protocols": "0.0.1-alpha.136"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"clean": "rm -rf ./dist",
|
package/src/analytics-plugin.ts
CHANGED
|
@@ -12,6 +12,7 @@ const config: JitsuOptions = {
|
|
|
12
12
|
host: null,
|
|
13
13
|
debug: false,
|
|
14
14
|
fetch: null,
|
|
15
|
+
echoEvents: false,
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
export const parseQuery = (qs?: string): Record<string, string> => {
|
|
@@ -276,6 +277,7 @@ function adjustPayload(payload: any, config: JitsuOptions, storage: PersistentSt
|
|
|
276
277
|
timestamp: new Date().toISOString(),
|
|
277
278
|
sentAt: new Date().toISOString(),
|
|
278
279
|
messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)),
|
|
280
|
+
writeKey: config.writeKey,
|
|
279
281
|
context: deepMerge(context, customContext),
|
|
280
282
|
};
|
|
281
283
|
delete withContext.meta;
|
|
@@ -284,6 +286,11 @@ function adjustPayload(payload: any, config: JitsuOptions, storage: PersistentSt
|
|
|
284
286
|
}
|
|
285
287
|
|
|
286
288
|
function send(method, payload, jitsuConfig: Required<JitsuOptions>, store: PersistentStorage): Promise<void> {
|
|
289
|
+
if (jitsuConfig.echoEvents) {
|
|
290
|
+
console.log(`[JITSU] sending '${method}' event:`, payload);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
287
294
|
const url = `${jitsuConfig.host}/api/s/${method}`;
|
|
288
295
|
const fetch = jitsuConfig.fetch || globalThis.fetch;
|
|
289
296
|
if (!fetch) {
|
|
@@ -291,7 +298,7 @@ function send(method, payload, jitsuConfig: Required<JitsuOptions>, store: Persi
|
|
|
291
298
|
"Please specify fetch function in jitsu plugin initialization, fetch isn't available in global scope"
|
|
292
299
|
);
|
|
293
300
|
}
|
|
294
|
-
const authHeader =
|
|
301
|
+
const authHeader = {};
|
|
295
302
|
const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
|
|
296
303
|
|
|
297
304
|
if (jitsuConfig.debug) {
|
|
@@ -352,8 +359,8 @@ const jitsuAnalyticsPlugin = (pluginConfig: JitsuOptions = {}): AnalyticsPlugin
|
|
|
352
359
|
if (config.debug) {
|
|
353
360
|
console.debug("Initializing Jitsu plugin with config: ", JSON.stringify(config));
|
|
354
361
|
}
|
|
355
|
-
if (!config.host) {
|
|
356
|
-
throw new Error("Please specify host variable in jitsu plugin initialization");
|
|
362
|
+
if (!config.host && !config.echoEvents) {
|
|
363
|
+
throw new Error("Please specify host variable in jitsu plugin initialization, or set echoEvents to true");
|
|
357
364
|
}
|
|
358
365
|
},
|
|
359
366
|
page: args => {
|
package/src/jitsu.ts
CHANGED
|
@@ -11,10 +11,33 @@ type JitsuOptions = {
|
|
|
11
11
|
* API Host. Default value: same host as script origin
|
|
12
12
|
*/
|
|
13
13
|
host?: string;
|
|
14
|
+
/**
|
|
15
|
+
* To enable debug logging
|
|
16
|
+
*/
|
|
14
17
|
debug?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Explicitely specify cookie domain. If not set, cookie domain will be set to top level
|
|
20
|
+
* of the current domain. Example: if JS lives on "app.example.com", cookie domain will be
|
|
21
|
+
* set to ".example.com". If it lives on "example.com", cookie domain will be set to ".example.com" too
|
|
22
|
+
*/
|
|
15
23
|
cookieDomain?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Provide fetch implementation. It is required if you want to use Jitsu in NodeJS
|
|
26
|
+
*/
|
|
16
27
|
fetch?: typeof fetch;
|
|
28
|
+
/**
|
|
29
|
+
* Which runtime to use. Runtime is used for obtaining context of the event: cookes,
|
|
30
|
+
* url, etc. At the moment, Jitsu supports browser runtime and NodeJS runtime, but you
|
|
31
|
+
* can provide your own implementation.
|
|
32
|
+
*
|
|
33
|
+
* If it's not set, the runtime will be detected automatically by presense of `window` object
|
|
34
|
+
*/
|
|
17
35
|
runtime?: RuntimeFacade;
|
|
36
|
+
/**
|
|
37
|
+
* If set to true, jitsu will output events in console. In this case you don't need to set
|
|
38
|
+
* writeKey / host. It's useful for debugging development environment
|
|
39
|
+
*/
|
|
40
|
+
echoEvents?: boolean;
|
|
18
41
|
};
|
|
19
42
|
|
|
20
43
|
type PersistentStorage = {
|