@visitorquery/react 0.0.8 → 0.0.9
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.d.ts +6 -1
- package/dist/index.js +27 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,5 +8,10 @@ type Params = {
|
|
|
8
8
|
SessionId: string;
|
|
9
9
|
Endpoint?: string;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
type State = {
|
|
12
|
+
Started: boolean;
|
|
13
|
+
Ended: boolean;
|
|
14
|
+
Errored?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare function useVisitorQuery(p: Params): State;
|
|
12
17
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { useEffect as useEffect2 } from "react";
|
|
2
|
+
import { useState as useState2, useEffect as useEffect2 } from "react";
|
|
3
3
|
|
|
4
4
|
// src/hooks.ts
|
|
5
5
|
import * as React from "react";
|
|
@@ -55,15 +55,40 @@ function useVisitorQuery(p) {
|
|
|
55
55
|
const clientScript = useScript("https://cdn.visitorquery.com/visitorquery.js", {
|
|
56
56
|
removeOnUnmount: false
|
|
57
57
|
});
|
|
58
|
+
const [state, setState] = useState2({
|
|
59
|
+
Started: false,
|
|
60
|
+
Ended: false
|
|
61
|
+
});
|
|
58
62
|
useEffect2(() => {
|
|
59
63
|
if (typeof window.VisitorQuery !== "undefined") {
|
|
60
64
|
window.VisitorQuery.run({
|
|
61
65
|
ApiKey: p.ApiKey,
|
|
62
66
|
Endpoint: p.Endpoint || defaultEndpoint,
|
|
63
|
-
SessionId: p.SessionId
|
|
67
|
+
SessionId: p.SessionId,
|
|
68
|
+
onOpen: () => {
|
|
69
|
+
setState({
|
|
70
|
+
Started: true,
|
|
71
|
+
Ended: false
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
onClose: () => {
|
|
75
|
+
setState({
|
|
76
|
+
Started: true,
|
|
77
|
+
Ended: true
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
onError: (err) => {
|
|
81
|
+
setState({
|
|
82
|
+
Started: true,
|
|
83
|
+
Ended: true,
|
|
84
|
+
Errored: true
|
|
85
|
+
});
|
|
86
|
+
console.error(err);
|
|
87
|
+
}
|
|
64
88
|
});
|
|
65
89
|
}
|
|
66
90
|
}, [p, clientScript]);
|
|
91
|
+
return state;
|
|
67
92
|
}
|
|
68
93
|
export {
|
|
69
94
|
useVisitorQuery
|
package/package.json
CHANGED