@jitsu/jitsu-react 0.0.1-alpha.122 → 0.0.1-alpha.126

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,4 @@
1
1
  /// <reference types="react" />
2
- import { AnalyticsInterface } from "@jitsu/protocols/analytics";
2
+ import { AnalyticsInterface } from "@jitsu/js";
3
3
  declare const JitsuContext: import("react").Context<AnalyticsInterface | null>;
4
4
  export default JitsuContext;
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { PropsWithChildren } from "react";
3
- import { JitsuOptions } from "@jitsu/js";
3
+ import { ExtendedJitsuOptions } from "./useJitsu";
4
4
  declare const JitsuProvider: React.FC<PropsWithChildren<{
5
- options: JitsuOptions;
5
+ options: ExtendedJitsuOptions;
6
6
  }>>;
7
7
  export default JitsuProvider;
package/dist/index.js CHANGED
@@ -3,15 +3,8 @@ var js = require('@jitsu/js');
3
3
 
4
4
  var JitsuContext = React.createContext(null);
5
5
 
6
- var JitsuProvider = function JitsuProvider(props) {
7
- var client = js.jitsuAnalytics(props.options);
8
- return React.createElement(JitsuContext.Provider, {
9
- value: client
10
- }, props.children);
11
- };
12
-
13
6
  function useJitsu(opts) {
14
- var _opts$autoPageTrackin;
7
+ var _opts$before;
15
8
  var cl = React.useContext(JitsuContext);
16
9
  if (!cl) {
17
10
  if (opts !== null && opts !== void 0 && opts.host) {
@@ -24,25 +17,32 @@ function useJitsu(opts) {
24
17
  }
25
18
  var client = cl;
26
19
  var reactLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.reactRouter ? opts.autoPageTracking.reactRouter() : null;
27
- var before = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.before ? opts.autoPageTracking.before : null;
20
+ var before = opts !== null && opts !== void 0 && opts.before ? opts.before.effect : null;
28
21
  var nextjsLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.nextjsRouter ? opts.autoPageTracking.nextjsRouter() : null;
29
22
  React.useEffect(function () {
30
23
  if (before) {
31
24
  before(client);
32
25
  }
33
- }, (opts === null || opts === void 0 ? void 0 : (_opts$autoPageTrackin = opts.autoPageTracking) === null || _opts$autoPageTrackin === void 0 ? void 0 : _opts$autoPageTrackin.beforeDeps) || []);
26
+ }, (opts === null || opts === void 0 ? void 0 : (_opts$before = opts.before) === null || _opts$before === void 0 ? void 0 : _opts$before.deps) || []);
34
27
  React.useEffect(function () {
35
28
  if (reactLocationHook) {
36
29
  client.page();
37
30
  } else if (nextjsLocationHook) {
38
31
  client.page();
39
32
  }
40
- }, [reactLocationHook, nextjsLocationHook]);
33
+ }, [reactLocationHook, nextjsLocationHook === null || nextjsLocationHook === void 0 ? void 0 : nextjsLocationHook.asPath]);
41
34
  return {
42
35
  analytics: client
43
36
  };
44
37
  }
45
38
 
39
+ var JitsuProvider = function JitsuProvider(props) {
40
+ var analytics = useJitsu(props.options);
41
+ return React.createElement(JitsuContext.Provider, {
42
+ value: analytics.analytics
43
+ }, props.children);
44
+ };
45
+
46
46
  exports.JitsuContext = JitsuContext;
47
47
  exports.JitsuProvider = JitsuProvider;
