@bambulabs/finedine-fingerprint-react 1.0.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/LICENSE +22 -0
- package/README.md +182 -0
- package/dist/FingerprintContext.d.ts +18 -0
- package/dist/client.d.ts +10 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.esm.js +1678 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +1684 -0
- package/dist/index.js.map +1 -0
- package/dist/storage.d.ts +13 -0
- package/dist/types.d.ts +45 -0
- package/dist/useVisitorId.d.ts +17 -0
- package/dist/useVisitorTracking.d.ts +18 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Finedine
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# @bambulabs/finedine-fingerprint-react
|
|
2
|
+
|
|
3
|
+
React hooks and components for Finedine visitor fingerprinting.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @bambulabs/finedine-fingerprint-react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### Option 1: Simple Hook
|
|
14
|
+
|
|
15
|
+
```jsx
|
|
16
|
+
import { useVisitorId } from '@bambulabs/finedine-fingerprint-react';
|
|
17
|
+
|
|
18
|
+
function App() {
|
|
19
|
+
const { visitorId, isLoading, error } = useVisitorId();
|
|
20
|
+
|
|
21
|
+
if (isLoading) return <div>Loading...</div>;
|
|
22
|
+
if (error) return <div>Error: {error}</div>;
|
|
23
|
+
|
|
24
|
+
return <div>Visitor ID: {visitorId}</div>;
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Option 2: Full Visitor Data
|
|
29
|
+
|
|
30
|
+
```jsx
|
|
31
|
+
import { useVisitorTracking } from '@bambulabs/finedine-fingerprint-react';
|
|
32
|
+
|
|
33
|
+
function App() {
|
|
34
|
+
const { visitor, isLoading } = useVisitorTracking();
|
|
35
|
+
|
|
36
|
+
if (isLoading) return <div>Loading...</div>;
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div>
|
|
40
|
+
<p>ID: {visitor?.id}</p>
|
|
41
|
+
<p>Visits: {visitor?.visitCount}</p>
|
|
42
|
+
<p>Browser: {visitor?.device?.browser?.name}</p>
|
|
43
|
+
<p>Device: {visitor?.device?.device?.type}</p>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Option 3: Context Provider (Recommended for Apps)
|
|
50
|
+
|
|
51
|
+
```jsx
|
|
52
|
+
// App.jsx
|
|
53
|
+
import { FingerprintProvider } from '@bambulabs/finedine-fingerprint-react';
|
|
54
|
+
|
|
55
|
+
function App() {
|
|
56
|
+
return (
|
|
57
|
+
<FingerprintProvider>
|
|
58
|
+
<YourApp />
|
|
59
|
+
</FingerprintProvider>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Any component
|
|
64
|
+
import { useFingerprint } from '@bambulabs/finedine-fingerprint-react';
|
|
65
|
+
|
|
66
|
+
function Header() {
|
|
67
|
+
const { visitor, visitorId } = useFingerprint();
|
|
68
|
+
return <span>Welcome! Visit #{visitor?.visitCount}</span>;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## API Reference
|
|
73
|
+
|
|
74
|
+
### Hooks
|
|
75
|
+
|
|
76
|
+
#### `useVisitorId(options?)`
|
|
77
|
+
|
|
78
|
+
Simple hook returning just the visitor ID.
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const { visitorId, isLoading, error, identify, clear } = useVisitorId({
|
|
82
|
+
apiUrl: 'https://track.finedinemenu.com/fingerprint', // optional
|
|
83
|
+
storageKey: 'fp_visitor_id', // optional
|
|
84
|
+
autoIdentify: true, // optional, default: true
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### `useVisitorTracking(options?)`
|
|
89
|
+
|
|
90
|
+
Full hook with complete visitor data.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
const { visitor, isLoading, error, identify, clear } = useVisitorTracking({
|
|
94
|
+
apiUrl: 'https://track.finedinemenu.com/fingerprint',
|
|
95
|
+
storageKey: 'fp_visitor_id',
|
|
96
|
+
autoIdentify: true,
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### `useFingerprint()`
|
|
101
|
+
|
|
102
|
+
Context hook (use within `FingerprintProvider`).
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const { visitor, visitorId, isLoading, error, identify, clear } = useFingerprint();
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Components
|
|
109
|
+
|
|
110
|
+
#### `<FingerprintProvider>`
|
|
111
|
+
|
|
112
|
+
Context provider for app-wide visitor tracking.
|
|
113
|
+
|
|
114
|
+
```jsx
|
|
115
|
+
<FingerprintProvider
|
|
116
|
+
apiUrl="https://track.finedinemenu.com/fingerprint"
|
|
117
|
+
storageKey="fp_visitor_id"
|
|
118
|
+
autoIdentify={true}
|
|
119
|
+
>
|
|
120
|
+
{children}
|
|
121
|
+
</FingerprintProvider>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Standalone Client
|
|
125
|
+
|
|
126
|
+
For non-React usage:
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
import { createFingerprintClient } from '@bambulabs/finedine-fingerprint-react';
|
|
130
|
+
|
|
131
|
+
const client = createFingerprintClient({
|
|
132
|
+
apiUrl: 'https://track.finedinemenu.com/fingerprint',
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Identify visitor
|
|
136
|
+
const visitor = await client.identify();
|
|
137
|
+
console.log(visitor.id, visitor.visitCount);
|
|
138
|
+
|
|
139
|
+
// Get stored ID
|
|
140
|
+
const storedId = client.getStoredId();
|
|
141
|
+
|
|
142
|
+
// Clear stored data
|
|
143
|
+
client.clear();
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Types
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
interface Visitor {
|
|
150
|
+
id: string;
|
|
151
|
+
fingerprint: string;
|
|
152
|
+
isNew: boolean;
|
|
153
|
+
firstSeen: Date;
|
|
154
|
+
visitCount: number;
|
|
155
|
+
device: {
|
|
156
|
+
browser: { name: string; version: string };
|
|
157
|
+
os: { name: string; version: string };
|
|
158
|
+
device: { type: string; vendor: string; model: string };
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Configuration
|
|
164
|
+
|
|
165
|
+
| Option | Type | Default | Description |
|
|
166
|
+
|--------|------|---------|-------------|
|
|
167
|
+
| `apiUrl` | `string` | `https://track.finedinemenu.com/fingerprint` | API endpoint |
|
|
168
|
+
| `storageKey` | `string` | `fp_visitor_id` | localStorage/cookie key |
|
|
169
|
+
| `autoIdentify` | `boolean` | `true` | Auto-identify on mount |
|
|
170
|
+
|
|
171
|
+
## How It Works
|
|
172
|
+
|
|
173
|
+
1. **Check localStorage** - Fastest, checked first
|
|
174
|
+
2. **Check cookie** - Fallback (server-set)
|
|
175
|
+
3. **Generate fingerprint** - Ultimate fallback using FingerprintJS
|
|
176
|
+
|
|
177
|
+
This ensures visitors are always identified, even after clearing storage.
|
|
178
|
+
|
|
179
|
+
## License
|
|
180
|
+
|
|
181
|
+
MIT
|
|
182
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { FingerprintContextValue } from './types';
|
|
3
|
+
interface FingerprintProviderProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
apiUrl?: string;
|
|
6
|
+
storageKey?: string;
|
|
7
|
+
autoIdentify?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Provider component for app-wide visitor tracking
|
|
11
|
+
*/
|
|
12
|
+
export declare function FingerprintProvider({ children, apiUrl, storageKey, autoIdentify, }: FingerprintProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
/**
|
|
14
|
+
* Hook to access visitor data from context
|
|
15
|
+
* Must be used within FingerprintProvider
|
|
16
|
+
*/
|
|
17
|
+
export declare function useFingerprint(): FingerprintContextValue;
|
|
18
|
+
export {};
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FingerprintConfig, Visitor } from './types';
|
|
2
|
+
export interface FingerprintClient {
|
|
3
|
+
identify: () => Promise<Visitor>;
|
|
4
|
+
getStoredId: () => string | null;
|
|
5
|
+
clear: () => void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Create a fingerprint client for non-React usage
|
|
9
|
+
*/
|
|
10
|
+
export declare function createFingerprintClient(config?: Partial<FingerprintConfig>): FingerprintClient;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { FingerprintProvider, useFingerprint } from './FingerprintContext';
|
|
2
|
+
export { useVisitorId } from './useVisitorId';
|
|
3
|
+
export { useVisitorTracking } from './useVisitorTracking';
|
|
4
|
+
export { createFingerprintClient } from './client';
|
|
5
|
+
export type { Visitor, VisitorDevice, VisitorResponse, FingerprintConfig, FingerprintContextValue, } from './types';
|