@jitsu/jitsu-react 1.0.0-canary-20230211030946 → 1.0.0-canary-20230219230011

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.
@@ -1,4 +1,23 @@
1
1
  /// <reference types="react" />
2
2
  import { AnalyticsInterface } from "@jitsu/js";
3
- declare const JitsuContext: import("react").Context<AnalyticsInterface | null>;
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
@@ -1,5 +1,4 @@
1
1
  var React = require('react');
2
- var src = require('@jitsu/js/compiled/src');
3
2
  var js = require('@jitsu/js');
4
3
 
5
4
  var JitsuContext = React.createContext(null);
@@ -10,71 +9,67 @@ var JitsuProvider = function JitsuProvider(props) {
10
9
  }
11
10
  if (!props.options.host) {
12
11
  var msg = "<JitsuProvider />. Jitsu host is not defined. Jitsu will not be initialized";
13
- console.error("%c" + msg, "color: red; font-size: 16px; font-weight: bold;");
12
+ console.error("%c" + msg, "color: red; font-weight: bold;");
14
13
  console.error(msg);
15
14
  return React.createElement(React.Fragment, null, props.children);
16
15
  }
17
- var analytics = src.jitsuAnalytics(props.options);
18
16
  return React.createElement(JitsuContext.Provider, {
19
- value: analytics
17
+ value: js.isInBrowser() ? {
18
+ analytics: js.jitsuAnalytics(props.options)
19
+ } : {
20
+ initOptions: props.options
21
+ }
20
22
  }, props.children);
21
23
  };
22
24
 
23
25
  var emptyAnalytics = {
24
- analytics: {
25
- track: function track() {
26
- return Promise.resolve();
27
- },
28
- page: function page() {
29
- return Promise.resolve();
30
- },
31
- user: function user() {
32
- return {};
33
- },
34
- identify: function identify() {
35
- return Promise.resolve({});
36
- },
37
- reset: function reset() {
38
- return Promise.resolve({});
39
- }
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({});
40
40
  }
41
41
  };
42
42
  function useJitsu(opts) {
43
- var _opts$before;
43
+ var jitsuInstance = React.useContext(JitsuContext);
44
44
  if (opts !== null && opts !== void 0 && opts.disabled) {
45
- return emptyAnalytics;
45
+ return {
46
+ analytics: emptyAnalytics
47
+ };
46
48
  }
47
- var cl = React.useContext(JitsuContext);
48
- if (!cl) {
49
+ if (!jitsuInstance) {
49
50
  if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
50
- cl = js.jitsuAnalytics(opts);
51
+ return {
52
+ analytics: js.jitsuAnalytics(opts)
53
+ };
51
54
  } else {
52
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";
53
56
  console.error("%c" + msg, "color: red; font-size: 16px; font-weight: bold;");
54
- return emptyAnalytics;
57
+ return {
58
+ analytics: emptyAnalytics
59
+ };
55
60
  }
56
61
  } else if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
57
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
+ };
58
72
  }
59
- var client = cl;
60
- var reactLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.reactRouter ? opts.autoPageTracking.reactRouter : null;
61
- var before = opts !== null && opts !== void 0 && opts.before ? opts.before.effect : null;
62
- var nextjsLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.nextjsRouter ? opts.autoPageTracking.nextjsRouter : null;
63
- React.useEffect(function () {
64
- if (before) {
65
- before(client);
66
- }
67
- }, (opts === null || opts === void 0 ? void 0 : (_opts$before = opts.before) === null || _opts$before === void 0 ? void 0 : _opts$before.deps) || []);
68
- React.useEffect(function () {
69
- if (reactLocationHook) {
70
- client.page();
71
- } else if (nextjsLocationHook) {
72
- client.page();
73
- }
74
- }, [reactLocationHook, nextjsLocationHook === null || nextjsLocationHook === void 0 ? void 0 : nextjsLocationHook.asPath]);
75
- return {
76
- analytics: client
77
- };
78
73
  }
79
74
 