48
48
  exports.useJitsu = useJitsu;
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/protocols/analytics\";\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, JitsuOptions } from \"@jitsu/js\";\n\nconst JitsuProvider: React.FC<PropsWithChildren<{ options: JitsuOptions }>> = function (props) {\n const client = jitsuAnalytics(props.options);\n return <JitsuContext.Provider value={client}>{props.children}</JitsuContext.Provider>;\n};\n\nexport default JitsuProvider;\n","import { useContext, useEffect } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\nimport { AnalyticsInterface } from \"@jitsu/protocols/analytics\";\nimport type { useLocation } from \"react-router-dom\";\nimport type { useRouter } from \"next/router\";\n\nimport { Union } from \"ts-toolbelt\";\nimport { jitsuAnalytics, JitsuOptions } from \"@jitsu/js\";\n\ninterface ReactRouterOptions {\n reactRouter: typeof useLocation;\n}\n\ninterface NextJsRouterOptions {\n nextjsRouter: typeof useRouter;\n}\n\ninterface AutoPageTrackingBefore {\n before: (analytics: AnalyticsInterface) => any;\n beforeDeps: any[];\n}\ntype RouterOptions = Union.Strict<ReactRouterOptions | NextJsRouterOptions>;\n\ntype ExtendedJitsuOptions = JitsuOptions & {\n autoPageTracking?: Union.Strict<(RouterOptions & AutoPageTrackingBefore) | RouterOptions>;\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 cl = useContext(JitsuContext);\n if (!cl) {\n if (opts?.host) {\n cl = jitsuAnalytics(opts);\n } else {\n throw new Error(\n \"Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\"\n );\n }\n } else if (opts?.host) {\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 =\n opts?.autoPageTracking && opts.autoPageTracking.reactRouter ? opts.autoPageTracking.reactRouter() : null;\n const before = opts?.autoPageTracking && opts.autoPageTracking.before ? opts.autoPageTracking.before : 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?.autoPageTracking?.beforeDeps || []);\n\n useEffect(() => {\n if (reactLocationHook) {\n client.page();\n } else if (nextjsLocationHook) {\n client.page();\n }\n }, [reactLocationHook, nextjsLocationHook]);\n\n return { analytics: client };\n}\n\nexport default useJitsu;\n"],"names":["JitsuContext","createContext","JitsuProvider","props","client","jitsuAnalytics","options","React","Provider","value","children","useJitsu","opts","cl","useContext","host","Error","reactLocationHook","autoPageTracking","reactRouter","before","nextjsLocationHook","nextjsRouter","useEffect","beforeDeps","page","analytics"],"mappings":";;;AAGA,IAAMA,YAAY,GAAGC,mBAAa,CAA4B,IAAI,CAAC;;ACEnE,IAAMC,aAAa,GAA2D,SAAxEA,aAAa,CAAqEC,KAAK;EAC3F,IAAMC,MAAM,GAAGC,iBAAc,CAACF,KAAK,CAACG,OAAO,CAAC;EAC5C,OAAOC,oBAACP,YAAY,CAACQ,QAAQ;IAACC,KAAK,EAAEL;KAASD,KAAK,CAACO,QAAQ,CAAyB;AACvF,CAAC;;ACsBD,SAASC,QAAQ,CAACC,IAA2B;;EAC3C,IAAIC,EAAE,GAAGC,gBAAU,CAACd,YAAY,CAAC;EACjC,IAAI,CAACa,EAAE,EAAE;IACP,IAAID,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEG,IAAI,EAAE;MACdF,EAAE,GAAGR,iBAAc,CAACO,IAAI,CAAC;KAC1B,MAAM;MACL,MAAM,IAAII,KAAK,CACb,iJAAiJ,CAClJ;;GAEJ,MAAM,IAAIJ,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEG,IAAI,EAAE;IACrB,MAAM,IAAIC,KAAK,CACb,2IAA2I,CAC5I;;EAEH,IAAMZ,MAAM,GAAGS,EAAE;EAEjB,IAAMI,iBAAiB,GACrBL,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEM,gBAAgB,IAAIN,IAAI,CAACM,gBAAgB,CAACC,WAAW,GAAGP,IAAI,CAACM,gBAAgB,CAACC,WAAW,EAAE,GAAG,IAAI;EAC1G,IAAMC,MAAM,GAAGR,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEM,gBAAgB,IAAIN,IAAI,CAACM,gBAAgB,CAACE,MAAM,GAAGR,IAAI,CAACM,gBAAgB,CAACE,MAAM,GAAG,IAAI;EAC3G,IAAMC,kBAAkB,GACtBT,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEM,gBAAgB,IAAIN,IAAI,CAACM,gBAAgB,CAACI,YAAY,GAAGV,IAAI,CAACM,gBAAgB,CAACI,YAAY,EAAE,GAAG,IAAI;EAC5GC,eAAS,CAAC;IACR,IAAIH,MAAM,EAAE;MACVA,MAAM,CAAChB,MAAM,CAAC;;GAEjB,EAAE,CAAAQ,IAAI,aAAJA,IAAI,gDAAJA,IAAI,CAAEM,gBAAgB,0DAAtB,sBAAwBM,UAAU,KAAI,EAAE,CAAC;EAE5CD,eAAS,CAAC;IACR,IAAIN,iBAAiB,EAAE;MACrBb,MAAM,CAACqB,IAAI,EAAE;KACd,MAAM,IAAIJ,kBAAkB,EAAE;MAC7BjB,MAAM,CAACqB,IAAI,EAAE;;GAEhB,EAAE,CAACR,iBAAiB,EAAEI,kBAAkB,CAAC,CAAC;EAE3C,OAAO;IAAEK,SAAS,EAAEtB;GAAQ;AAC9B;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/JitsuContext.tsx","../src/useJitsu.ts","../src/JitsuProvider.tsx"],"sourcesContent":["import { createContext } from \"react\";\nimport { AnalyticsInterface } from \"@jitsu/js\";\n\nconst JitsuContext = createContext<AnalyticsInterface | null>(null);\n\nexport default JitsuContext;\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 { Union } from \"ts-toolbelt\";\nimport { jitsuAnalytics, JitsuOptions, AnalyticsInterface } from \"@jitsu/js\";\n\ninterface ReactRouterOptions {\n reactRouter: typeof useLocation;\n}\n\ninterface NextJsRouterOptions {\n nextjsRouter: typeof useRouter;\n}\n\nexport interface BeforeEffect {\n effect: (analytics: AnalyticsInterface) => any;\n deps: any[];\n}\nexport type RouterOptions = Union.Strict<ReactRouterOptions | NextJsRouterOptions>;\n\nexport type ExtendedJitsuOptions = JitsuOptions & {\n autoPageTracking?: RouterOptions;\n before?: BeforeEffect;\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 cl = useContext(JitsuContext);\n if (!cl) {\n if (opts?.host) {\n cl = jitsuAnalytics(opts);\n } else {\n throw new Error(\n \"Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\"\n );\n }\n } else if (opts?.host) {\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 =\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","import * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\nimport useJitsu, { ExtendedJitsuOptions } from \"./useJitsu\";\n\nconst JitsuProvider: React.FC<PropsWithChildren<{ options: ExtendedJitsuOptions }>> = function (props) {\n const analytics = useJitsu(props.options);\n return <JitsuContext.Provider value={analytics.analytics}>{props.children}</JitsuContext.Provider>;\n};\n\nexport default JitsuProvider;\n"],"names":["JitsuContext","createContext","useJitsu","opts","cl","useContext","host","jitsuAnalytics","Error","client","reactLocationHook","autoPageTracking","reactRouter","before","effect","nextjsLocationHook","nextjsRouter","useEffect","deps","page","asPath","analytics","JitsuProvider","props","options","React","Provider","value","children"],"mappings":";;;AAGA,IAAMA,YAAY,GAAGC,mBAAa,CAA4B,IAAI,CAAC;;AC2BnE,SAASC,QAAQ,CAACC,IAA2B;;EAC3C,IAAIC,EAAE,GAAGC,gBAAU,CAACL,YAAY,CAAC;EACjC,IAAI,CAACI,EAAE,EAAE;IACP,IAAID,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEG,IAAI,EAAE;MACdF,EAAE,GAAGG,iBAAc,CAACJ,IAAI,CAAC;KAC1B,MAAM;MACL,MAAM,IAAIK,KAAK,CACb,iJAAiJ,CAClJ;;GAEJ,MAAM,IAAIL,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEG,IAAI,EAAE;IACrB,MAAM,IAAIE,KAAK,CACb,2IAA2I,CAC5I;;EAEH,IAAMC,MAAM,GAAGL,EAAE;EAEjB,IAAMM,iBAAiB,GACrBP,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEQ,gBAAgB,IAAIR,IAAI,CAACQ,gBAAgB,CAACC,WAAW,GAAGT,IAAI,CAACQ,gBAAgB,CAACC,WAAW,EAAE,GAAG,IAAI;EAC1G,IAAMC,MAAM,GAAGV,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEU,MAAM,GAAGV,IAAI,CAACU,MAAM,CAACC,MAAM,GAAG,IAAI;EACvD,IAAMC,kBAAkB,GACtBZ,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEQ,gBAAgB,IAAIR,IAAI,CAACQ,gBAAgB,CAACK,YAAY,GAAGb,IAAI,CAACQ,gBAAgB,CAACK,YAAY,EAAE,GAAG,IAAI;EAC5GC,eAAS,CAAC;IACR,IAAIJ,MAAM,EAAE;MACVA,MAAM,CAACJ,MAAM,CAAC;;GAEjB,EAAE,CAAAN,IAAI,aAAJA,IAAI,uCAAJA,IAAI,CAAEU,MAAM,iDAAZ,aAAcK,IAAI,KAAI,EAAE,CAAC;EAE5BD,eAAS,CAAC;IACR,IAAIP,iBAAiB,EAAE;MACrBD,MAAM,CAACU,IAAI,EAAE;KACd,MAAM,IAAIJ,kBAAkB,EAAE;MAC7BN,MAAM,CAACU,IAAI,EAAE;;GAEhB,EAAE,CAACT,iBAAiB,EAAEK,kBAAkB,aAAlBA,kBAAkB,uBAAlBA,kBAAkB,CAAEK,MAAM,CAAC,CAAC;EAEnD,OAAO;IAAEC,SAAS,EAAEZ;GAAQ;AAC9B;;AC9DA,IAAMa,aAAa,GAAmE,SAAhFA,aAAa,CAA6EC,KAAK;EACnG,IAAMF,SAAS,GAAGnB,QAAQ,CAACqB,KAAK,CAACC,OAAO,CAAC;EACzC,OAAOC,oBAACzB,YAAY,CAAC0B,QAAQ;IAACC,KAAK,EAAEN,SAAS,CAACA;KAAYE,KAAK,CAACK,QAAQ,CAAyB;AACpG,CAAC;;;;;;"}
@@ -1,17 +1,10 @@
1
- import { createContext, createElement, useContext, useEffect } from 'react';
1
+ import { createContext, useContext, useEffect, createElement } from 'react';
2
2
  import { jitsuAnalytics } from '@jitsu/js';
