featurely-site-manager 1.1.5 → 1.1.6
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 +37 -48
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,9 +63,11 @@ siteManager.init();
|
|
|
63
63
|
|
|
64
64
|
### 📊 Analytics
|
|
65
65
|
|
|
66
|
+
- Automatic page view tracking (SPA-compatible)
|
|
67
|
+
- Session start and end tracking
|
|
68
|
+
- User login event tracking
|
|
69
|
+
- Page exit tracking with time-on-page duration
|
|
66
70
|
- Track custom events
|
|
67
|
-
- Automatic feature flag usage tracking
|
|
68
|
-
- Session management
|
|
69
71
|
- User identification
|
|
70
72
|
|
|
71
73
|
## 📖 Usage
|
|
@@ -216,6 +218,7 @@ const manager = new SiteManager({
|
|
|
216
218
|
});
|
|
217
219
|
|
|
218
220
|
manager.init();
|
|
221
|
+
// Automatically tracks: session_start, page_view, page_exit on every navigation
|
|
219
222
|
|
|
220
223
|
// Track custom events
|
|
221
224
|
manager.trackEvent("button_clicked", {
|
|
@@ -223,12 +226,25 @@ manager.trackEvent("button_clicked", {
|
|
|
223
226
|
page: "/home",
|
|
224
227
|
});
|
|
225
228
|
|
|
226
|
-
manager.trackEvent("
|
|
227
|
-
|
|
228
|
-
|
|
229
|
+
manager.trackEvent("purchase_completed", {
|
|
230
|
+
amount: 99.99,
|
|
231
|
+
plan: "pro",
|
|
229
232
|
});
|
|
230
233
|
```
|
|
231
234
|
|
|
235
|
+
#### Automatic Events
|
|
236
|
+
|
|
237
|
+
When `enableAnalytics` is `true` (default), the SDK automatically tracks:
|
|
238
|
+
|
|
239
|
+
| Event | When | Properties |
|
|
240
|
+
| --- | --- | --- |
|
|
241
|
+
| `session_start` | On first page load | `path`, `title`, `referrer` |
|
|
242
|
+
| `page_view` | On every page navigation | `path`, `title`, `referrer`, `isLoggedIn`, `userId?`, `userEmail?` |
|
|
243
|
+
| `page_exit` | When navigating away from a page | `path`, `durationSeconds` |
|
|
244
|
+
| `user_login` | First time `setUser()` is called with a userId | `userId`, `userEmail?`, `userName?` |
|
|
245
|
+
|
|
246
|
+
Page tracking is SPA-compatible — it patches `history.pushState` and `history.replaceState` and listens to `popstate` so navigations in React, Next.js, Vue, and similar frameworks are captured automatically.
|
|
247
|
+
|
|
232
248
|
### Custom Poll Interval
|
|
233
249
|
|
|
234
250
|
```typescript
|
|
@@ -280,12 +296,12 @@ Initialize and start the site manager.
|
|
|
280
296
|
await manager.init();
|
|
281
297
|
```
|
|
282
298
|
|
|
283
|
-
#### `setUser(email: string, userId?: string)`
|
|
299
|
+
#### `setUser(email: string, userId?: string, userName?: string)`
|
|
284
300
|
|
|
285
|
-
Update user
|
|
301
|
+
Update user context for whitelist, targeting, and analytics. If `userId` is provided for the first time, a `user_login` analytics event is fired automatically.
|
|
286
302
|
|
|
287
303
|
```typescript
|
|
288
|
-
manager.setUser("user@example.com", "user_123");
|
|
304
|
+
manager.setUser("user@example.com", "user_123", "Jane Doe");
|
|
289
305
|
```
|
|
290
306
|
|
|
291
307
|
#### `refresh()`
|
|
@@ -464,56 +480,29 @@ const manager = new SiteManager({
|
|
|
464
480
|
manager.init();
|
|
465
481
|
```
|
|
466
482
|
|
|
467
|
-
##
|
|
483
|
+
## 🔒 Content Security Policy (CSP)
|
|
468
484
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
| Option | Type | Required | Default | Description |
|
|
472
|
-
| ----------------------- | --------------- | -------- | ------------------------- | ----------------------------- |
|
|
473
|
-
| `apiKey` | `string` | ✅ | - | Your Featurely API key |
|
|
474
|
-
| `projectId` | `string` | ✅ | - | Your Featurely project ID |
|
|
475
|
-
| `apiUrl` | `string` | ❌ | `'https://featurely.no'` | Custom API endpoint |
|
|
476
|
-
| `pollInterval` | `number` | ❌ | `60000` | Polling interval in ms |
|
|
477
|
-
| `userEmail` | `string` | ❌ | - | User email for whitelist |
|
|
478
|
-
| `bypassCheck` | `() => boolean` | ❌ | - | Custom bypass function |
|
|
479
|
-
| `onMaintenanceEnabled` | `function` | ❌ | - | Maintenance enabled callback |
|
|
480
|
-
| `onMaintenanceDisabled` | `function` | ❌ | - | Maintenance disabled callback |
|
|
481
|
-
| `onMessageReceived` | `function` | ❌ | - | Message received callback |
|
|
482
|
-
| `onMessageDismissed` | `function` | ❌ | - | Message dismissed callback |
|
|
483
|
-
| `onError` | `function` | ❌ | - | Error callback |
|
|
484
|
-
|
|
485
|
-
## 🎯 API Methods
|
|
485
|
+
If your site uses a `Content-Security-Policy` header, you must allow connections to `https://www.featurely.no`. Without this, all API calls (config polling, analytics, feature flags) will be silently blocked.
|
|
486
486
|
|
|
487
|
-
|
|
487
|
+
Add the following to your `connect-src` directive:
|
|
488
488
|
|
|
489
|
-
Initialize and start the site manager.
|
|
490
|
-
|
|
491
|
-
```typescript
|
|
492
|
-
await manager.init();
|
|
493
489
|
```
|
|
494
|
-
|
|
495
|
-
### `setUser(email: string)`
|
|
496
|
-
|
|
497
|
-
Update user email for whitelist checks.
|
|
498
|
-
|
|
499
|
-
```typescript
|
|
500
|
-
manager.setUser("user@example.com");
|
|
490
|
+
connect-src 'self' https://www.featurely.no;
|
|
501
491
|
```
|
|
502
492
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
Manually refresh configuration from server.
|
|
493
|
+
**Next.js example** (`next.config.js`):
|
|
506
494
|
|
|
507
|
-
```
|
|
508
|
-
|
|
495
|
+
```javascript
|
|
496
|
+
const cspHeader = `
|
|
497
|
+
connect-src 'self' https://www.featurely.no;
|
|
498
|
+
`.trim();
|
|
509
499
|
```
|
|
510
500
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
Stop the manager and clean up.
|
|
501
|
+
If the SDK is being blocked by CSP, you will see a message like this in the browser console:
|
|
514
502
|
|
|
515
|
-
```
|
|
516
|
-
|
|
503
|
+
```
|
|
504
|
+
[SiteManager] ⚠️ Connection to Featurely was blocked — check your Content-Security-Policy.
|
|
505
|
+
Add "https://www.featurely.no" to your connect-src directive.
|
|
517
506
|
```
|
|
518
507
|
|
|
519
508
|
## 🎨 Maintenance Mode
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "featurely-site-manager",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "Complete site management SDK for maintenance mode, status messages, feature flags, version checking, and analytics",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|