80
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<AnalyticsInterface | null>(null);\n\nexport default JitsuContext;\n","import * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\nimport { jitsuAnalytics } from \"@jitsu/js/compiled/src\";\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-size: 16px; font-weight: bold;\");\n console.error(msg);\n return <React.Fragment>{props.children}</React.Fragment>;\n }\n const analytics = jitsuAnalytics(props.options);\n return <JitsuContext.Provider value={analytics}>{props.children}</JitsuContext.Provider>;\n};\n\nexport default JitsuProvider;\n","import { useContext, useEffect } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\nimport type { useLocation } from \"react-router-dom\";\nimport type { useRouter } from \"next/router\";\n\nimport { AnalyticsInterface, jitsuAnalytics, JitsuOptions } from \"@jitsu/js\";\n\nexport interface BeforeEffect {\n effect: (analytics: AnalyticsInterface) => any;\n deps: any[];\n}\n\nexport type RouterOptions =\n | { reactRouter: ReturnType<typeof useLocation>; nextjsRouter?: never }\n | { reactRouter?: never; nextjsRouter: ReturnType<typeof useRouter> };\n\nexport type ExtendedJitsuOptions =\n | (Omit<JitsuOptions, \"host\"> & { host: string } & {\n disabled?: false | undefined;\n autoPageTracking?: RouterOptions;\n echoEvents?: boolean;\n before?: BeforeEffect;\n })\n | { disabled: true };\n\n\nconst emptyAnalytics = {\n analytics: {\n track: () => Promise.resolve(),\n page: () => Promise.resolve(),\n user: () => ({}),\n identify: () => Promise.resolve({}),\n reset: () => Promise.resolve({}),\n },\n};\n\n/**\n * See for details http://jitsu.com/docs/sending-data/js-sdk/react\n */\nfunction useJitsu(opts?: ExtendedJitsuOptions): { analytics: AnalyticsInterface } {\n if (opts?.disabled) {\n return emptyAnalytics;\n }\n let cl = useContext(JitsuContext);\n if (!cl) {\n if (opts?.host || opts?.echoEvents) {\n cl = 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 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 }\n const client = cl;\n\n const reactLocationHook: ReturnType<typeof useLocation> | null =\n opts?.autoPageTracking && opts.autoPageTracking.reactRouter ? opts.autoPageTracking.reactRouter : null;\n const before = opts?.before ? opts.before.effect : null;\n const nextjsLocationHook =\n opts?.autoPageTracking && opts.autoPageTracking.nextjsRouter ? opts.autoPageTracking.nextjsRouter : null;\n useEffect(() => {\n if (before) {\n before(client);\n }\n }, opts?.before?.deps || []);\n\n useEffect(() => {\n if (reactLocationHook) {\n client.page();\n } else if (nextjsLocationHook) {\n client.page();\n }\n }, [reactLocationHook, nextjsLocationHook?.asPath]);\n\n return { analytics: client };\n}\n\nexport default useJitsu;\nexport { AnalyticsInterface, JitsuOptions };\n"],"names":["JitsuContext","createContext","JitsuProvider","props","options","disabled","React","children","host","msg","console","error","analytics","jitsuAnalytics","Provider","value","emptyAnalytics","track","Promise","resolve","page","user","identify","reset","useJitsu","opts","cl","useContext","echoEvents","Error","client","reactLocationHook","autoPageTracking","reactRouter","before","effect","nextjsLocationHook","nextjsRouter","useEffect","deps","asPath"],"mappings":";;;;AAGA,IAAMA,YAAY,GAAGC,mBAAa,CAA4B,IAAI,CAAC;;ACGnE,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,iDAAiD,CAAC;IAC5EC,OAAO,CAACC,KAAK,CAACF,GAAG,CAAC;IAClB,OAAOH,oBAACA,cAAc,QAAEH,KAAK,CAACI,QAAQ,CAAkB;;EAE1D,IAAMK,SAAS,GAAGC,kBAAc,CAACV,KAAK,C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IAAI,eAAJA,IAAI,CAAEO,gBAAgB,IAAIP,IAAI,CAACO,gBAAgB,CAACC,WAAW,GAAGR,IAAI,CAACO,gBAAgB,CAACC,WAAW,GAAG,IAAI;EACxG,IAAMC,MAAM,GAAGT,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAES,MAAM,GAAGT,IAAI,CAACS,MAAM,CAACC,MAAM,GAAG,IAAI;EACvD,IAAMC,kBAAkB,GACtBX,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEO,gBAAgB,IAAIP,IAAI,CAACO,gBAAgB,CAACK,YAAY,GAAGZ,IAAI,CAACO,gBAAgB,CAACK,YAAY,GAAG,IAAI;EAC1GC,eAAS,CAAC;IACR,IAAIJ,MAAM,EAAE;MACVA,MAAM,CAACJ,MAAM,CAAC;;GAEjB,EAAE,CAAAL,IAAI,aAAJA,IAAI,uCAAJA,IAAI,CAAES,MAAM,iDAAZ,aAAcK,IAAI,KAAI,EAAE,CAAC;EAE5BD,eAAS,CAAC;IACR,IAAIP,iBAAiB,EAAE;MACrBD,MAAM,CAACV,IAAI,EAAE;KACd,MAAM,IAAIgB,kBAAkB,EAAE;MAC7BN,MAAM,CAACV,IAAI,EAAE;;GAEhB,EAAE,CAACW,iBAAiB,EAAEK,kBAAkB,aAAlBA,kBAAkB,uBAAlBA,kBAAkB,CAAEI,MAAM,CAAC,CAAC;EAEnD,OAAO;IAAE5B,SAAS,EAAEkB;GAAQ;AAC9B;;;;;;"}
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,QA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AA2I,CAC5I;GAEF,MAAM,IAAIH,aAAa,CAACb,SAAS,EAAE;IAClC,OAAO;MAAEA,SAAS,EAAEa,aAAa,CAACb;KAAW;GAC9C,MAAM;IACL,IAAMA,SAAS,GAAGa,aAAa,CAACX,WAAW,CAACZ,QAAQ,GAAGa,cAAc,GAAGF,iBAAc,CAACY,aAAa,CAACX,WAAW,CAAC;IACjH,OAAO;MAAEF,SAAS,EAATA;KAAW;;AAExB;;;;;;"}
@@ -1,6 +1,5 @@
1
- import { createContext, createElement, Fragment, useContext, useEffect } from 'react';
2
- import { jitsuAnalytics } from '@jitsu/js/compiled/src';
3
- import { jitsuAnalytics as jitsuAnalytics$1 } from '@jitsu/js';
1
+ import { createContext, createElement, Fragment, useContext } from 'react';
2
+ import { isInBrowser, jitsuAnalytics } from '@jitsu/js';
4
3
 