3
3
 
4
4
  var JitsuContext = createContext(null);
5
5
 
6
- var JitsuProvider = function JitsuProvider(props) {
7
- var client = jitsuAnalytics(props.options);
8
- return createElement(JitsuContext.Provider, {
9
- value: client
10
- }, props.children);
11
- };
12
-
13
6
  function useJitsu(opts) {
14
- var _opts$autoPageTrackin;
7
+ var _opts$before;
15
8
  var cl = useContext(JitsuContext);
16
9
  if (!cl) {
17
10
  if (opts !== null && opts !== void 0 && opts.host) {
@@ -24,24 +17,31 @@ function useJitsu(opts) {
24
17
  }
25
18
  var client = cl;
26
19
  var reactLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.reactRouter ? opts.autoPageTracking.reactRouter() : null;
27
- var before = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.before ? opts.autoPageTracking.before : null;
20
+ var before = opts !== null && opts !== void 0 && opts.before ? opts.before.effect : null;
28
21
  var nextjsLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.nextjsRouter ? opts.autoPageTracking.nextjsRouter() : null;
29
22
  useEffect(function () {
30
23
  if (before) {
31
24
  before(client);
32
25
  }
33
- }, (opts === null || opts === void 0 ? void 0 : (_opts$autoPageTrackin = opts.autoPageTracking) === null || _opts$autoPageTrackin === void 0 ? void 0 : _opts$autoPageTrackin.beforeDeps) || []);
26
+ }, (opts === null || opts === void 0 ? void 0 : (_opts$before = opts.before) === null || _opts$before === void 0 ? void 0 : _opts$before.deps) || []);
34
27
  useEffect(function () {
35
28
  if (reactLocationHook) {
36
29
  client.page();
37
30
  } else if (nextjsLocationHook) {
38
31
  client.page();
39
32
  }
40
- }, [reactLocationHook, nextjsLocationHook]);
33
+ }, [reactLocationHook, nextjsLocationHook === null || nextjsLocationHook === void 0 ? void 0 : nextjsLocationHook.asPath]);
41
34
  return {
42
35
  analytics: client
43
36
  };
