@jitsu/jitsu-react 0.0.1-alpha.183 → 1.0.0-canary-20230211032904

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/index.js CHANGED
@@ -3,14 +3,54 @@ var js = require('@jitsu/js');
3
3
 
4
4
  var JitsuContext = React.createContext(null);
5
5
 
6
+ var JitsuProvider = function JitsuProvider(props) {
7
+ if (props.options.disabled) {
8
+ return React.createElement(React.Fragment, null, props.children);
9
+ }
10
+ if (!props.options.host) {
11
+ var msg = "<JitsuProvider />. Jitsu host is not defined. Jitsu will not be initialized";
12
+ console.error("%c" + msg, "color: red; font-size: 16px; font-weight: bold;");
13
+ console.error(msg);
14
+ return React.createElement(React.Fragment, null, props.children);
15
+ }
16
+ var analytics = js.jitsuAnalytics(props.options);
17
+ return React.createElement(JitsuContext.Provider, {
18
+ value: analytics
19
+ }, props.children);
20
+ };
21
+
22
+ var emptyAnalytics = {
23
+ analytics: {
24
+ track: function track() {
25
+ return Promise.resolve();
26
+ },
27
+ page: function page() {
28
+ return Promise.resolve();
29
+ },
30
+ user: function user() {
31
+ return {};
32
+ },
33
+ identify: function identify() {
34
+ return Promise.resolve({});
35
+ },
36
+ reset: function reset() {
37
+ return Promise.resolve({});
38
+ }
39
+ }
40
+ };
6
41
  function useJitsu(opts) {
7
42
  var _opts$before;
43
+ if (opts !== null && opts !== void 0 && opts.disabled) {
44
+ return emptyAnalytics;
45
+ }
8
46
  var cl = React.useContext(JitsuContext);
9
47
  if (!cl) {
10
48
  if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
11
49
  cl = js.jitsuAnalytics(opts);
12
50
  } else {
13
- throw new Error("Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react");
51
+ 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
+ console.error("%c" + msg, "color: red; font-size: 16px; font-weight: bold;");
53
+ return emptyAnalytics;
14
54
  }
15
55
  } else if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
16
56
  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");
@@ -36,17 +76,6 @@ function useJitsu(opts) {
36
76
  };
37
77
  }
38
78
 
39
- var JitsuProvider = function JitsuProvider(props) {
40
- if (props.options.host) {
41
- var analytics = useJitsu(props.options);
42
- return React.createElement(JitsuContext.Provider, {
43
- value: analytics.analytics
44
- }, props.children);
45
- } else {
46
- return React.createElement("div", null, props.children);
47
- }
48
- };
49
-
50
79
  exports.JitsuContext = JitsuContext;
51
80
  exports.JitsuProvider = JitsuProvider;
52
81
  exports.useJitsu = useJitsu;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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 { jitsuAnalytics, JitsuOptions, AnalyticsInterface } 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 = JitsuOptions & {\n autoPageTracking?: RouterOptions;\n echoEvents?: boolean;\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 || opts?.echoEvents) {\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 || 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","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 if (props.options.host) {\n const analytics = useJitsu(props.options);\n return <JitsuContext.Provider value={analytics.analytics}>{props.children}</JitsuContext.Provider>;\n } else {\n return <div>{props.children}</div>;\n }\n};\n\nexport default JitsuProvider;\n"],"names":["JitsuContext","createContext","useJitsu","opts","cl","useContext","host","echoEvents","jitsuAnalytics","Error","client","reactLocationHook","autoPageTracking","reactRouter","before","effect","nextjsLocationHook","nextjsRouter","useEffect","deps","page","asPath","analytics","JitsuProvider","props","options","React","Provider","value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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;;ACzDA,IAAMa,aAAa,GAAmE,SAAhFA,aAAa,CAA6EC,KAAK;EACnG,IAAIA,KAAK,CAACC,OAAO,CAACnB,IAAI,EAAE;IACtB,IAAMgB,SAAS,GAAGpB,QAAQ,CAACsB,KAAK,CAACC,OAAO,CAAC;IACzC,OAAOC,oBAAC1B,YAAY,CAAC2B,QAAQ;MAACC,KAAK,EAAEN,SAAS,CAACA;OAAYE,KAAK,CAACK,QAAQ,CAAyB;GACnG,MAAM;IACL,OAAOH,iCAAMF,KAAK,CAACK,QAAQ,CAAO;;AAEtC,CAAC;;;;;;"}
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\";\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\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,iBAAc,CAACV,KAAK,CAACC,OAAO,CAAC;EAC/C,OAAOE,oBAACN,YAAY,CAACc,QAAQ;IA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B,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,16 +1,56 @@
1
- import { createContext, useContext, useEffect, createElement } from 'react';
1
+ import { createContext, createElement, Fragment, useContext, useEffect } 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
+ if (props.options.disabled) {
8
+ return createElement(Fragment, null, props.children);
9
+ }
10
+ if (!props.options.host) {
11
+ var msg = "<JitsuProvider />. Jitsu host is not defined. Jitsu will not be initialized";
12
+ console.error("%c" + msg, "color: red; font-size: 16px; font-weight: bold;");
13
+ console.error(msg);
14
+ return createElement(Fragment, null, props.children);
15
+ }
16
+ var analytics = jitsuAnalytics(props.options);
17
+ return createElement(JitsuContext.Provider, {
18
+ value: analytics
19
+ }, props.children);
20
+ };
21
+
22
+ var emptyAnalytics = {
23
+ analytics: {
24
+ track: function track() {
25
+ return Promise.resolve();
26
+ },
27
+ page: function page() {
28
+ return Promise.resolve();
29
+ },
30
+ user: function user() {
31
+ return {};
32
+ },
33
+ identify: function identify() {
34
+ return Promise.resolve({});
35
+ },
36
+ reset: function reset() {
37
+ return Promise.resolve({});
38
+ }
39
+ }
40
+ };
6
41
  function useJitsu(opts) {
7
42
  var _opts$before;
43
+ if (opts !== null && opts !== void 0 && opts.disabled) {
44
+ return emptyAnalytics;
45
+ }
8
46
  var cl = useContext(JitsuContext);
9
47
  if (!cl) {
10
48
  if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
11
49
  cl = jitsuAnalytics(opts);
12
50
  } else {
13
- throw new Error("Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react");
51
+ 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
+ console.error("%c" + msg, "color: red; font-size: 16px; font-weight: bold;");
53
+ return emptyAnalytics;
14
54
  }
15
55
  } else if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
