@easyfunnel/react 0.1.0
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.mts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +115 -0
- package/dist/index.mjs +93 -0
- package/package.json +33 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { EasyFunnelOptions, Tracker } from '@easyfunnel/sdk';
|
|
4
|
+
|
|
5
|
+
interface EasyFunnelProviderProps extends Omit<EasyFunnelOptions, 'autoPageView'> {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
declare function EasyFunnelProvider({ children, ...options }: EasyFunnelProviderProps): react_jsx_runtime.JSX.Element;
|
|
9
|
+
declare function useEasyFunnel(): Tracker | null;
|
|
10
|
+
|
|
11
|
+
declare function useTrack(): (eventName: string, properties?: Record<string, any>) => void;
|
|
12
|
+
declare function useIdentify(): (userId: string) => void;
|
|
13
|
+
|
|
14
|
+
export { EasyFunnelProvider, useEasyFunnel, useIdentify, useTrack };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { EasyFunnelOptions, Tracker } from '@easyfunnel/sdk';
|
|
4
|
+
|
|
5
|
+
interface EasyFunnelProviderProps extends Omit<EasyFunnelOptions, 'autoPageView'> {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
declare function EasyFunnelProvider({ children, ...options }: EasyFunnelProviderProps): react_jsx_runtime.JSX.Element;
|
|
9
|
+
declare function useEasyFunnel(): Tracker | null;
|
|
10
|
+
|
|
11
|
+
declare function useTrack(): (eventName: string, properties?: Record<string, any>) => void;
|
|
12
|
+
declare function useIdentify(): (userId: string) => void;
|
|
13
|
+
|
|
14
|
+
export { EasyFunnelProvider, useEasyFunnel, useIdentify, useTrack };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __objRest = (source, exclude) => {
|
|
24
|
+
var target = {};
|
|
25
|
+
for (var prop in source)
|
|
26
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
27
|
+
target[prop] = source[prop];
|
|
28
|
+
if (source != null && __getOwnPropSymbols)
|
|
29
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
30
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
31
|
+
target[prop] = source[prop];
|
|
32
|
+
}
|
|
33
|
+
return target;
|
|
34
|
+
};
|
|
35
|
+
var __export = (target, all) => {
|
|
36
|
+
for (var name in all)
|
|
37
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
38
|
+
};
|
|
39
|
+
var __copyProps = (to, from, except, desc) => {
|
|
40
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
41
|
+
for (let key of __getOwnPropNames(from))
|
|
42
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
43
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
44
|
+
}
|
|
45
|
+
return to;
|
|
46
|
+
};
|
|
47
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
48
|
+
|
|
49
|
+
// src/index.ts
|
|
50
|
+
var index_exports = {};
|
|
51
|
+
__export(index_exports, {
|
|
52
|
+
EasyFunnelProvider: () => EasyFunnelProvider,
|
|
53
|
+
useEasyFunnel: () => useEasyFunnel,
|
|
54
|
+
useIdentify: () => useIdentify,
|
|
55
|
+
useTrack: () => useTrack
|
|
56
|
+
});
|
|
57
|
+
module.exports = __toCommonJS(index_exports);
|
|
58
|
+
|
|
59
|
+
// src/provider.tsx
|
|
60
|
+
var import_react = require("react");
|
|
61
|
+
var import_sdk = require("@easyfunnel/sdk");
|
|
62
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
63
|
+
var EasyFunnelContext = (0, import_react.createContext)(null);
|
|
64
|
+
function EasyFunnelProvider(_a) {
|
|
65
|
+
var _b = _a, {
|
|
66
|
+
children
|
|
67
|
+
} = _b, options = __objRest(_b, [
|
|
68
|
+
"children"
|
|
69
|
+
]);
|
|
70
|
+
const trackerRef = (0, import_react.useRef)(null);
|
|
71
|
+
(0, import_react.useEffect)(() => {
|
|
72
|
+
if (!trackerRef.current) {
|
|
73
|
+
trackerRef.current = import_sdk.EasyFunnel.init(__spreadProps(__spreadValues({}, options), {
|
|
74
|
+
autoPageView: true
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
return () => {
|
|
78
|
+
var _a2;
|
|
79
|
+
(_a2 = trackerRef.current) == null ? void 0 : _a2.destroy();
|
|
80
|
+
trackerRef.current = null;
|
|
81
|
+
};
|
|
82
|
+
}, [options.apiKey]);
|
|
83
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EasyFunnelContext.Provider, { value: trackerRef.current, children });
|
|
84
|
+
}
|
|
85
|
+
function useEasyFunnel() {
|
|
86
|
+
return (0, import_react.useContext)(EasyFunnelContext);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/hooks.ts
|
|
90
|
+
var import_react2 = require("react");
|
|
91
|
+
function useTrack() {
|
|
92
|
+
const tracker = useEasyFunnel();
|
|
93
|
+
return (0, import_react2.useCallback)(
|
|
94
|
+
(eventName, properties) => {
|
|
95
|
+
tracker == null ? void 0 : tracker.track(eventName, properties);
|
|
96
|
+
},
|
|
97
|
+
[tracker]
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
function useIdentify() {
|
|
101
|
+
const tracker = useEasyFunnel();
|
|
102
|
+
return (0, import_react2.useCallback)(
|
|
103
|
+
(userId) => {
|
|
104
|
+
tracker == null ? void 0 : tracker.identify(userId);
|
|
105
|
+
},
|
|
106
|
+
[tracker]
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
110
|
+
0 && (module.exports = {
|
|
111
|
+
EasyFunnelProvider,
|
|
112
|
+
useEasyFunnel,
|
|
113
|
+
useIdentify,
|
|
114
|
+
useTrack
|
|
115
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/provider.tsx
|
|
34
|
+
import {
|
|
35
|
+
createContext,
|
|
36
|
+
useContext,
|
|
37
|
+
useEffect,
|
|
38
|
+
useRef
|
|
39
|
+
} from "react";
|
|
40
|
+
import { EasyFunnel } from "@easyfunnel/sdk";
|
|
41
|
+
import { jsx } from "react/jsx-runtime";
|
|
42
|
+
var EasyFunnelContext = createContext(null);
|
|
43
|
+
function EasyFunnelProvider(_a) {
|
|
44
|
+
var _b = _a, {
|
|
45
|
+
children
|
|
46
|
+
} = _b, options = __objRest(_b, [
|
|
47
|
+
"children"
|
|
48
|
+
]);
|
|
49
|
+
const trackerRef = useRef(null);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!trackerRef.current) {
|
|
52
|
+
trackerRef.current = EasyFunnel.init(__spreadProps(__spreadValues({}, options), {
|
|
53
|
+
autoPageView: true
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
return () => {
|
|
57
|
+
var _a2;
|
|
58
|
+
(_a2 = trackerRef.current) == null ? void 0 : _a2.destroy();
|
|
59
|
+
trackerRef.current = null;
|
|
60
|
+
};
|
|
61
|
+
}, [options.apiKey]);
|
|
62
|
+
return /* @__PURE__ */ jsx(EasyFunnelContext.Provider, { value: trackerRef.current, children });
|
|
63
|
+
}
|
|
64
|
+
function useEasyFunnel() {
|
|
65
|
+
return useContext(EasyFunnelContext);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/hooks.ts
|
|
69
|
+
import { useCallback } from "react";
|
|
70
|
+
function useTrack() {
|
|
71
|
+
const tracker = useEasyFunnel();
|
|
72
|
+
return useCallback(
|
|
73
|
+
(eventName, properties) => {
|
|
74
|
+
tracker == null ? void 0 : tracker.track(eventName, properties);
|
|
75
|
+
},
|
|
76
|
+
[tracker]
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
function useIdentify() {
|
|
80
|
+
const tracker = useEasyFunnel();
|
|
81
|
+
return useCallback(
|
|
82
|
+
(userId) => {
|
|
83
|
+
tracker == null ? void 0 : tracker.identify(userId);
|
|
84
|
+
},
|
|
85
|
+
[tracker]
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
EasyFunnelProvider,
|
|
90
|
+
useEasyFunnel,
|
|
91
|
+
useIdentify,
|
|
92
|
+
useTrack
|
|
93
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@easyfunnel/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React/Next.js provider for easyfunnel.so analytics",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": ["dist"],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --external react",
|
|
11
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --external react --watch"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@easyfunnel/sdk": "0.1.0"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"react": ">=18.0.0",
|
|
18
|
+
"next": ">=14.0.0"
|
|
19
|
+
},
|
|
20
|
+
"peerDependenciesMeta": {
|
|
21
|
+
"next": {
|
|
22
|
+
"optional": true
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/react": "^19.0.0",
|
|
27
|
+
"react": "^19.0.0",
|
|
28
|
+
"tsup": "^8.0.0",
|
|
29
|
+
"typescript": "^5.0.0"
|
|
30
|
+
},
|
|
31
|
+
"keywords": ["analytics", "funnel", "react", "nextjs", "easyfunnel"],
|
|
32
|
+
"license": "MIT"
|
|
33
|
+
}
|