44
37
  }
45
38
 
39
+ var JitsuProvider = function JitsuProvider(props) {
40
+ var analytics = useJitsu(props.options);
41
+ return createElement(JitsuContext.Provider, {
42
+ value: analytics.analytics
43
+ }, props.children);
44
+ };
45
+
46
46
  export { JitsuContext, JitsuProvider, useJitsu };
47
47
  //# sourceMappingURL=index.modern.js.map
@@ -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/protocols/analytics\";\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, JitsuOptions } from \"@jitsu/js\";\n\nconst JitsuProvider: React.FC<PropsWithChildren<{ options: JitsuOptions }>> = function (props) {\n const client = jitsuAnalytics(props.options);\n return <JitsuContext.Provider value={client}>{props.children}</JitsuContext.Provider>;\n};\n\nexport default JitsuProvider;\n","import { useContext, useEffect } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\nimport { AnalyticsInterface } from \"@jitsu/protocols/analytics\";\nimport type { useLocation } from \"react-router-dom\";\nimport type { useRouter } from \"next/router\";\n\nimport { Union } from \"ts-toolbelt\";\nimport { jitsuAnalytics, JitsuOptions } from \"@jitsu/js\";\n\ninterface ReactRouterOptions {\n reactRouter: typeof useLocation;\n}\n\ninterface NextJsRouterOptions {\n nextjsRouter: typeof useRouter;\n}\n\ninterface AutoPageTrackingBefore {\n before: (analytics: AnalyticsInterface) => any;\n beforeDeps: any[];\n}\ntype RouterOptions = Union.Strict<ReactRouterOptions | NextJsRouterOptions>;\n\ntype ExtendedJitsuOptions = JitsuOptions & {\n autoPageTracking?: Union.Strict<(RouterOptions & AutoPageTrackingBefore) | RouterOptions>;\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 cl = useContext(JitsuContext);\n if (!cl) {\n if (opts?.host) {\n cl = jitsuAnalytics(opts);\n } else {\n throw new Error(\n \"Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\"\n );\n }\n } else if (opts?.host) {\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 =\n opts?.autoPageTracking && opts.autoPageTracking.reactRouter ? opts.autoPageTracking.reactRouter() : null;\n const before = opts?.autoPageTracking && opts.autoPageTracking.before ? opts.autoPageTracking.before : 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?.autoPageTracking?.beforeDeps || []);\n\n useEffect(() => {\n if (reactLocationHook) {\n client.page();\n } else if (nextjsLocationHook) {\n client.page();\n }\n }, [reactLocationHook, nextjsLocationHook]);\n\n return { analytics: client };\n}\n\nexport default useJitsu;\n"],"names":["JitsuContext","createContext","JitsuProvider","props","client","jitsuAnalytics","options","React","Provider","value","children","useJitsu","opts","cl","useContext","host","Error","reactLocationHook","autoPageTracking","reactRouter","before","nextjsLocationHook","nextjsRouter","useEffect","beforeDeps","page","analytics"],"mappings":";;;AAGA,IAAMA,YAAY,GAAGC,aAAa,CAA4B,IAAI,CAAC;;ACEnE,IAAMC,aAAa,GAA2D,SAAxEA,aAAa,CAAqEC,KAAK;EAC3F,IAAMC,MAAM,GAAGC,cAAc,CAACF,KAAK,CAACG,OAAO,CAAC;EAC5C,OAAOC,cAACP,YAAY,CAACQ,QAAQ;IAACC,KAAK,EAAEL;KAASD,KAAK,CAACO,QAAQ,CAAyB;AACvF,CAAC;;ACsBD,SAASC,QAAQ,CAACC,IAA2B;;EAC3C,IAAIC,EAAE,GAAGC,UAAU,CAACd,YAAY,CAAC;EACjC,IAAI,CAACa,EAAE,EAAE;IACP,IAAID,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEG,IAAI,EAAE;MACdF,EAAE,GAAGR,cAAc,CAACO,IAAI,CAAC;KAC1B,MAAM;MACL,MAAM,IAAII,KAAK,CACb,iJAAiJ,CAClJ;;GAEJ,MAAM,IAAIJ,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEG,IAAI,EAAE;IACrB,MAAM,IAAIC,KAAK,CACb,2IAA2I,CAC5I;;EAEH,IAAMZ,MAAM,GAAGS,EAAE;EAEjB,IAAMI,iBAAiB,GACrBL,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEM,gBAAgB,IAAIN,IAAI,CAACM,gBAAgB,CAACC,WAAW,GAAGP,IAAI,CAACM,gBAAgB,CAACC,WAAW,EAAE,GAAG,IAAI;EAC1G,IAAMC,MAAM,GAAGR,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEM,gBAAgB,IAAIN,IAAI,CAACM,gBAAgB,CAACE,MAAM,GAAGR,IAAI,CAACM,gBAAgB,CAACE,MAAM,GAAG,IAAI;EAC3G,IAAMC,kBAAkB,GACtBT,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEM,gBAAgB,IAAIN,IAAI,CAACM,gBAAgB,CAACI,YAAY,GAAGV,IAAI,CAACM,gBAAgB,CAACI,YAAY,EAAE,GAAG,IAAI;EAC5GC,SAAS,CAAC;IACR,IAAIH,MAAM,EAAE;MACVA,MAAM,CAAChB,MAAM,CAAC;;GAEjB,EAAE,CAAAQ,IAAI,aAAJA,IAAI,gDAAJA,IAAI,CAAEM,gBAAgB,0DAAtB,sBAAwBM,UAAU,KAAI,EAAE,CAAC;EAE5CD,SAAS,CAAC;IACR,IAAIN,iBAAiB,EAAE;MACrBb,MAAM,CAACqB,IAAI,EAAE;KACd,MAAM,IAAIJ,kBAAkB,EAAE;MAC7BjB,MAAM,CAACqB,IAAI,EAAE;;GAEhB,EAAE,CAACR,iBAAiB,EAAEI,kBAAkB,CAAC,CAAC;EAE3C,OAAO;IAAEK,SAAS,EAAEtB;GAAQ;AAC9B;;;;"}
1
+ {"version":3,"file":"index.modern.js","sources":["../src/JitsuContext.tsx","../src/useJitsu.ts","../src/JitsuProvider.tsx"],"sourcesContent":["import { createContext } from \"react\";\nimport { AnalyticsInterface } from \"@jitsu/js\";\n\nconst JitsuContext = createContext<AnalyticsInterface | null>(null);\n\nexport default JitsuContext;\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 { Union } from \"ts-toolbelt\";\nimport { jitsuAnalytics, JitsuOptions, AnalyticsInterface } from \"@jitsu/js\";\n\ninterface ReactRouterOptions {\n reactRouter: typeof useLocation;\n}\n\ninterface NextJsRouterOptions {\n nextjsRouter: typeof useRouter;\n}\n\nexport interface BeforeEffect {\n effect: (analytics: AnalyticsInterface) => any;\n deps: any[];\n}\nexport type RouterOptions = Union.Strict<ReactRouterOptions | NextJsRouterOptions>;\n\nexport type ExtendedJitsuOptions = JitsuOptions & {\n autoPageTracking?: RouterOptions;\n before?: BeforeEffect;\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 cl = useContext(JitsuContext);\n if (!cl) {\n if (opts?.host) {\n cl = jitsuAnalytics(opts);\n } else {\n throw new Error(\n \"Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react\"\n );\n }\n } else if (opts?.host) {\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 =\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","import * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\nimport JitsuContext from \"./JitsuContext\";\nimport useJitsu, { ExtendedJitsuOptions } from \"./useJitsu\";\n\nconst JitsuProvider: React.FC<PropsWithChildren<{ options: ExtendedJitsuOptions }>> = function (props) {\n const analytics = useJitsu(props.options);\n return <JitsuContext.Provider value={analytics.analytics}>{props.children}</JitsuContext.Provider>;\n};\n\nexport default JitsuProvider;\n"],"names":["JitsuContext","createContext","useJitsu","opts","cl","useContext","host","jitsuAnalytics","Error","client","reactLocationHook","autoPageTracking","reactRouter","before","effect","nextjsLocationHook","nextjsRouter","useEffect","deps","page","asPath","analytics","JitsuProvider","props","options","React","Provider","value","children"],"mappings":";;;AAGA,IAAMA,YAAY,GAAGC,aAAa,CAA4B,IAAI,CAAC;;AC2BnE,SAASC,QAAQ,CAACC,IAA2B;;EAC3C,IAAIC,EAAE,GAAGC,UAAU,CAACL,YAAY,CAAC;EACjC,IAAI,CAACI,EAAE,EAAE;IACP,IAAID,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEG,IAAI,EAAE;MACdF,EAAE,GAAGG,cAAc,CAACJ,IAAI,CAAC;KAC1B,MAAM;MACL,MAAM,IAAIK,KAAK,CACb,iJAAiJ,CAClJ;;GAEJ,MAAM,IAAIL,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEG,IAAI,EAAE;IACrB,MAAM,IAAIE,KAAK,CACb,2IAA2I,CAC5I;;EAEH,IAAMC,MAAM,GAAGL,EAAE;EAEjB,IAAMM,iBAAiB,GACrBP,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEQ,gBAAgB,IAAIR,IAAI,CAACQ,gBAAgB,CAACC,WAAW,GAAGT,IAAI,CAACQ,gBAAgB,CAACC,WAAW,EAAE,GAAG,IAAI;EAC1G,IAAMC,MAAM,GAAGV,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEU,MAAM,GAAGV,IAAI,CAACU,MAAM,CAACC,MAAM,GAAG,IAAI;EACvD,IAAMC,kBAAkB,GACtBZ,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEQ,gBAAgB,IAAIR,IAAI,CAACQ,gBAAgB,CAACK,YAAY,GAAGb,IAAI,CAACQ,gBAAgB,CAACK,YAAY,EAAE,GAAG,IAAI;EAC5GC,SAAS,CAAC;IACR,IAAIJ,MAAM,EAAE;MACVA,MAAM,CAACJ,MAAM,CAAC;;GAEjB,EAAE,CAAAN,IAAI,aAAJA,IAAI,uCAAJA,IAAI,CAAEU,MAAM,iDAAZ,aAAcK,IAAI,KAAI,EAAE,CAAC;EAE5BD,SAAS,CAAC;IACR,IAAIP,iBAAiB,EAAE;MACrBD,MAAM,CAACU,IAAI,EAAE;KACd,MAAM,IAAIJ,kBAAkB,EAAE;MAC7BN,MAAM,CAACU,IAAI,EAAE;;GAEhB,EAAE,CAACT,iBAAiB,EAAEK,kBAAkB,aAAlBA,kBAAkB,uBAAlBA,kBAAkB,CAAEK,MAAM,CAAC,CAAC;EAEnD,OAAO;IAAEC,SAAS,EAAEZ;GAAQ;AAC9B;;AC9DA,IAAMa,aAAa,GAAmE,SAAhFA,aAAa,CAA6EC,KAAK;EACnG,IAAMF,SAAS,GAAGnB,QAAQ,CAACqB,KAAK,CAACC,OAAO,CAAC;EACzC,OAAOC,cAACzB,YAAY,CAAC0B,QAAQ;IAACC,KAAK,EAAEN,SAAS,CAACA;KAAYE,KAAK,CAACK,QAAQ,CAAyB;AACpG,CAAC;;;;"}
@@ -1,21 +1,21 @@
1
- import { AnalyticsInterface } from "@jitsu/protocols/analytics";
2
1
  import type { useLocation } from "react-router-dom";
