@jitsu/jitsu-react 1.0.0-canary-20230211032904 → 1.0.0-canary-20230219230449
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/dist/JitsuContext.d.ts +20 -1
- package/dist/index.js +40 -44
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +42 -46
- package/dist/index.modern.js.map +1 -1
- package/dist/useJitsu.d.ts +0 -11
- package/package.json +4 -4
package/dist/JitsuContext.d.ts
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { AnalyticsInterface } from "@jitsu/js";
|
|
3
|
-
|
|
3
|
+
import { ExtendedJitsuOptions } from "./useJitsu";
|
|
4
|
+
/**
|
|
5
|
+
* An instance if Jitsu that is kept in the context. It's one of:
|
|
6
|
+
* - AnalyticsInterface - for CSR, if Jitsu is initialized in browser
|
|
7
|
+
* - ExtendedJitsuOptions - for SSR, if provider can't access context
|
|
8
|
+
*/
|
|
9
|
+
export declare type JitsuInstance = {
|
|
10
|
+
analytics: AnalyticsInterface;
|
|
11
|
+
initOptions?: never;
|
|
12
|
+
} | {
|
|
13
|
+
analytics?: never;
|
|
14
|
+
initOptions: ExtendedJitsuOptions;
|
|
15
|
+
};
|
|
16
|
+
declare const JitsuContext: import("react").Context<{
|
|
17
|
+
analytics: AnalyticsInterface;
|
|
18
|
+
initOptions?: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
analytics?: undefined;
|
|
21
|
+
initOptions: ExtendedJitsuOptions;
|
|
22
|
+
} | null>;
|
|
4
23
|
export default JitsuContext;
|
package/dist/index.js
CHANGED
|
@@ -9,71 +9,67 @@ var JitsuProvider = function JitsuProvider(props) {
|
|
|
9
9
|
}
|
|
10
10
|
if (!props.options.host) {
|
|
11
11
|
var msg = "<JitsuProvider />. Jitsu host is not defined. Jitsu will not be initialized";
|
|
12
|
-
console.error("%c" + msg, "color: red; font-
|
|
12
|
+
console.error("%c" + msg, "color: red; font-weight: bold;");
|
|
13
13
|
console.error(msg);
|
|
14
14
|
return React.createElement(React.Fragment, null, props.children);
|
|
15
15
|
}
|
|
16
|
-
var analytics = js.jitsuAnalytics(props.options);
|
|
17
16
|
return React.createElement(JitsuContext.Provider, {
|
|
18
|
-
value:
|
|
17
|
+
value: js.isInBrowser() ? {
|
|
18
|
+
analytics: js.jitsuAnalytics(props.options)
|
|
19
|
+
} : {
|
|
20
|
+
initOptions: props.options
|
|
21
|
+
}
|
|
19
22
|
}, props.children);
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
var emptyAnalytics = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return Promise.resolve({});
|
|
38
|
-
}
|
|
26
|
+
track: function track() {
|
|
27
|
+
return Promise.resolve();
|
|
28
|
+
},
|
|
29
|
+
page: function page() {
|
|
30
|
+
return Promise.resolve();
|
|
31
|
+
},
|
|
32
|
+
user: function user() {
|
|
33
|
+
return {};
|
|
34
|
+
},
|
|
35
|
+
identify: function identify() {
|
|
36
|
+
return Promise.resolve({});
|
|
37
|
+
},
|
|
38
|
+
reset: function reset() {
|
|
39
|
+
return Promise.resolve({});
|
|
39
40
|
}
|
|
40
41
|
};
|
|
41
42
|
function useJitsu(opts) {
|
|
42
|
-
var
|
|
43
|
+
var jitsuInstance = React.useContext(JitsuContext);
|
|
43
44
|
if (opts !== null && opts !== void 0 && opts.disabled) {
|
|
44
|
-
return
|
|
45
|
+
return {
|
|
46
|
+
analytics: emptyAnalytics
|
|
47
|
+
};
|
|
45
48
|
}
|
|
46
|
-
|
|
47
|
-
if (!cl) {
|
|
49
|
+
if (!jitsuInstance) {
|
|
48
50
|
if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
|
|
49
|
-
|
|
51
|
+
return {
|
|
52
|
+
analytics: js.jitsuAnalytics(opts)
|
|
53
|
+
};
|
|
50
54
|
} else {
|
|
51
55
|
var msg = "Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react";
|
|
52
56
|
console.error("%c" + msg, "color: red; font-size: 16px; font-weight: bold;");
|
|
53
|
-
return
|
|
57
|
+
return {
|
|
58
|
+
analytics: emptyAnalytics
|
|
59
|
+
};
|
|
54
60
|
}
|
|
55
61
|
} else if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
|
|
56
62
|
throw new Error("Jitsu client already set up with <JitsuProvider /> and cannot be overridden. Read more in http://jitsu.com/docs/sending-data/js-sdk/react");
|
|
63
|
+
} else if (jitsuInstance.analytics) {
|
|
64
|
+
return {
|
|
65
|
+
analytics: jitsuInstance.analytics
|
|
66
|
+
};
|
|
67
|
+
} else {
|
|
68
|
+
var analytics = jitsuInstance.initOptions.disabled ? emptyAnalytics : js.jitsuAnalytics(jitsuInstance.initOptions);
|
|
69
|
+
return {
|
|
70
|
+
analytics: analytics
|
|
71
|
+
};
|
|
57
72
|
}
|
|
58
|
-
var client = cl;
|
|
59
|
-
var reactLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.reactRouter ? opts.autoPageTracking.reactRouter : null;
|
|
60
|
-
var before = opts !== null && opts !== void 0 && opts.before ? opts.before.effect : null;
|
|
61
|
-
var nextjsLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.nextjsRouter ? opts.autoPageTracking.nextjsRouter : null;
|
|
62
|
-
React.useEffect(function () {
|
|
63
|
-
if (before) {
|
|
64
|
-
before(client);
|
|
65
|
-
}
|
|
66
|
-
}, (opts === null || opts === void 0 ? void 0 : (_opts$before = opts.before) === null || _opts$before === void 0 ? void 0 : _opts$before.deps) || []);
|
|
67
|
-
React.useEffect(function () {
|
|
68
|
-
if (reactLocationHook) {
|
|
69
|
-
client.page();
|
|
70
|
-
} else if (nextjsLocationHook) {
|
|
71
|
-
client.page();
|
|
72
|
-
}
|
|
73
|
-
}, [reactLocationHook, nextjsLocationHook === null || nextjsLocationHook === void 0 ? void 0 : nextjsLocationHook.asPath]);
|
|
74
|
-
return {
|
|
75
|
-
analytics: client
|
|
76
|
-
};
|
|
77
73
|
}
|
|
78
74
|
|
|
79
75
|
exports.JitsuContext = JitsuContext;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/JitsuContext.tsx","../src/JitsuProvider.tsx","../src/useJitsu.ts"],"sourcesContent":["import { createContext } from \"react\";\nimport { AnalyticsInterface } from \"@jitsu/js\";\n\nconst JitsuContext = createContext<
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/JitsuContext.tsx","../src/JitsuProvider.tsx","../src/useJitsu.ts"],"sourcesContent":["import { createContext } from \"react\";\nimport { AnalyticsInterface } from \"@jitsu/js\";\nimport { ExtendedJitsuOptions } from \"./useJitsu\";\n\n/**\n * An instance if Jitsu that is kept in the context. It's one of:\n * - AnalyticsInterface - for CSR, if Jitsu is initialized in browser\n * - ExtendedJitsuOptions - for SSR, if provider can't access context\n */\nexport type JitsuInstance =\n | { analytics: AnalyticsInterface; initOptions?: never }\n | { analytics?: never; initOptions: ExtendedJitsuOptions };\n\nconst JitsuContext = createContext<JitsuInstance | null>(null);\n\nexport default JitsuContext;\n","import * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\nimport { jitsuAnalytics, isInBrowser } from \"@jitsu/js\";\nimport { ExtendedJitsuOptions } from \"./useJitsu\";\n\nconst JitsuProvider: React.FC<PropsWithChildren<{ options: ExtendedJitsuOptions }>> = props => {\n if (props.options.disabled) {\n return <React.Fragment>{props.children}</React.Fragment>;\n }\n if (!props.options.host) {\n const msg = \"<JitsuProvider />. Jitsu host is not defined. Jitsu will not be initialized\";\n console.error(`%c${msg}`, \"color: red; font-weight: bold;\");\n console.error(msg);\n return <React.Fragment>{props.children}</React.Fragment>;\n }\n return (\n <JitsuContext.Provider\n value={isInBrowser() ? { analytics: jitsuAnalytics(props.options) } : { initOptions: props.options }}\n >\n {props.children}\n </JitsuContext.Provider>\n );\n};\n\nexport default JitsuProvider;\n","import { useContext } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\n\nimport { AnalyticsInterface, jitsuAnalytics, JitsuOptions } from \"@jitsu/js\";\n\nexport interface BeforeEffect {\n effect: (analytics: AnalyticsInterface) => any;\n deps: any[];\n}\n\nexport type ExtendedJitsuOptions =\n | (Omit<JitsuOptions, \"host\"> & { host: string } & {\n disabled?: false | undefined;\n echoEvents?: boolean;\n })\n | { disabled: true };\n\nconst emptyAnalytics = {\n track: () => Promise.resolve(),\n page: () => Promise.resolve(),\n user: () => ({}),\n identify: () => Promise.resolve({}),\n reset: () => Promise.resolve({}),\n};\n\n/**\n * See for details http://jitsu.com/docs/sending-data/js-sdk/react\n */\nfunction useJitsu(opts?: ExtendedJitsuOptions): { analytics: AnalyticsInterface } {\n let jitsuInstance = useContext(JitsuContext);\n if (opts?.disabled) {\n return { analytics: emptyAnalytics };\n }\n //useJitsu() isn't wrapped into JitsuProvider. Return new instance of Jitsu provider if config is provided\n if (!jitsuInstance) {\n if (opts?.host || opts?.echoEvents) {\n return { analytics: jitsuAnalytics(opts) };\n } else {\n const msg =\n \"Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\";\n console.error(`%c${msg}`, \"color: red; font-size: 16px; font-weight: bold;\");\n return { analytics: emptyAnalytics };\n }\n } else if (opts?.host || opts?.echoEvents) {\n throw new Error(\n \"Jitsu client already set up with <JitsuProvider /> and cannot be overridden. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\"\n );\n //Jitsu analytics is initialized inside provider\n } else if (jitsuInstance.analytics) {\n return { analytics: jitsuInstance.analytics };\n } else {\n const analytics = jitsuInstance.initOptions.disabled ? emptyAnalytics : jitsuAnalytics(jitsuInstance.initOptions);\n return { analytics };\n }\n}\n\nexport default useJitsu;\nexport { AnalyticsInterface, JitsuOptions };\n"],"names":["JitsuContext","createContext","JitsuProvider","props","options","disabled","React","children","host","msg","console","error","Provider","value","isInBrowser","analytics","jitsuAnalytics","initOptions","emptyAnalytics","track","Promise","resolve","page","user","identify","reset","useJitsu","opts","jitsuInstance","useContext","echoEvents","Error"],"mappings":";;;AAaA,IAAMA,YAAY,GAAGC,mBAAa,CAAuB,IAAI,CAAC;;ACP9D,IAAMC,aAAa,GAAmE,SAAhFA,aAAa,CAAmEC,KAAK;EACzF,IAAIA,KAAK,CAACC,OAAO,CAACC,QAAQ,EAAE;IAC1B,OAAOC,oBAACA,cAAc,QAAEH,KAAK,CAACI,QAAQ,CAAkB;;EAE1D,IAAI,CAACJ,KAAK,CAACC,OAAO,CAACI,IAAI,EAAE;IACvB,IAAMC,GAAG,GAAG,6EAA6E;IACzFC,OAAO,CAACC,KAAK,QAAMF,GAAG,EAAI,gCAAgC,CAAC;IAC3DC,OAAO,CAACC,KAAK,CAACF,GAAG,CAAC;IAClB,OAAOH,oBAACA,cAAc,QAAEH,KAAK,CAACI,QAAQ,CAAkB;;EAE1D,OACED,oBAACN,YAAY,CAACY,QAAQ;IACpBC,KAAK,EAAEC,cAAW,EAAE,GAAG;MAAEC,SAAS,EAAEC,iBAAc,CAACb,KAAK,CAACC,OAAO;KAAG,GAAG;MAAEa,WAAW,EAAEd,KAAK,CAACC;;KAE1FD,KAAK,CAACI,QAAQ,CACO;AAE5B,CAAC;;ACND,IAAMW,cAAc,GAAG;EACrBC,KAAK,EAAE;IAAA,OAAMC,OAAO,CAACC,OAAO,EAAE;;EAC9BC,IAAI,EAAE;IAAA,OAAMF,OAAO,CAACC,OAAO,EAAE;;EAC7BE,IAAI,EAAE;IAAA,OAAO,EAAE;GAAC;EAChBC,QAAQ,EAAE;I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alytics } from '@jitsu/js';
|
|
1
|
+
import { createContext, createElement, Fragment, useContext } from 'react';
|
|
2
|
+
import { isInBrowser, jitsuAnalytics } from '@jitsu/js';
|
|
3
3
|
|
|
4
4
|
var JitsuContext = createContext(null);
|
|
5
5
|
|
|
@@ -9,71 +9,67 @@ var JitsuProvider = function JitsuProvider(props) {
|
|
|
9
9
|
}
|
|
10
10
|
if (!props.options.host) {
|
|
11
11
|
var msg = "<JitsuProvider />. Jitsu host is not defined. Jitsu will not be initialized";
|
|
12
|
-
console.error("%c" + msg, "color: red; font-
|
|
12
|
+
console.error("%c" + msg, "color: red; font-weight: bold;");
|
|
13
13
|
console.error(msg);
|
|
14
14
|
return createElement(Fragment, null, props.children);
|
|
15
15
|
}
|
|
16
|
-
var analytics = jitsuAnalytics(props.options);
|
|
17
16
|
return createElement(JitsuContext.Provider, {
|
|
18
|
-
value:
|
|
17
|
+
value: isInBrowser() ? {
|
|
18
|
+
analytics: jitsuAnalytics(props.options)
|
|
19
|
+
} : {
|
|
20
|
+
initOptions: props.options
|
|
21
|
+
}
|
|
19
22
|
}, props.children);
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
var emptyAnalytics = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return Promise.resolve({});
|
|
38
|
-
}
|
|
26
|
+
track: function track() {
|
|
27
|
+
return Promise.resolve();
|
|
28
|
+
},
|
|
29
|
+
page: function page() {
|
|
30
|
+
return Promise.resolve();
|
|
31
|
+
},
|
|
32
|
+
user: function user() {
|
|
33
|
+
return {};
|
|
34
|
+
},
|
|
35
|
+
identify: function identify() {
|
|
36
|
+
return Promise.resolve({});
|
|
37
|
+
},
|
|
38
|
+
reset: function reset() {
|
|
39
|
+
return Promise.resolve({});
|
|
39
40
|
}
|
|
40
41
|
};
|
|
41
42
|
function useJitsu(opts) {
|
|
42
|
-
var
|
|
43
|
+
var jitsuInstance = useContext(JitsuContext);
|
|
43
44
|
if (opts !== null && opts !== void 0 && opts.disabled) {
|
|
44
|
-
return
|
|
45
|
+
return {
|
|
46
|
+
analytics: emptyAnalytics
|
|
47
|
+
};
|
|
45
48
|
}
|
|
46
|
-
|
|
47
|
-
if (!cl) {
|
|
49
|
+
if (!jitsuInstance) {
|
|
48
50
|
if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
|
|
49
|
-
|
|
51
|
+
return {
|
|
52
|
+
analytics: jitsuAnalytics(opts)
|
|
53
|
+
};
|
|
50
54
|
} else {
|
|
51
55
|
var msg = "Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react";
|
|
52
56
|
console.error("%c" + msg, "color: red; font-size: 16px; font-weight: bold;");
|
|
53
|
-
return
|
|
57
|
+
return {
|
|
58
|
+
analytics: emptyAnalytics
|
|
59
|
+
};
|
|
54
60
|
}
|
|
55
61
|
} else if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
|
|
56
62
|
throw new Error("Jitsu client already set up with <JitsuProvider /> and cannot be overridden. Read more in http://jitsu.com/docs/sending-data/js-sdk/react");
|
|
63
|
+
} else if (jitsuInstance.analytics) {
|
|
64
|
+
return {
|
|
65
|
+
analytics: jitsuInstance.analytics
|
|
66
|
+
};
|
|
67
|
+
} else {
|
|
68
|
+
var analytics = jitsuInstance.initOptions.disabled ? emptyAnalytics : jitsuAnalytics(jitsuInstance.initOptions);
|
|
69
|
+
return {
|
|
70
|
+
analytics: analytics
|
|
71
|
+
};
|
|
57
72
|
}
|
|
58
|
-
var client = cl;
|
|
59
|
-
var reactLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.reactRouter ? opts.autoPageTracking.reactRouter : null;
|
|
60
|
-
var before = opts !== null && opts !== void 0 && opts.before ? opts.before.effect : null;
|
|
61
|
-
var nextjsLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.nextjsRouter ? opts.autoPageTracking.nextjsRouter : null;
|
|
62
|
-
useEffect(function () {
|
|
63
|
-
if (before) {
|
|
64
|
-
before(client);
|
|
65
|
-
}
|
|
66
|
-
}, (opts === null || opts === void 0 ? void 0 : (_opts$before = opts.before) === null || _opts$before === void 0 ? void 0 : _opts$before.deps) || []);
|
|
67
|
-
useEffect(function () {
|
|
68
|
-
if (reactLocationHook) {
|
|
69
|
-
client.page();
|
|
70
|
-
} else if (nextjsLocationHook) {
|
|
71
|
-
client.page();
|
|
72
|
-
}
|
|
73
|
-
}, [reactLocationHook, nextjsLocationHook === null || nextjsLocationHook === void 0 ? void 0 : nextjsLocationHook.asPath]);
|
|
74
|
-
return {
|
|
75
|
-
analytics: client
|
|
76
|
-
};
|
|
77
73
|
}
|
|
78
74
|
|
|
79
75
|
export { JitsuContext, JitsuProvider, useJitsu };
|
package/dist/index.modern.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.js","sources":["../src/JitsuContext.tsx","../src/JitsuProvider.tsx","../src/useJitsu.ts"],"sourcesContent":["import { createContext } from \"react\";\nimport { AnalyticsInterface } from \"@jitsu/js\";\n\nconst JitsuContext = createContext<
|
|
1
|
+
{"version":3,"file":"index.modern.js","sources":["../src/JitsuContext.tsx","../src/JitsuProvider.tsx","../src/useJitsu.ts"],"sourcesContent":["import { createContext } from \"react\";\nimport { AnalyticsInterface } from \"@jitsu/js\";\nimport { ExtendedJitsuOptions } from \"./useJitsu\";\n\n/**\n * An instance if Jitsu that is kept in the context. It's one of:\n * - AnalyticsInterface - for CSR, if Jitsu is initialized in browser\n * - ExtendedJitsuOptions - for SSR, if provider can't access context\n */\nexport type JitsuInstance =\n | { analytics: AnalyticsInterface; initOptions?: never }\n | { analytics?: never; initOptions: ExtendedJitsuOptions };\n\nconst JitsuContext = createContext<JitsuInstance | null>(null);\n\nexport default JitsuContext;\n","import * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\nimport { jitsuAnalytics, isInBrowser } from \"@jitsu/js\";\nimport { ExtendedJitsuOptions } from \"./useJitsu\";\n\nconst JitsuProvider: React.FC<PropsWithChildren<{ options: ExtendedJitsuOptions }>> = props => {\n if (props.options.disabled) {\n return <React.Fragment>{props.children}</React.Fragment>;\n }\n if (!props.options.host) {\n const msg = \"<JitsuProvider />. Jitsu host is not defined. Jitsu will not be initialized\";\n console.error(`%c${msg}`, \"color: red; font-weight: bold;\");\n console.error(msg);\n return <React.Fragment>{props.children}</React.Fragment>;\n }\n return (\n <JitsuContext.Provider\n value={isInBrowser() ? { analytics: jitsuAnalytics(props.options) } : { initOptions: props.options }}\n >\n {props.children}\n </JitsuContext.Provider>\n );\n};\n\nexport default JitsuProvider;\n","import { useContext } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\n\nimport { AnalyticsInterface, jitsuAnalytics, JitsuOptions } from \"@jitsu/js\";\n\nexport interface BeforeEffect {\n effect: (analytics: AnalyticsInterface) => any;\n deps: any[];\n}\n\nexport type ExtendedJitsuOptions =\n | (Omit<JitsuOptions, \"host\"> & { host: string } & {\n disabled?: false | undefined;\n echoEvents?: boolean;\n })\n | { disabled: true };\n\nconst emptyAnalytics = {\n track: () => Promise.resolve(),\n page: () => Promise.resolve(),\n user: () => ({}),\n identify: () => Promise.resolve({}),\n reset: () => Promise.resolve({}),\n};\n\n/**\n * See for details http://jitsu.com/docs/sending-data/js-sdk/react\n */\nfunction useJitsu(opts?: ExtendedJitsuOptions): { analytics: AnalyticsInterface } {\n let jitsuInstance = useContext(JitsuContext);\n if (opts?.disabled) {\n return { analytics: emptyAnalytics };\n }\n //useJitsu() isn't wrapped into JitsuProvider. Return new instance of Jitsu provider if config is provided\n if (!jitsuInstance) {\n if (opts?.host || opts?.echoEvents) {\n return { analytics: jitsuAnalytics(opts) };\n } else {\n const msg =\n \"Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\";\n console.error(`%c${msg}`, \"color: red; font-size: 16px; font-weight: bold;\");\n return { analytics: emptyAnalytics };\n }\n } else if (opts?.host || opts?.echoEvents) {\n throw new Error(\n \"Jitsu client already set up with <JitsuProvider /> and cannot be overridden. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\"\n );\n //Jitsu analytics is initialized inside provider\n } else if (jitsuInstance.analytics) {\n return { analytics: jitsuInstance.analytics };\n } else {\n const analytics = jitsuInstance.initOptions.disabled ? emptyAnalytics : jitsuAnalytics(jitsuInstance.initOptions);\n return { analytics };\n }\n}\n\nexport default useJitsu;\nexport { AnalyticsInterface, JitsuOptions };\n"],"names":["JitsuContext","createContext","JitsuProvider","props","options","disabled","React","children","host","msg","console","error","Provider","value","isInBrowser","analytics","jitsuAnalytics","initOptions","emptyAnalytics","track","Promise","resolve","page","user","identify","reset","useJitsu","opts","jitsuInstance","useContext","echoEvents","Error"],"mappings":";;;AAaA,IAAMA,YAAY,GAAGC,aAAa,CAAuB,IAAI,CAAC;;ACP9D,IAAMC,aAAa,GAAmE,SAAhFA,aAAa,CAAmEC,KAAK;EACzF,IAAIA,KAAK,CAACC,OAAO,CAACC,QAAQ,EAAE;IAC1B,OAAOC,cAACA,QAAc,QAAEH,KAAK,CAACI,QAAQ,CAAkB;;EAE1D,IAAI,CAACJ,KAAK,CAACC,OAAO,CAACI,IAAI,EAAE;IACvB,IAAMC,GAAG,GAAG,6EAA6E;IACzFC,OAAO,CAACC,KAAK,QAAMF,GAAG,EAAI,gCAAgC,CAAC;IAC3DC,OAAO,CAACC,KAAK,CAACF,GAAG,CAAC;IAClB,OAAOH,cAACA,QAAc,QAAEH,KAAK,CAACI,QAAQ,CAAkB;;EAE1D,OACED,cAACN,YAAY,CAACY,QAAQ;IACpBC,KAAK,EAAEC,WAAW,EAAE,G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b,SAAS,EAAE;IAClC,OAAO;MAAEA,SAAS,EAAEa,aAAa,CAACb;KAAW;GAC9C,MAAM;IACL,IAAMA,SAAS,GAAGa,aAAa,CAACX,WAAW,CAACZ,QAAQ,GAAGa,cAAc,GAAGF,cAAc,CAACY,aAAa,CAACX,WAAW,CAAC;IACjH,OAAO;MAAEF,SAAS,EAATA;KAAW;;AAExB;;;;"}
|
package/dist/useJitsu.d.ts
CHANGED
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
import type { useLocation } from "react-router-dom";
|
|
2
|
-
import type { useRouter } from "next/router";
|
|
3
1
|
import { AnalyticsInterface, JitsuOptions } from "@jitsu/js";
|
|
4
2
|
export interface BeforeEffect {
|
|
5
3
|
effect: (analytics: AnalyticsInterface) => any;
|
|
6
4
|
deps: any[];
|
|
7
5
|
}
|
|
8
|
-
export declare type RouterOptions = {
|
|
9
|
-
reactRouter: ReturnType<typeof useLocation>;
|
|
10
|
-
nextjsRouter?: never;
|
|
11
|
-
} | {
|
|
12
|
-
reactRouter?: never;
|
|
13
|
-
nextjsRouter: ReturnType<typeof useRouter>;
|
|
14
|
-
};
|
|
15
6
|
export declare type ExtendedJitsuOptions = (Omit<JitsuOptions, "host"> & {
|
|
16
7
|
host: string;
|
|
17
8
|
} & {
|
|
18
9
|
disabled?: false | undefined;
|
|
19
|
-
autoPageTracking?: RouterOptions;
|
|
20
10
|
echoEvents?: boolean;
|
|
21
|
-
before?: BeforeEffect;
|
|
22
11
|
}) | {
|
|
23
12
|
disabled: true;
|
|
24
13
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jitsu/jitsu-react",
|
|
3
|
-
"version": "1.0.0-canary-
|
|
3
|
+
"version": "1.0.0-canary-20230219230449",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"node": ">=10"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@jitsu/js": "1.0.0-canary-
|
|
14
|
+
"@jitsu/js": "1.0.0-canary-20230219230449"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"react": "15.x || 16.x || 17.x || 18.x",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"ts-toolbelt": "^9.6.0",
|
|
32
|
-
"@jitsu/js": "1.0.0-canary-20230211032904",
|
|
33
32
|
"@testing-library/jest-dom": "^5.16.5",
|
|
34
33
|
"@testing-library/react": "^13.4.0",
|
|
35
34
|
"@testing-library/user-event": "^14.4.3",
|
|
36
35
|
"@types/jest": "^29.2.3",
|
|
37
36
|
"@types/node": "^18.11.9",
|
|
38
37
|
"microbundle-crl": "^0.13.11",
|
|
39
|
-
"typescript": "^4.9.3"
|
|
38
|
+
"typescript": "^4.9.3",
|
|
39
|
+
"@jitsu/js": "1.0.0-canary-20230219230449"
|
|
40
40
|
},
|
|
41
41
|
"files": [
|
|
42
42
|
"dist"
|