16
56
  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");
@@ -36,16 +76,5 @@ function useJitsu(opts) {
36
76
  };
37
77
  }
38
78
 
39
- var JitsuProvider = function JitsuProvider(props) {
40
- if (props.options.host) {
41
- var analytics = useJitsu(props.options);
42
- return createElement(JitsuContext.Provider, {
43
- value: analytics.analytics
44
- }, props.children);
45
- } else {
46
- return createElement("div", null, props.children);
47
- }
48
- };
49
-
50
79
  export { JitsuContext, JitsuProvider, useJitsu };
51
80
  //# sourceMappingURL=index.modern.js.map
@@ -1 +1 @@
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 { jitsuAnalytics, JitsuOptions, AnalyticsInterface } 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 = JitsuOptions & {\n autoPageTracking?: RouterOptions;\n echoEvents?: boolean;\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 || opts?.echoEvents) {\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 || 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","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 if (props.options.host) {\n const analytics = useJitsu(props.options);\n return <JitsuContext.Provider value={analytics.analytics}>{props.children}</JitsuContext.Provider>;\n } else {\n return <div>{props.children}</div>;\n }\n};\n\nexport default JitsuProvider;\n"],"names":["JitsuContext","createContext","useJitsu","opts","cl","useContext","host","echoEvents","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;;ACsBnE,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,IAAIH,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEI,UAAU,EAAE;MAClCH,EAAE,GAAGI,cAAc,CAACL,IAAI,CAAC;KAC1B,MAAM;MACL,MAAM,IAAIM,KAAK,CACb,iJAAiJ,CAClJ;;GAEJ,MAAM,IAAIN,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEG,IAAI,IAAIH,IAAI,aAAJA,IAAI,eAA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AAOC,cAAC1B,YAAY,CAAC2B,QAAQ;MAACC,KAAK,EAAEN,SAAS,CAACA;OAAYE,KAAK,CAACK,QAAQ,CAAyB;GACnG,MAAM;IACL,OAAOH,2BAAMF,KAAK,CAACK,QAAQ,CAAO;;AAEtC,CAAC;;;;"}
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\";\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\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;;ACOD,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,EAAE;KAAC;IAChBC,QAAQ,EAAE;MAAA,OAAMJ,OAAO,CAACC,OAAO,CAAC,EAAE,CAAC;;IACnCI,KAAK,EAAE;MAAA,OAAML,OAAO,CAACC,OAAO,CAAC,EAAE,CAAC;;;CAEnC;AAKD,SAASK,QAAQ,CAACC,IAA2B;;EAC3C,IAAIA,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEpB,QA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K,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,6 +1,6 @@
1
1
  import type { useLocation } from "react-router-dom";
2
2
  import type { useRouter } from "next/router";
