@jitsu/jitsu-react 0.0.1-alpha.127 → 0.0.1-alpha.136
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +4 -4
- package/dist/index.modern.js.map +1 -1
- package/dist/useJitsu.d.ts +8 -8
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -7,18 +7,18 @@ function useJitsu(opts) {
|
|
|
7
7
|
var _opts$before;
|
|
8
8
|
var cl = React.useContext(JitsuContext);
|
|
9
9
|
if (!cl) {
|
|
10
|
-
if (opts !== null && opts !== void 0 && opts.host) {
|
|
10
|
+
if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
|
|
11
11
|
cl = js.jitsuAnalytics(opts);
|
|
12
12
|
} else {
|
|
13
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");
|
|
14
14
|
}
|
|
15
|
-
} else if (opts !== null && opts !== void 0 && opts.host) {
|
|
15
|
+
} else if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
|
|
16
16
|
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");
|
|
17
17
|
}
|
|
18
18
|
var client = cl;
|
|
19
|
-
var reactLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.reactRouter ? opts.autoPageTracking.reactRouter
|
|
19
|
+
var reactLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.reactRouter ? opts.autoPageTracking.reactRouter : null;
|
|
20
20
|
var before = opts !== null && opts !== void 0 && opts.before ? opts.before.effect : null;
|
|
21
|
-
var nextjsLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.nextjsRouter ? opts.autoPageTracking.nextjsRouter
|
|
21
|
+
var nextjsLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.nextjsRouter ? opts.autoPageTracking.nextjsRouter : null;
|
|
22
22
|
React.useEffect(function () {
|
|
23
23
|
if (before) {
|
|
24
24
|
before(client);
|
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 {
|
|
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 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","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,mBAAa,CAA4B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P,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,IAAMF,SAAS,GAAGpB,QAAQ,CAACsB,KAAK,CAACC,OAAO,CAAC;EACzC,OAAOC,oBAAC1B,YAAY,CAAC2B,QAAQ;IAACC,KAAK,EAAEN,SAAS,CAACA;KAAYE,KAAK,CAACK,QAAQ,CAAyB;AACpG,CAAC;;;;;;"}
|
package/dist/index.modern.js
CHANGED
|
@@ -7,18 +7,18 @@ function useJitsu(opts) {
|
|
|
7
7
|
var _opts$before;
|
|
8
8
|
var cl = useContext(JitsuContext);
|
|
9
9
|
if (!cl) {
|
|
10
|
-
if (opts !== null && opts !== void 0 && opts.host) {
|
|
10
|
+
if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
|
|
11
11
|
cl = jitsuAnalytics(opts);
|
|
12
12
|
} else {
|
|
13
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");
|
|
14
14
|
}
|
|
15
|
-
} else if (opts !== null && opts !== void 0 && opts.host) {
|
|
15
|
+
} else if (opts !== null && opts !== void 0 && opts.host || opts !== null && opts !== void 0 && opts.echoEvents) {
|
|
16
16
|
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");
|
|
17
17
|
}
|
|
18
18
|
var client = cl;
|
|
19
|
-
var reactLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.reactRouter ? opts.autoPageTracking.reactRouter
|
|
19
|
+
var reactLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.reactRouter ? opts.autoPageTracking.reactRouter : null;
|
|
20
20
|
var before = opts !== null && opts !== void 0 && opts.before ? opts.before.effect : null;
|
|
21
|
-
var nextjsLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.nextjsRouter ? opts.autoPageTracking.nextjsRouter
|
|
21
|
+
var nextjsLocationHook = opts !== null && opts !== void 0 && opts.autoPageTracking && opts.autoPageTracking.nextjsRouter ? opts.autoPageTracking.nextjsRouter : null;
|
|
22
22
|
useEffect(function () {
|
|
23
23
|
if (before) {
|
|
24
24
|
before(client);
|
package/dist/index.modern.js.map
CHANGED
|
@@ -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 {
|
|
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 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","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,eAAJA,IAAI,CAAEI,UAAU,EAAE;IACzC,MAAM,IAAIE,KAAK,CACb,2IAA2I,CAC5I;;EAEH,IAAMC,MAAM,GAAGN,EAAE;EAEjB,IAAMO,iBAAiB,GACrBR,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAES,gBAAgB,IAAIT,IAAI,CAACS,gBAAgB,CAACC,WAAW,GAAGV,IAAI,CAACS,gBAAgB,CAACC,WAAW,GAAG,IAAI;EACxG,IAAMC,MAAM,GAAGX,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEW,MAAM,GAAGX,IAAI,CAACW,MAAM,CAACC,MAAM,GAAG,IAAI;EACvD,IAAMC,kBAAkB,GACtBb,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAES,gBAAgB,IAAIT,IAAI,CAACS,gBAAgB,CAACK,YAAY,GAAGd,IAAI,CAACS,gBAAgB,CAACK,YAAY,GAAG,IAAI;EAC1GC,SAAS,CAAC;IACR,IAAIJ,MAAM,EAAE;MACVA,MAAM,CAACJ,MAAM,CAAC;;GAEjB,EAAE,CAAAP,IAAI,aAAJA,IAAI,uCAAJA,IAAI,CAAEW,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;;ACzDA,IAAMa,aAAa,GAAmE,SAAhFA,aAAa,CAA6EC,KAAK;EACnG,IAAMF,SAAS,GAAGpB,QAAQ,CAACsB,KAAK,CAACC,OAAO,CAAC;EACzC,OAAOC,cAAC1B,YAAY,CAAC2B,QAAQ;IAACC,KAAK,EAAEN,SAAS,CAACA;KAAYE,KAAK,CAACK,QAAQ,CAAyB;AACpG,CAAC;;;;"}
|
package/dist/useJitsu.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type { useLocation } from "react-router-dom";
|
|
2
2
|
import type { useRouter } from "next/router";
|
|
3
|
-
import { Union } from "ts-toolbelt";
|
|
4
3
|
import { JitsuOptions, AnalyticsInterface } from "@jitsu/js";
|
|
5
|
-
interface ReactRouterOptions {
|
|
6
|
-
reactRouter: typeof useLocation;
|
|
7
|
-
}
|
|
8
|
-
interface NextJsRouterOptions {
|
|
9
|
-
nextjsRouter: typeof useRouter;
|
|
10
|
-
}
|
|
11
4
|
export interface BeforeEffect {
|
|
12
5
|
effect: (analytics: AnalyticsInterface) => any;
|
|
13
6
|
deps: any[];
|
|
14
7
|
}
|
|
15
|
-
export declare type RouterOptions =
|
|
8
|
+
export declare type RouterOptions = {
|
|
9
|
+
reactRouter: ReturnType<typeof useLocation>;
|
|
10
|
+
nextjsRouter?: never;
|
|
11
|
+
} | {
|
|
12
|
+
reactRouter?: never;
|
|
13
|
+
nextjsRouter: ReturnType<typeof useRouter>;
|
|
14
|
+
};
|
|
16
15
|
export declare type ExtendedJitsuOptions = JitsuOptions & {
|
|
17
16
|
autoPageTracking?: RouterOptions;
|
|
17
|
+
echoEvents?: boolean;
|
|
18
18
|
before?: BeforeEffect;
|
|
19
19
|
};
|
|
20
20
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jitsu/jitsu-react",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.136",
|
|
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.
|
|
14
|
+
"@jitsu/js": "0.0.1-alpha.136"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"react": "15.x || 16.x || 17.x || 18.x",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@types/node": "^18.11.9",
|
|
37
37
|
"microbundle-crl": "^0.13.11",
|
|
38
38
|
"typescript": "^4.9.3",
|
|
39
|
-
"@jitsu/js": "0.0.1-alpha.
|
|
39
|
+
"@jitsu/js": "0.0.1-alpha.136"
|
|
40
40
|
},
|
|
41
41
|
"files": [
|
|
42
42
|
"dist"
|