@usermaven/nextjs 1.4.4 → 1.5.1
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 +4 -4
- package/lib/UsermavenContext.d.ts +0 -1
- package/lib/UsermavenProvider.d.ts +3 -3
- package/lib/UsermavenProvider.js +2 -2
- package/lib/index.es.js +1288 -2577
- package/lib/middlewareEnv.d.ts +1 -1
- package/lib/usePageView.js +38 -12
- package/lib/useUsermaven.d.ts +15 -3
- package/lib/useUsermaven.js +5 -3
- package/package.json +7 -7
package/lib/middlewareEnv.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
-
import { ClientProperties } from "@usermaven/sdk-js
|
|
2
|
+
import { ClientProperties } from "@usermaven/sdk-js";
|
|
3
3
|
declare function middlewareEnv(req: NextRequest, res: NextResponse, opts?: {
|
|
4
4
|
disableCookies?: boolean;
|
|
5
5
|
}): {
|
package/lib/usePageView.js
CHANGED
|
@@ -1,22 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const router = (0, router_1.useRouter)();
|
|
4
|
+
function useUrlChange() {
|
|
5
|
+
const [url, setUrl] = (0, react_1.useState)('');
|
|
7
6
|
(0, react_1.useEffect)(() => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
setUrl(window.location.href);
|
|
8
|
+
const handleUrlChange = () => {
|
|
9
|
+
setUrl(window.location.href);
|
|
10
|
+
};
|
|
11
|
+
window.addEventListener('popstate', handleUrlChange);
|
|
12
|
+
const originalPushState = window.history.pushState;
|
|
13
|
+
const originalReplaceState = window.history.replaceState;
|
|
14
|
+
window.history.pushState = function () {
|
|
15
|
+
originalPushState.apply(this, arguments);
|
|
16
|
+
handleUrlChange();
|
|
17
|
+
};
|
|
18
|
+
window.history.replaceState = function () {
|
|
19
|
+
originalReplaceState.apply(this, arguments);
|
|
20
|
+
handleUrlChange();
|
|
13
21
|
};
|
|
14
|
-
handleRouteChange();
|
|
15
|
-
router.events.on('routeChangeComplete', handleRouteChange);
|
|
16
22
|
return () => {
|
|
17
|
-
|
|
23
|
+
window.removeEventListener('popstate', handleUrlChange);
|
|
24
|
+
window.history.pushState = originalPushState;
|
|
25
|
+
window.history.replaceState = originalReplaceState;
|
|
18
26
|
};
|
|
19
|
-
}, [
|
|
27
|
+
}, []);
|
|
28
|
+
return url;
|
|
29
|
+
}
|
|
30
|
+
function usePageView(usermaven, opts = {}) {
|
|
31
|
+
const url = useUrlChange();
|
|
32
|
+
const trackPageView = (0, react_1.useCallback)(() => {
|
|
33
|
+
if (typeof window === 'undefined') {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (opts.before) {
|
|
37
|
+
opts.before(usermaven);
|
|
38
|
+
}
|
|
39
|
+
usermaven.track((opts === null || opts === void 0 ? void 0 : opts.typeName) || 'pageview', Object.assign(Object.assign({}, opts.payload), { url: window.location.href, path: window.location.pathname, referrer: document.referrer, title: document.title }));
|
|
40
|
+
}, [usermaven, opts.before, opts.typeName, opts.payload]);
|
|
41
|
+
(0, react_1.useEffect)(() => {
|
|
42
|
+
if (url) {
|
|
43
|
+
trackPageView();
|
|
44
|
+
}
|
|
45
|
+
}, [url, trackPageView]);
|
|
20
46
|
return usermaven;
|
|
21
47
|
}
|
|
22
48
|
exports.default = usePageView;
|
package/lib/useUsermaven.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
trackPageView: () =>
|
|
1
|
+
import { EventPayload, UserProps } from "@usermaven/sdk-js";
|
|
2
|
+
export type UsermavenClient = {
|
|
3
|
+
trackPageView: () => void;
|
|
4
|
+
id: (userData: UserProps, doNotSendEvent?: boolean) => Promise<void>;
|
|
5
|
+
track: (typeName: string, payload?: EventPayload) => void;
|
|
6
|
+
rawTrack: (payload: any) => void;
|
|
7
|
+
set: (properties: Record<string, any>, opts?: {
|
|
8
|
+
eventType?: string;
|
|
9
|
+
persist?: boolean;
|
|
10
|
+
}) => void;
|
|
11
|
+
unset: (propertyName: string, opts?: {
|
|
12
|
+
eventType?: string;
|
|
13
|
+
persist?: boolean;
|
|
14
|
+
}) => void;
|
|
4
15
|
};
|
|
16
|
+
declare function useUsermaven(): UsermavenClient;
|
|
5
17
|
export default useUsermaven;
|
package/lib/useUsermaven.js
CHANGED
|
@@ -5,17 +5,19 @@ const UsermavenContext_1 = require("./UsermavenContext");
|
|
|
5
5
|
function useUsermaven() {
|
|
6
6
|
const client = (0, react_1.useContext)(UsermavenContext_1.default);
|
|
7
7
|
if (!client) {
|
|
8
|
-
throw new Error("Before calling useUsermaven() hook, please wrap your component into <
|
|
8
|
+
throw new Error("Before calling useUsermaven() hook, please wrap your component into <UsermavenProvider />. Read more in http://jitsu.com/docs/sending-data/js-sdk/react");
|
|
9
9
|
}
|
|
10
10
|
const id = (0, react_1.useCallback)((userData, doNotSendEvent) => client === null || client === void 0 ? void 0 : client.id(userData, doNotSendEvent), [client]);
|
|
11
11
|
const trackPageView = (0, react_1.useCallback)(() => client === null || client === void 0 ? void 0 : client.track('pageview'), [client]);
|
|
12
12
|
const track = (0, react_1.useCallback)((typeName, payload) => client === null || client === void 0 ? void 0 : client.track(typeName, payload), [client]);
|
|
13
13
|
const rawTrack = (0, react_1.useCallback)((payload) => client === null || client === void 0 ? void 0 : client.rawTrack(payload), [client]);
|
|
14
|
-
const
|
|
14
|
+
const set = (0, react_1.useCallback)((properties, opts) => client === null || client === void 0 ? void 0 : client.set(properties, opts), [client]);
|
|
15
|
+
const unset = (0, react_1.useCallback)((propertyName, opts) => client === null || client === void 0 ? void 0 : client.unset(propertyName, opts), [client]);
|
|
15
16
|
return Object.assign(Object.assign({}, client), { id,
|
|
16
17
|
track,
|
|
17
18
|
trackPageView,
|
|
18
19
|
rawTrack,
|
|
19
|
-
|
|
20
|
+
set,
|
|
21
|
+
unset });
|
|
20
22
|
}
|
|
21
23
|
exports.default = useUsermaven;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usermaven/nextjs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Usermaven JavaScript SDK for NextJS",
|
|
5
5
|
"author": "Usermaven <hello@usermaven.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@usermaven/sdk-js": "
|
|
21
|
+
"@usermaven/sdk-js": "1.5.1",
|
|
22
22
|
"cookie": "^0.5.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"rollup": "^2.70.1",
|
|
36
36
|
"rollup-plugin-peer-deps-external": "^2.2.4"
|
|
37
37
|
},
|
|
38
|
-
"scripts": {
|
|
39
|
-
"build": "rollup -c && tsc",
|
|
40
|
-
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
41
|
-
},
|
|
42
38
|
"repository": {
|
|
43
39
|
"type": "git",
|
|
44
40
|
"url": "https://github.com/usermaven/usermaven-js",
|
|
45
41
|
"directory": "packages/nextjs"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "rollup -c && tsc",
|
|
45
|
+
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
}
|