@visitorquery/react 0.0.16 → 0.0.17
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/README.md +2 -17
- package/dist/index.js +38 -37
- package/dist/provider.d.ts +15 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,20 +14,5 @@ This plugin requires a valid api key (Public api key) and that you provision a s
|
|
|
14
14
|
please visit our website
|
|
15
15
|
at [visitorquery.com](https://visitorquery.com) and pick a suitable plan.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
```typescript
|
|
20
|
-
import {useVisitorQuery} from "@visitorquery/react";
|
|
21
|
-
|
|
22
|
-
export default function LayoutComponent() {
|
|
23
|
-
// visitorquery should be loaded and your visitor assessed
|
|
24
|
-
// to check the result, issue a GET request from your backend
|
|
25
|
-
const visitorQuery = useVisitorQuery({
|
|
26
|
-
// use your project's !!PUBLIC!! api key here
|
|
27
|
-
ApiKey : process.env.NEXT_PUBLIC_VISITOR_QUERY_API_KEY!,
|
|
28
|
-
SessionId: "unique-session-id-to-later-identify-the-visitor",
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
For more info and up to date documentation, please visit our [official page](https://visitorquery.com/docs).
|
|
17
|
+
For more info and up to date documentation, please visit
|
|
18
|
+
our [official docs](https://docs.visitorquery.com/integrations/react) for this plugin.
|
package/dist/index.js
CHANGED
|
@@ -1,80 +1,81 @@
|
|
|
1
1
|
import { jsx as f } from "react/jsx-runtime";
|
|
2
|
-
import * as
|
|
2
|
+
import * as l from "react";
|
|
3
3
|
import { createContext as v, useState as y, useEffect as E, useMemo as S, useContext as w } from "react";
|
|
4
|
-
function V(t,
|
|
5
|
-
const [
|
|
6
|
-
return
|
|
4
|
+
function V(t, i = {}) {
|
|
5
|
+
const [a, r] = l.useState("loading"), d = l.useRef(i);
|
|
6
|
+
return l.useEffect(() => {
|
|
7
7
|
let e = document.querySelector(`script[src="${t}"]`);
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
r(
|
|
8
|
+
const o = e == null ? void 0 : e.getAttribute("data-status");
|
|
9
|
+
if (o) {
|
|
10
|
+
r(o);
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
if (e === null) {
|
|
14
14
|
e = document.createElement("script"), e.src = t, e.async = !0, e.setAttribute("data-status", "loading"), document.body.appendChild(e);
|
|
15
|
-
const
|
|
16
|
-
e == null || e.setAttribute("data-status", "ready"), r("ready"),
|
|
17
|
-
},
|
|
18
|
-
e == null || e.setAttribute("data-status", "error"), r("error"),
|
|
19
|
-
},
|
|
20
|
-
e == null || e.removeEventListener("load",
|
|
15
|
+
const s = () => {
|
|
16
|
+
e == null || e.setAttribute("data-status", "ready"), r("ready"), u();
|
|
17
|
+
}, n = () => {
|
|
18
|
+
e == null || e.setAttribute("data-status", "error"), r("error"), u();
|
|
19
|
+
}, u = () => {
|
|
20
|
+
e == null || e.removeEventListener("load", s), e == null || e.removeEventListener("error", n);
|
|
21
21
|
};
|
|
22
|
-
e.addEventListener("load",
|
|
23
|
-
const
|
|
22
|
+
e.addEventListener("load", s), e.addEventListener("error", n);
|
|
23
|
+
const c = d.current.removeOnUnmount;
|
|
24
24
|
return () => {
|
|
25
|
-
|
|
25
|
+
c === !0 && (e == null || e.remove(), u());
|
|
26
26
|
};
|
|
27
27
|
} else
|
|
28
28
|
r("unknown");
|
|
29
|
-
}, [t]),
|
|
29
|
+
}, [t]), a;
|
|
30
30
|
}
|
|
31
|
-
const
|
|
31
|
+
const m = v(null);
|
|
32
32
|
function L({
|
|
33
33
|
apiKey: t,
|
|
34
|
-
sessionId:
|
|
35
|
-
endpoint:
|
|
36
|
-
children: r
|
|
34
|
+
sessionId: i,
|
|
35
|
+
endpoint: a,
|
|
36
|
+
children: r,
|
|
37
|
+
trigger: d
|
|
37
38
|
}) {
|
|
38
|
-
const
|
|
39
|
+
const e = "main.check.visitorquery.com", o = V("https://cdn.visitorquery.com/visitorquery.js", {
|
|
39
40
|
removeOnUnmount: !1
|
|
40
|
-
}), [
|
|
41
|
+
}), [s, n] = y({
|
|
41
42
|
started: !1,
|
|
42
43
|
ended: !1
|
|
43
44
|
});
|
|
44
45
|
E(() => {
|
|
45
46
|
typeof window.VisitorQuery < "u" && window.VisitorQuery.run({
|
|
46
47
|
ApiKey: t,
|
|
47
|
-
Endpoint:
|
|
48
|
-
SessionId:
|
|
48
|
+
Endpoint: a || e,
|
|
49
|
+
SessionId: i,
|
|
49
50
|
onOpen: () => {
|
|
50
|
-
|
|
51
|
+
n({
|
|
51
52
|
started: !0,
|
|
52
53
|
ended: !1
|
|
53
54
|
});
|
|
54
55
|
},
|
|
55
56
|
onClose: () => {
|
|
56
|
-
|
|
57
|
+
n({
|
|
57
58
|
started: !0,
|
|
58
59
|
ended: !0
|
|
59
60
|
});
|
|
60
61
|
},
|
|
61
|
-
onError: (
|
|
62
|
-
|
|
62
|
+
onError: (c) => {
|
|
63
|
+
n({
|
|
63
64
|
started: !0,
|
|
64
65
|
ended: !0,
|
|
65
66
|
errored: !0
|
|
66
|
-
}), console.error(
|
|
67
|
+
}), console.error(c);
|
|
67
68
|
}
|
|
68
69
|
});
|
|
69
|
-
}, [t, i,
|
|
70
|
-
const
|
|
71
|
-
...
|
|
72
|
-
isLoading:
|
|
73
|
-
}), [
|
|
74
|
-
return /* @__PURE__ */ f(
|
|
70
|
+
}, [t, a, i, o, d]);
|
|
71
|
+
const u = S(() => ({
|
|
72
|
+
...s,
|
|
73
|
+
isLoading: o === "loading"
|
|
74
|
+
}), [s, o]);
|
|
75
|
+
return /* @__PURE__ */ f(m.Provider, { value: u, children: r });
|
|
75
76
|
}
|
|
76
77
|
function Q() {
|
|
77
|
-
const t = w(
|
|
78
|
+
const t = w(m);
|
|
78
79
|
if (!t)
|
|
79
80
|
throw new Error("useVisitorQuery must be used within a VisitorQueryProvider");
|
|
80
81
|
return t;
|
package/dist/provider.d.ts
CHANGED
|
@@ -14,10 +14,24 @@ type VisitorQueryContextType = VisitorQueryState & {
|
|
|
14
14
|
};
|
|
15
15
|
type VisitorQueryProviderProps = {
|
|
16
16
|
apiKey: string;
|
|
17
|
+
/**
|
|
18
|
+
* A unique identifier for the session. This is used in order to later
|
|
19
|
+
* pull results from the VisitorQuery API.
|
|
20
|
+
*/
|
|
17
21
|
sessionId: string;
|
|
22
|
+
/**
|
|
23
|
+
* The endpoint to use for the VisitorQuery script. Useful in cases when
|
|
24
|
+
* you are using custom/vanity domains
|
|
25
|
+
*/
|
|
18
26
|
endpoint?: string;
|
|
19
27
|
children: React.ReactNode;
|
|
28
|
+
/**
|
|
29
|
+
* A trigger that can be used to re-run the VisitorQuery script.
|
|
30
|
+
* This could be a route change or any other event that you want to use to
|
|
31
|
+
* re-initialize the VisitorQuery script.
|
|
32
|
+
*/
|
|
33
|
+
trigger?: string;
|
|
20
34
|
};
|
|
21
|
-
export declare function VisitorQueryProvider({ apiKey, sessionId, endpoint, children }: VisitorQueryProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
export declare function VisitorQueryProvider({ apiKey, sessionId, endpoint, children, trigger }: VisitorQueryProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
22
36
|
export declare function useVisitorQuery(): VisitorQueryContextType;
|
|
23
37
|
export {};
|
package/package.json
CHANGED