5
4
  var JitsuContext = createContext(null);
6
5
 
@@ -10,71 +9,67 @@ var JitsuProvider = function JitsuProvider(props) {
10
9
  }
11
10
  if (!props.options.host) {
12
11
  var msg = "<JitsuProvider />. Jitsu host is not defined. Jitsu will not be initialized";
13
- console.error("%c" + msg, "color: red; font-size: 16px; font-weight: bold;");
12
+ console.error("%c" + msg, "color: red; font-weight: bold;");
14
13
  console.error(msg);
15
14
  return createElement(Fragment, null, props.children);
16
15
  }
17
- var analytics = jitsuAnalytics(props.options);
18
16
  return createElement(JitsuContext.Provider, {
19
- value: analytics
17
+ value: isInBrowser() ? {
18
+ analytics: jitsuAnalytics(props.options)
19
+ } : {
20
+ initOptions: props.options
21
+ }
20
22
  }, props.children);
21
23
  };
22
24
 
23
25
  var emptyAnalytics = {
24
- analytics: {
25
- track: function track() {
26
- return Promise.resolve();
27
- },
28
- page: function page() {
29
- return Promise.resolve();
30
- },
31
- user: function user() {
32
- return {};
33
- },
34
- identify: function identify() {
35
- return Promise.resolve({});
36
- },
37
- reset: function reset() {
38
- return Promise.resolve({});
39
- }
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({});
40
40
  }
41
41
  };