3
- import { JitsuOptions, AnalyticsInterface } from "@jitsu/js";
3
+ import { AnalyticsInterface, JitsuOptions } from "@jitsu/js";
4
4
  export interface BeforeEffect {
5
5
  effect: (analytics: AnalyticsInterface) => any;
6
6
  deps: any[];
@@ -12,10 +12,15 @@ export declare type RouterOptions = {
12
12
  reactRouter?: never;
13
13
  nextjsRouter: ReturnType<typeof useRouter>;
14
14
  };
15
- export declare type ExtendedJitsuOptions = JitsuOptions & {
15
+ export declare type ExtendedJitsuOptions = (Omit<JitsuOptions, "host"> & {
16
+ host: string;
17
+ } & {
18
+ disabled?: false | undefined;
16
19
  autoPageTracking?: RouterOptions;
17
20
  echoEvents?: boolean;
18
21
  before?: BeforeEffect;
22
+ }) | {
23
+ disabled: true;
19
24
  };
20
25
  /**
21
26
  * See for details http://jitsu.com/docs/sending-data/js-sdk/react
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jitsu/jitsu-react",
3
- "version": "0.0.1-alpha.183",
3
+ "version": "1.0.0-canary-20230211032904",
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.183"
14
+ "@jitsu/js": "1.0.0-canary-20230211032904"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "react": "15.x || 16.x || 17.x || 18.x",
@@ -29,20 +29,21 @@
29
29
  },
30
30
  "devDependencies": {
31
31
  "ts-toolbelt": "^9.6.0",
32
+ "@jitsu/js": "1.0.0-canary-20230211032904",
32
33
  "@testing-library/jest-dom": "^5.16.5",
33
34
  "@testing-library/react": "^13.4.0",
34
35
  "@testing-library/user-event": "^14.4.3",
35
36
  "@types/jest": "^29.2.3",
36
37
  "@types/node": "^18.11.9",
37
38
  "microbundle-crl": "^0.13.11",
38
- "typescript": "^4.9.3",
39
- "@jitsu/js": "0.0.1-alpha.183"
39
+ "typescript": "^4.9.3"
40
40
  },
41
41
  "files": [
42
42
  "dist"
43
43
  ],
44
44
  "scripts": {
45
45
  "build": "microbundle-crl --no-compress --format es,cjs",
46
- "compile": "tsc -p ."
46
+ "compile": "tsc -p .",
47
+ "clean": "rm -rf dist"
47
48
  }
48
49
  }
package/dist/client.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { JitsuOptions } from "@jitsu/js";
2
- import { AnalyticsInterface } from "@jitsu/protocols/analytics";
3
- declare function createClient(params: JitsuOptions): AnalyticsInterface;
4
- export default createClient;
package/dist/index.es.js DELETED
@@ -1,47 +0,0 @@
1
- import { createContext, createElement, useContext, useEffect } from 'react';
2
- import { jitsuAnalytics } from '@jitsu/js';
3
-
4
- var JitsuContext = createContext(null);
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
- function useJitsu(opts) {
14
- var _opts$autoPageTrackin;
15
- var cl = useContext(JitsuContext);
16
- if (!cl) {
17
- if (opts !== null && opts !== void 0 && opts.host) {
18
- cl = jitsuAnalytics(opts);
19
- } else {
20
- throw new Error("Before calling useJitsu() hook, please wrap your component into <JitsuProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react");
21
- }
22
- } else if (opts !== null && opts !== void 0 && opts.host) {
23
- 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");
24
- }
25
- var client = cl;
26
- 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;
28
- var nextjsLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.nextjsRouter ? opts.autoPageTracking.nextjsRouter() : null;
29
- useEffect(function () {
30
- if (before) {
31
- before(client);
32
- }
33
- }, (opts === null || opts === void 0 ? void 0 : (_opts$autoPageTrackin = opts.autoPageTracking) === null || _opts$autoPageTrackin === void 0 ? void 0 : _opts$autoPageTrackin.beforeDeps) || []);
34
- useEffect(function () {
35
- if (reactLocationHook) {
36
- client.page();
37
- } else if (nextjsLocationHook) {
38
- client.page();
39
- }
40
- }, [reactLocationHook, nextjsLocationHook]);
41
- return {
42
- analytics: client
43
- };
44
- }
45
-
46
- export { JitsuContext, JitsuProvider, useJitsu };
47
- //# sourceMappingURL=index.es.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/JitsuContext.tsx","../src/JitsuProvider.tsx","../src/useJitsu.ts"],"sourcesContent":["import { createContext } from 'react'\nimport { AnalyticsInterface } from \"@jitsu/types/analytics\";\n\n\nconst JitsuContext = createContext<AnalyticsInterface | null>(null)\n\nexport default JitsuContext","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/types/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":";;;AAIA,IAAMA,YAAY,GAAGC,aAAa,CAA4B,IAAI,CAAC;;ACCnE,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,GAAG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