3
2
  import type { useRouter } from "next/router";
4
3
  import { Union } from "ts-toolbelt";
5
- import { JitsuOptions } from "@jitsu/js";
4
+ import { JitsuOptions, AnalyticsInterface } from "@jitsu/js";
6
5
  interface ReactRouterOptions {
7
6
  reactRouter: typeof useLocation;
8
7
  }
9
8
  interface NextJsRouterOptions {
10
9
  nextjsRouter: typeof useRouter;
11
10
  }
12
- interface AutoPageTrackingBefore {
13
- before: (analytics: AnalyticsInterface) => any;
14
- beforeDeps: any[];
11
+ export interface BeforeEffect {
12
+ effect: (analytics: AnalyticsInterface) => any;
13
+ deps: any[];
15
14
  }
16
- declare type RouterOptions = Union.Strict<ReactRouterOptions | NextJsRouterOptions>;
17
- declare type ExtendedJitsuOptions = JitsuOptions & {
18
- autoPageTracking?: Union.Strict<(RouterOptions & AutoPageTrackingBefore) | RouterOptions>;
15
+ export declare type RouterOptions = Union.Strict<ReactRouterOptions | NextJsRouterOptions>;
16
+ export declare type ExtendedJitsuOptions = JitsuOptions & {
17
+ autoPageTracking?: RouterOptions;
18
+ before?: BeforeEffect;
19
19
  };
20
20
  /**
21
21
  * See for details http://jitsu.com/docs/sending-data/js-sdk/react
@@ -24,3 +24,4 @@ declare function useJitsu(opts?: ExtendedJitsuOptions): {
24
24
  analytics: AnalyticsInterface;
25
25
  };
26
26
  export default useJitsu;
27
+ export { AnalyticsInterface, JitsuOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jitsu/jitsu-react",
3
- "version": "0.0.1-alpha.122",
3
+ "version": "0.0.1-alpha.126",
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": "0.0.1-alpha.122"
14
+ "@jitsu/js": "0.0.1-alpha.126"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "react": "15.x || 16.x || 17.x || 18.x",
@@ -39,8 +39,7 @@
39
39
  "microbundle-crl": "^0.13.11",
40
40
  "react": "^18.2.0",
41
41
  "typescript": "^4.9.3",
42
- "@jitsu/js": "0.0.1-alpha.122",
43
- "@jitsu/protocols": "0.0.1-alpha.122"
42
+ "@jitsu/js": "0.0.1-alpha.126"
44
43
  },
45
44
  "files": [
46
45
  "dist"