@usermaven/react 1.4.4 → 1.5.0-rc.90
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 -2
- package/lib/UsermavenContext.d.ts +0 -1
- package/lib/UsermavenProvider.d.ts +2 -2
- package/lib/UsermavenProvider.js +1 -1
- package/lib/index.es.js +1287 -2570
- package/lib/usePageView.d.ts +2 -1
- package/lib/usePageView.js +43 -7
- package/lib/useUsermaven.d.ts +15 -3
- package/lib/useUsermaven.js +0 -2
- package/package.json +7 -7
package/lib/usePageView.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UsermavenClient } from "./useUsermaven";
|
|
2
|
+
import { EventPayload } from "@usermaven/sdk-js";
|
|
2
3
|
declare function usePageView(opts?: {
|
|
3
4
|
before?: (usermaven: UsermavenClient) => void;
|
|
4
5
|
typeName?: string;
|
package/lib/usePageView.js
CHANGED
|
@@ -1,17 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
|
-
const react_router_1 = require("react-router");
|
|
5
4
|
const useUsermaven_1 = require("./useUsermaven");
|
|
5
|
+
function useUrlChange() {
|
|
6
|
+
const [url, setUrl] = (0, react_1.useState)(window.location.href);
|
|
7
|
+
const lastUrlRef = (0, react_1.useRef)(window.location.href);
|
|
8
|
+
(0, react_1.useEffect)(() => {
|
|
9
|
+
const handleUrlChange = () => {
|
|
10
|
+
const currentUrl = window.location.href;
|
|
11
|
+
if (currentUrl !== lastUrlRef.current) {
|
|
12
|
+
lastUrlRef.current = currentUrl;
|
|
13
|
+
setUrl(currentUrl);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
window.addEventListener('popstate', handleUrlChange);
|
|
17
|
+
const originalPushState = window.history.pushState;
|
|
18
|
+
const originalReplaceState = window.history.replaceState;
|
|
19
|
+
window.history.pushState = function () {
|
|
20
|
+
originalPushState.apply(this, arguments);
|
|
21
|
+
handleUrlChange();
|
|
22
|
+
};
|
|
23
|
+
window.history.replaceState = function () {
|
|
24
|
+
originalReplaceState.apply(this, arguments);
|
|
25
|
+
handleUrlChange();
|
|
26
|
+
};
|
|
27
|
+
return () => {
|
|
28
|
+
window.removeEventListener('popstate', handleUrlChange);
|
|
29
|
+
window.history.pushState = originalPushState;
|
|
30
|
+
window.history.replaceState = originalReplaceState;
|
|
31
|
+
};
|
|
32
|
+
}, []);
|
|
33
|
+
return url;
|
|
34
|
+
}
|
|
6
35
|
function usePageView(opts = {}) {
|
|
7
|
-
|
|
36
|
+
const url = useUrlChange();
|
|
8
37
|
const usermaven = (0, useUsermaven_1.default)();
|
|
9
|
-
(0, react_1.
|
|
10
|
-
|
|
11
|
-
|
|
38
|
+
const lastTrackedUrl = (0, react_1.useRef)('');
|
|
39
|
+
const trackPageView = (0, react_1.useCallback)(() => {
|
|
40
|
+
if (url !== lastTrackedUrl.current) {
|
|
41
|
+
if (opts.before) {
|
|
42
|
+
opts.before(usermaven);
|
|
43
|
+
}
|
|
44
|
+
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 }));
|
|
45
|
+
lastTrackedUrl.current = url;
|
|
12
46
|
}
|
|
13
|
-
|
|
14
|
-
|
|
47
|
+
}, [usermaven, url, opts.before, opts.typeName, opts.payload]);
|
|
48
|
+
(0, react_1.useEffect)(() => {
|
|
49
|
+
trackPageView();
|
|
50
|
+
}, [url, trackPageView]);
|
|
15
51
|
return usermaven;
|
|
16
52
|
}
|
|
17
53
|
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
|
@@ -11,14 +11,12 @@ function useUsermaven() {
|
|
|
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 interceptAnalytics = (0, react_1.useCallback)((analytics) => client === null || client === void 0 ? void 0 : client.interceptAnalytics(analytics), [client]);
|
|
15
14
|
const set = (0, react_1.useCallback)((properties, opts) => client === null || client === void 0 ? void 0 : client.set(properties, opts), [client]);
|
|
16
15
|
const unset = (0, react_1.useCallback)((propertyName, opts) => client === null || client === void 0 ? void 0 : client.unset(propertyName, opts), [client]);
|
|
17
16
|
return Object.assign(Object.assign({}, client), { id,
|
|
18
17
|
track,
|
|
19
18
|
trackPageView,
|
|
20
19
|
rawTrack,
|
|
21
|
-
interceptAnalytics,
|
|
22
20
|
set,
|
|
23
21
|
unset });
|
|
24
22
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usermaven/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0-rc.90",
|
|
4
4
|
"description": "Usermaven JavaScript SDK for React",
|
|
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.0-rc.90"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": "15.x || 16.x || 17.x || 18.x",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"rollup": "^2.70.1",
|
|
35
35
|
"rollup-plugin-peer-deps-external": "^2.2.4"
|
|
36
36
|
},
|
|
37
|
-
"scripts": {
|
|
38
|
-
"build": "rollup -c && tsc",
|
|
39
|
-
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
40
|
-
},
|
|
41
37
|
"repository": {
|
|
42
38
|
"type": "git",
|
|
43
39
|
"url": "https://github.com/usermaven/usermaven-js",
|
|
44
40
|
"directory": "packages/react"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "rollup -c && tsc",
|
|
44
|
+
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
}
|