@su-labs/visit-tracker 21.0.5 → 22.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/CHANGELOG.md +6 -0
- package/README.md +31 -31
- package/fesm2022/su-labs-visit-tracker.mjs +56 -54
- package/fesm2022/su-labs-visit-tracker.mjs.map +1 -1
- package/package.json +7 -6
- package/types/su-labs-visit-tracker.d.ts +28 -33
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [22.0.0] - 2026-11-04
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Upgrade to Angular 22 (peer dependencies now `^22.0.0`)
|
|
12
|
+
- Remove emojis from README.md
|
|
13
|
+
|
|
8
14
|
## [21.0.5] - 2026-02-04
|
|
9
15
|
|
|
10
16
|
### Changed
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
`@su-labs/visit-tracker`
|
|
4
4
|
|
|
5
5
|

|
|
6
|
-

|
|
7
7
|

|
|
8
8
|

|
|
9
9
|

|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
A lightweight Angular service to track user visits. Provides reactive signals for visit count, last visit date, and milestone visits.
|
|
15
15
|
|
|
16
|
-
##
|
|
16
|
+
## Table of Contents
|
|
17
17
|
|
|
18
18
|
- [Why Use This Library?](#-why-use-this-library)
|
|
19
19
|
- [Features](#features)
|
|
@@ -29,14 +29,14 @@ A lightweight Angular service to track user visits. Provides reactive signals fo
|
|
|
29
29
|
- [Contributing](#contributing)
|
|
30
30
|
- [License](#license)
|
|
31
31
|
|
|
32
|
-
##
|
|
32
|
+
## Why Use This Library?
|
|
33
33
|
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
34
|
+
- **Lightweight** - Only ~5KB minified
|
|
35
|
+
- **Reactive** - Built with Angular Signals
|
|
36
|
+
- **Type-Safe** - Full TypeScript support
|
|
37
|
+
- **Zero Dependencies** - No bloat
|
|
38
|
+
- **Well Tested** - Comprehensive test coverage
|
|
39
|
+
- **Well Documented** - Clear examples and API docs
|
|
40
40
|
|
|
41
41
|
## Features
|
|
42
42
|
|
|
@@ -60,10 +60,10 @@ npm install @su-labs/visit-tracker
|
|
|
60
60
|
This library requires the following peer dependencies:
|
|
61
61
|
|
|
62
62
|
```sh
|
|
63
|
-
npm install @angular/common@^
|
|
63
|
+
npm install @angular/common@^22 @angular/core@^22
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
##
|
|
66
|
+
## Quick Start
|
|
67
67
|
|
|
68
68
|
```typescript
|
|
69
69
|
// 1. Install
|
|
@@ -109,18 +109,18 @@ export class AppComponent {
|
|
|
109
109
|
}
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
Automatically increments the visit count and updates the last visit timestamp.
|
|
113
113
|
|
|
114
114
|
### Example 2: Checking milestone visits
|
|
115
115
|
You can reactively check if a milestone visit has been reached:
|
|
116
116
|
|
|
117
117
|
```HTML
|
|
118
118
|
@if(visitService.isTenthVisit()){
|
|
119
|
-
<p
|
|
119
|
+
<p>Congratulations on your 10th visit!</p>
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
@if(visitService.isHundredthVisit()){
|
|
123
|
-
<p
|
|
123
|
+
<p>100 visits! You're a power user!</p>
|
|
124
124
|
}
|
|
125
125
|
```
|
|
126
126
|
|
|
@@ -148,7 +148,7 @@ export const appConfig = {
|
|
|
148
148
|
};
|
|
149
149
|
```
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
Allows overriding the localStorage key and defining custom milestone visits.
|
|
152
152
|
|
|
153
153
|
### Example 4: Using last visit date
|
|
154
154
|
|
|
@@ -162,7 +162,7 @@ export const appConfig = {
|
|
|
162
162
|
|
|
163
163
|
The service stores last visit as an ISO string (e.g., "2025-08-25T12:34:56.789Z"), so it can easily be used in Angular date pipes.
|
|
164
164
|
|
|
165
|
-
##
|
|
165
|
+
## API Reference
|
|
166
166
|
|
|
167
167
|
### Signals
|
|
168
168
|
|
|
@@ -197,12 +197,12 @@ The service can be configured to fit your application's needs. You can customize
|
|
|
197
197
|
| `storageKey` | The key used to persist the visit data in `localStorage`. | `'su:visits'` |
|
|
198
198
|
| `milestoneVisits` | An array of numbers representing visits to track as milestones. | `[10, 100]` |
|
|
199
199
|
|
|
200
|
-
##
|
|
200
|
+
## Browser Compatibility
|
|
201
201
|
|
|
202
202
|
Works in all modern browsers that support:
|
|
203
|
-
-
|
|
204
|
-
-
|
|
205
|
-
-
|
|
203
|
+
- localStorage API
|
|
204
|
+
- Angular 22+
|
|
205
|
+
- ES2022+
|
|
206
206
|
|
|
207
207
|
| Browser | Version |
|
|
208
208
|
|---------|---------|
|
|
@@ -211,16 +211,16 @@ Works in all modern browsers that support:
|
|
|
211
211
|
| Safari | ≥ 14 |
|
|
212
212
|
| Edge | ≥ 90 |
|
|
213
213
|
|
|
214
|
-
##
|
|
214
|
+
## Related Libraries
|
|
215
215
|
|
|
216
216
|
Part of the **@su-labs** suite:
|
|
217
217
|
|
|
218
|
-
-
|
|
219
|
-
-
|
|
220
|
-
-
|
|
221
|
-
-
|
|
218
|
+
- [@su-labs/theme](https://www.npmjs.com/package/@su-labs/theme) - Theme management with dark mode support
|
|
219
|
+
- [@su-labs/notifications](https://www.npmjs.com/package/@su-labs/notifications) - Toast notification system
|
|
220
|
+
- [@su-labs/scroll-spy](https://www.npmjs.com/package/@su-labs/scroll-spy) - Scroll position tracking
|
|
221
|
+
- [@su-labs/font-size](https://www.npmjs.com/package/@su-labs/font-size) - Accessible font size controls
|
|
222
222
|
|
|
223
|
-
##
|
|
223
|
+
## Troubleshooting
|
|
224
224
|
|
|
225
225
|
### Visit count not persisting?
|
|
226
226
|
|
|
@@ -232,13 +232,13 @@ Milestones are only checked during service initialization. Call `init()` to reca
|
|
|
232
232
|
|
|
233
233
|
### TypeScript errors?
|
|
234
234
|
|
|
235
|
-
Ensure you have Angular
|
|
235
|
+
Ensure you have Angular 22+ and TypeScript 6.0+ installed.
|
|
236
236
|
|
|
237
|
-
##
|
|
237
|
+
## Support
|
|
238
238
|
|
|
239
|
-
-
|
|
240
|
-
-
|
|
241
|
-
-
|
|
239
|
+
- Found a bug? [Open an issue](https://github.com/Greezaaa/settings-utils-lib/issues)
|
|
240
|
+
- Have a feature request? [Start a discussion](https://github.com/Greezaaa/settings-utils-lib/discussions)
|
|
241
|
+
- Like this library? [Give it a star!](https://github.com/Greezaaa/settings-utils-lib)
|
|
242
242
|
|
|
243
243
|
## Notes
|
|
244
244
|
|
|
@@ -1,55 +1,57 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { Injectable, signal } from "@angular/core";
|
|
3
|
+
var SuVisitTrackerService = class SuVisitTrackerService {
|
|
4
|
+
storageKey = "su:visits";
|
|
5
|
+
_milestones = [10, 100];
|
|
6
|
+
count = signal(0, ...ngDevMode ? [{ debugName: "count" }] : /* istanbul ignore next */ []);
|
|
7
|
+
lastVisit = signal(null, ...ngDevMode ? [{ debugName: "lastVisit" }] : /* istanbul ignore next */ []);
|
|
8
|
+
milestone = signal(null, ...ngDevMode ? [{ debugName: "milestone" }] : /* istanbul ignore next */ []);
|
|
9
|
+
init(config) {
|
|
10
|
+
if (config?.storageKey) this.storageKey = config.storageKey;
|
|
11
|
+
if (config?.milestoneVisits && Array.isArray(config.milestoneVisits)) this._milestones = config.milestoneVisits.sort((a, b) => a - b);
|
|
12
|
+
const storedData = localStorage.getItem(this.storageKey);
|
|
13
|
+
const stored = storedData ? JSON.parse(storedData) : {};
|
|
14
|
+
const prevCount = stored.count ?? 0;
|
|
15
|
+
const prevDate = stored.lastVisit ?? null;
|
|
16
|
+
const newCount = prevCount + 1;
|
|
17
|
+
this.count.set(newCount);
|
|
18
|
+
this.lastVisit.set(prevDate);
|
|
19
|
+
this.updateMilestone(newCount);
|
|
20
|
+
localStorage.setItem(this.storageKey, JSON.stringify({
|
|
21
|
+
count: newCount,
|
|
22
|
+
lastVisit: (/* @__PURE__ */ new Date()).toISOString()
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
updateMilestone(count) {
|
|
26
|
+
const reachedMilestone = this._milestones.find((m) => m === count);
|
|
27
|
+
this.milestone.set(reachedMilestone ?? null);
|
|
28
|
+
}
|
|
29
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
30
|
+
minVersion: "12.0.0",
|
|
31
|
+
version: "22.2.4",
|
|
32
|
+
ngImport: i0,
|
|
33
|
+
type: SuVisitTrackerService,
|
|
34
|
+
deps: [],
|
|
35
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
36
|
+
});
|
|
37
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
38
|
+
minVersion: "12.0.0",
|
|
39
|
+
version: "22.2.4",
|
|
40
|
+
ngImport: i0,
|
|
41
|
+
type: SuVisitTrackerService,
|
|
42
|
+
providedIn: "root"
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
46
|
+
minVersion: "12.0.0",
|
|
47
|
+
version: "22.2.4",
|
|
48
|
+
ngImport: i0,
|
|
49
|
+
type: SuVisitTrackerService,
|
|
50
|
+
decorators: [{
|
|
51
|
+
type: Injectable,
|
|
52
|
+
args: [{ providedIn: "root" }]
|
|
53
|
+
}]
|
|
54
|
+
});
|
|
54
55
|
export { SuVisitTrackerService };
|
|
55
|
-
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=su-labs-visit-tracker.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"su-labs-visit-tracker.mjs","sources":["../../../../projects/su-labs/visit-tracker/src/lib/visit-tracker.service.ts"
|
|
1
|
+
{"version":3,"file":"su-labs-visit-tracker.mjs","names":[],"sources":["../../../../projects/su-labs/visit-tracker/src/lib/visit-tracker.service.ts"],"sourcesContent":["import { Injectable, signal, WritableSignal } from '@angular/core';\nimport { SuVisitData, SuVisitTrackerConfig } from './visit-tracker.types';\n\n@Injectable({ providedIn: 'root' })\nexport class SuVisitTrackerService {\n /** Key used for localStorage */\n private storageKey = 'su:visits';\n\n /** Milestones to track */\n private _milestones: number[] = [10, 100];\n\n /** Current visit count */\n public count: WritableSignal<number> = signal(0);\n\n /** Last visit date as ISO string */\n public lastVisit: WritableSignal<string | null> = signal(null);\n\n /** The number of the milestone reached on the current visit, or null */\n public milestone: WritableSignal<number | null> = signal(null);\n\n /** Initialize the service and update signals */\n public init(config?: SuVisitTrackerConfig): void {\n if (config?.storageKey) {\n this.storageKey = config.storageKey;\n }\n if (config?.milestoneVisits && Array.isArray(config.milestoneVisits)) {\n this._milestones = config.milestoneVisits.sort((a, b) => a - b);\n }\n\n const storedData = localStorage.getItem(this.storageKey);\n const stored: Partial<SuVisitData> = storedData ? JSON.parse(storedData) : {};\n\n const prevCount = stored.count ?? 0;\n const prevDate = stored.lastVisit ?? null;\n const newCount = prevCount + 1;\n\n this.count.set(newCount);\n this.lastVisit.set(prevDate);\n\n this.updateMilestone(newCount);\n\n localStorage.setItem(\n this.storageKey,\n JSON.stringify({ count: newCount, lastVisit: new Date().toISOString() }),\n );\n }\n\n /** Update the milestone signal based on the current count */\n private updateMilestone(count: number): void {\n const reachedMilestone = this._milestones.find(m => m === count);\n this.milestone.set(reachedMilestone ?? null);\n }\n}\n"],"mappings":";;AAIA,IAAa,wBAAb,MAAa,sBAAqB;CAExB,aAAa;CAGb,cAAwB,CAAC,IAAI,GAAG;CAGjC,QAAgC,OAAO,GAAE,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+BAAA,CAAA,CAAA;CAGzC,YAA2C,OAAO,MAAK,GAAA,YAAA,CAAA,EAAA,WAAA,YAAA,CAAA,+BAAA,CAAA,CAAA;CAGvD,YAA2C,OAAO,MAAK,GAAA,YAAA,CAAA,EAAA,WAAA,YAAA,CAAA,+BAAA,CAAA,CAAA;CAGvD,KAAK,QAA6B;EACvC,IAAI,QAAQ,YACV,KAAK,aAAa,OAAO;EAE3B,IAAI,QAAQ,mBAAmB,MAAM,QAAQ,OAAO,eAAe,GACjE,KAAK,cAAc,OAAO,gBAAgB,MAAM,GAAG,MAAM,IAAI,CAAC;EAGhE,MAAM,aAAa,aAAa,QAAQ,KAAK,UAAU;EACvD,MAAM,SAA+B,aAAa,KAAK,MAAM,UAAU,IAAI,CAAA;EAE3E,MAAM,YAAY,OAAO,SAAS;EAClC,MAAM,WAAW,OAAO,aAAa;EACrC,MAAM,WAAW,YAAY;EAE7B,KAAK,MAAM,IAAI,QAAQ;EACvB,KAAK,UAAU,IAAI,QAAQ;EAE3B,KAAK,gBAAgB,QAAQ;EAE7B,aAAa,QACX,KAAK,YACL,KAAK,UAAU;GAAE,OAAO;GAAU,4BAAW,IAAI,KAAI,EAAE,CAAC,YAAW;EAAE,CAAE,CAAC;CAE5E;CAGQ,gBAAgB,OAAa;EACnC,MAAM,mBAAmB,KAAK,YAAY,MAAK,MAAK,MAAM,KAAK;EAC/D,KAAK,UAAU,IAAI,oBAAoB,IAAI;CAC7C;CA/CW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAqB,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAArB,OAAA,QAAA,GAAA,sBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAqB,YADR;CAAM,CAAA;;AACnB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAqB,YAAA,CAAA;EADjC,MAAA;EAAW,MAAA,CAAA,EAAE,YAAY,OAAM,CAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@su-labs/visit-tracker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.0.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"angular",
|
|
6
6
|
"user-tracking",
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"metrics"
|
|
15
15
|
],
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@angular/common": "^
|
|
18
|
-
"@angular/core": "^
|
|
17
|
+
"@angular/common": "^22.0.0",
|
|
18
|
+
"@angular/core": "^22.0.0"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"tslib": "^2.3.0"
|
|
22
22
|
},
|
|
23
|
-
"homepage": "https://github.com/Greezaaa/settings-utils-lib/tree/main/projects/su-labs/
|
|
23
|
+
"homepage": "https://github.com/Greezaaa/settings-utils-lib/tree/main/projects/su-labs/visit-tracker#readme",
|
|
24
24
|
"author": {
|
|
25
25
|
"name": "Yevheniy Alekseyev",
|
|
26
26
|
"email": "yev.alekseyev@gmail.com",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"repository": {
|
|
30
30
|
"type": "git",
|
|
31
31
|
"url": "https://github.com/Greezaaa/settings-utils-lib.git",
|
|
32
|
-
"directory": "projects/su-labs/
|
|
32
|
+
"directory": "projects/su-labs/visit-tracker"
|
|
33
33
|
},
|
|
34
34
|
"bugs": {
|
|
35
35
|
"url": "https://github.com/Greezaaa/settings-utils-lib/issues"
|
|
@@ -46,5 +46,6 @@
|
|
|
46
46
|
"types": "./types/su-labs-visit-tracker.d.ts",
|
|
47
47
|
"default": "./fesm2022/su-labs-visit-tracker.mjs"
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
},
|
|
50
|
+
"type": "module"
|
|
50
51
|
}
|
|
@@ -1,41 +1,36 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import { WritableSignal } from
|
|
3
|
-
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { WritableSignal } from "@angular/core";
|
|
4
3
|
/**
|
|
5
4
|
* Configuration options for SuVisitTrackerService
|
|
6
5
|
*/
|
|
7
|
-
interface SuVisitTrackerConfig {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
export interface SuVisitTrackerConfig {
|
|
7
|
+
/** Key used for storing visit data in localStorage (default: 'su:visits') */
|
|
8
|
+
storageKey?: string;
|
|
9
|
+
/** Milestones to track, e.g., 10th visit, 100th visit */
|
|
10
|
+
milestoneVisits?: number[];
|
|
12
11
|
}
|
|
13
12
|
/**
|
|
14
13
|
* Shape of the data stored in localStorage
|
|
15
14
|
*/
|
|
16
|
-
interface SuVisitData {
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
export interface SuVisitData {
|
|
16
|
+
count: number;
|
|
17
|
+
lastVisit: string;
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export { SuVisitTrackerService };
|
|
41
|
-
export type { SuVisitData, SuVisitTrackerConfig };
|
|
19
|
+
export declare class SuVisitTrackerService {
|
|
20
|
+
/** Key used for localStorage */
|
|
21
|
+
private storageKey;
|
|
22
|
+
/** Milestones to track */
|
|
23
|
+
private _milestones;
|
|
24
|
+
/** Current visit count */
|
|
25
|
+
count: WritableSignal<number>;
|
|
26
|
+
/** Last visit date as ISO string */
|
|
27
|
+
lastVisit: WritableSignal<string | null>;
|
|
28
|
+
/** The number of the milestone reached on the current visit, or null */
|
|
29
|
+
milestone: WritableSignal<number | null>;
|
|
30
|
+
/** Initialize the service and update signals */
|
|
31
|
+
init(config?: SuVisitTrackerConfig): void;
|
|
32
|
+
/** Update the milestone signal based on the current count */
|
|
33
|
+
private updateMilestone;
|
|
34
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SuVisitTrackerService, never>;
|
|
35
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
36
|
+
}
|