42
42
  function useJitsu(opts) {
43
- var _opts$before;
43
+ var jitsuInstance = useContext(JitsuContext);
44
44
  if (opts !== null && opts !== void 0 && opts.disabled) {
45
- return emptyAnalytics;
45
+ return {
46
+ analytics: emptyAnalytics
47
+ };
46
48
  }
47
- var cl = useContext(JitsuContext);
48
- if (!cl) {
49
+ if (!jitsuInstance) {
49
50
  if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
50
- cl = jitsuAnalytics$1(opts);
51
+ return {
52
+ analytics: jitsuAnalytics(opts)
53
+ };
51
54
  } else {
52
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";
53
56
  console.error("%c" + msg, "color: red; font-size: 16px; font-weight: bold;");
54
- return emptyAnalytics;
57
+ return {
58
+ analytics: emptyAnalytics
59
+ };
55
60
  }
56
61
  } else if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
57
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
+ };
58
72
  }
59
- var client = cl;
60
- var reactLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.reactRouter ? opts.autoPageTracking.reactRouter : null;
61
- var before = opts !== null && opts !== void 0 && opts.before ? opts.before.effect : null;
62
- var nextjsLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.nextjsRouter ? opts.autoPageTracking.nextjsRouter : null;
63
- useEffect(function () {
64
- if (before) {
65
- before(client);
66
- }
67
- }, (opts === null || opts === void 0 ? void 0 : (_opts$before = opts.before) === null || _opts$before === void 0 ? void 0 : _opts$before.deps) || []);
68
- useEffect(function () {
69
- if (reactLocationHook) {
70
- client.page();
71
- } else if (nextjsLocationHook) {
72
- client.page();
73
- }
74
- }, [reactLocationHook, nextjsLocationHook === null || nextjsLocationHook === void 0 ? void 0 : nextjsLocationHook.asPath]);
75
- return {
76
- analytics: client
77
- };
78
73
  }
79
74
 
80
75
  export { JitsuContext, JitsuProvider, useJitsu };
@@ -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<AnalyticsInterface | null>(null);\n\nexport default JitsuContext;\n","import * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\nimport { jitsuAnalytics } from \"@jitsu/js/compiled/src\";\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-size: 16px; font-weight: bold;\");\n console.error(msg);\n return <React.Fragment>{props.children}</React.Fragment>;\n }\n const analytics = jitsuAnalytics(props.options);\n return <JitsuContext.Provider value={analytics}>{props.children}</JitsuContext.Provider>;\n};\n\nexport default JitsuProvider;\n","import { useContext, useEffect } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\nimport type { useLocation } from \"react-router-dom\";\nimport type { useRouter } from \"next/router\";\n\nimport { AnalyticsInterface, jitsuAnalytics, JitsuOptions } from \"@jitsu/js\";\n\nexport interface BeforeEffect {\n effect: (analytics: AnalyticsInterface) => any;\n deps: any[];\n}\n\nexport type RouterOptions =\n | { reactRouter: ReturnType<typeof useLocation>; nextjsRouter?: never }\n | { reactRouter?: never; nextjsRouter: ReturnType<typeof useRouter> };\n\nexport type ExtendedJitsuOptions =\n | (Omit<JitsuOptions, \"host\"> & { host: string } & {\n disabled?: false | undefined;\n autoPageTracking?: RouterOptions;\n echoEvents?: boolean;\n before?: BeforeEffect;\n })\n | { disabled: true };\n\n\nconst emptyAnalytics = {\n analytics: {\n track: () => Promise.resolve(),\n page: () => Promise.resolve(),\n user: () => ({}),\n identify: () => Promise.resolve({}),\n reset: () => Promise.resolve({}),\n },\n};\n\n/**\n * See for details http://jitsu.com/docs/sending-data/js-sdk/react\n */\nfunction useJitsu(opts?: ExtendedJitsuOptions): { analytics: AnalyticsInterface } {\n if (opts?.disabled) {\n return emptyAnalytics;\n }\n let cl = useContext(JitsuContext);\n if (!cl) {\n if (opts?.host || opts?.echoEvents) {\n cl = 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 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 }\n const client = cl;\n\n const reactLocationHook: ReturnType<typeof useLocation> | null =\n opts?.autoPageTracking && opts.autoPageTracking.reactRouter ? opts.autoPageTracking.reactRouter : null;\n const before = opts?.before ? opts.before.effect : null;\n const nextjsLocationHook =\n opts?.autoPageTracking && opts.autoPageTracking.nextjsRouter ? opts.autoPageTracking.nextjsRouter : null;\n useEffect(() => {\n if (before) {\n before(client);\n }\n }, opts?.before?.deps || []);\n\n useEffect(() => {\n if (reactLocationHook) {\n client.page();\n } else if (nextjsLocationHook) {\n client.page();\n }\n }, [reactLocationHook, nextjsLocationHook?.asPath]);\n\n return { analytics: client };\n}\n\nexport default useJitsu;\nexport { AnalyticsInterface, JitsuOptions };\n"],"names":["JitsuContext","createContext","JitsuProvider","props","options","disabled","React","children","host","msg","console","error","analytics","jitsuAnalytics","Provider","value","emptyAnalytics","track","Promise","resolve","page","user","identify","reset","useJitsu","opts","cl","useContext","echoEvents","Error","client","reactLocationHook","autoPageTracking","reactRouter","before","effect","nextjsLocationHook","nextjsRouter","useEffect","deps","asPath"],"mappings":";;;;AAGA,IAAMA,YAAY,GAAGC,aAAa,CAA4B,IAAI,CAAC;;ACGnE,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,iDAAiD,CAAC;IAC5EC,OAAO,CAACC,KAAK,CAACF,GAAG,CAAC;IAClB,OAAOH,cAACA,QAAc,QAAEH,KAAK,CAACI,QAAQ,CAAkB;;EAE1D,IAAMK,SAAS,GAAGC,cAAc,CAACV,KAAK,CAACC,OAAO,CAAC;EAC/C,OAAOE,cAACN,YAAY,CAACc,QAAQ;IAACC,KAAK,EAAEH;KAAYT,KAAK,CAACI,QAAQ,CAAyB;AAC1F,CAAC;;ACQD,IAAMS,cAAc,GAAG;EACrBJ,SAAS,EAAE;IACTK,KAAK,EAAE;MAAA,OAAMC,OAAO,CAACC,OAAO,EAAE;;IAC9BC,IAAI,EAAE;MAAA,OAAMF,OAAO,CAACC,OAAO,EAAE;;IAC7BE,IAAI,EAAE;MAAA,OAAO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AgB,IAAIP,IAAI,CAACO,gBAAgB,CAACK,YAAY,GAAGZ,IAAI,CAACO,gBAAgB,CAACK,YAAY,GAAG,IAAI;EAC1GC,SAAS,CAAC;IACR,IAAIJ,MAAM,EAAE;MACVA,MAAM,CAACJ,MAAM,CAAC;;GAEjB,EAAE,CAAAL,IAAI,aAAJA,IAAI,uCAAJA,IAAI,CAAES,MAAM,iDAAZ,aAAcK,IAAI,KAAI,EAAE,CAAC;EAE5BD,SAAS,CAAC;IACR,IAAIP,iBAAiB,EAAE;MACrBD,MAAM,CAACV,IAAI,EAAE;KACd,MAAM,IAAIgB,kBAAkB,EAAE;MAC7BN,MAAM,CAACV,IAAI,EAAE;;GAEhB,EAAE,CAACW,iBAAiB,EAAEK,kBAAkB,aAAlBA,kBAAkB,uBAAlBA,kBAAkB,CAAEI,MAAM,CAAC,CAAC;EAEnD,OAAO;IAAE5B,SAAS,EAAEkB;GAAQ;AAC9B;;;;"}
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,GAAG;MAAEC,SAAS,EAAEC,cAAc,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,EA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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-20230211030946",
3
+ "version": "1.0.0-canary-20230219230011",
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-20230211030946"
14
+ "@jitsu/js": "1.0.0-canary-20230219230011"
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-20230211030946",
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-20230219230011"
40
40
  },
41
41
  "files": [
42
42
  "dist"