@su-labs/visit-tracker 1.0.3 → 19.1.2
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 +84 -0
- package/README.md +173 -36
- package/fesm2022/su-labs-visit-tracker.mjs +32 -36
- package/fesm2022/su-labs-visit-tracker.mjs.map +1 -1
- package/index.d.ts +3 -39
- package/lib/visit-tracker.service.d.ts +31 -0
- package/package.json +6 -5
- package/public-api.d.ts +2 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [22.1.2] - 2026-11-16
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Uses `@su-labs/core` 1.9.0 (was 1.8.0), the same version as every other `@su-labs` package, so apps using several of them install core once
|
|
12
|
+
|
|
13
|
+
## [22.1.1] - 2026-11-14
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- Package homepage now points to the website with a live demo
|
|
17
|
+
- Pins `@su-labs/core` to exactly 1.8.0
|
|
18
|
+
|
|
19
|
+
## [22.1.0] - 2026-11-05
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- Visit tracking moved to the framework-agnostic `@su-labs/core/visit-tracker`; `SuVisitTrackerService` is now a thin wrapper with the same API
|
|
23
|
+
- `SuVisitTrackerConfig` and `SuVisitData` are now re-exported from `@su-labs/core/visit-tracker`
|
|
24
|
+
- Added `@su-labs/core` as a dependency
|
|
25
|
+
- README links to the `@su-labs/core` installation guides for non-Angular projects
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
- Corrupted or invalid saved data no longer throws; counting starts over
|
|
29
|
+
- `init()` no longer sorts the `milestoneVisits` array passed in the config
|
|
30
|
+
- Safe to call during server-side rendering (no `localStorage` access without a browser)
|
|
31
|
+
- README now documents the actual API (`milestone()` signal, `init()` required)
|
|
32
|
+
- Repair table of contents links in README.md
|
|
33
|
+
|
|
34
|
+
## [22.0.0] - 2026-11-04
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
- Upgrade to Angular 22 (peer dependencies now `^22.0.0`)
|
|
38
|
+
- Remove emojis from README.md
|
|
39
|
+
|
|
40
|
+
## [21.0.5] - 2026-02-04
|
|
41
|
+
|
|
42
|
+
### Changed
|
|
43
|
+
- Update README.md
|
|
44
|
+
|
|
45
|
+
## [21.0.4] - 2026-02-03
|
|
46
|
+
|
|
47
|
+
### Changed
|
|
48
|
+
- **BREAKING:** Updated to Angular 21 support. This version requires Angular 21.0.0 or higher.
|
|
49
|
+
- Updated peer dependencies to `@angular/common: ^21.0.0` and `@angular/core: ^21.0.0`.
|
|
50
|
+
- Aligned package version with Angular major version for clearer compatibility (v21.x.x = Angular 21 support).
|
|
51
|
+
|
|
52
|
+
### Notes
|
|
53
|
+
- Projects using Angular 20 or below should continue using version 1.0.3.
|
|
54
|
+
- This release maintains full backward compatibility with the 1.x API - only the Angular version requirement has changed.
|
|
55
|
+
s
|
|
56
|
+
|
|
57
|
+
## [1.0.3] - 2025-08-30
|
|
58
|
+
|
|
59
|
+
### Fixed
|
|
60
|
+
- Removed unintended `.spec.ts` exports from the public API surface.
|
|
61
|
+
- Ensured `"license": "MIT"` is correctly reflected in the published package metadata.
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
## [1.0.2] - 2025-08-30
|
|
65
|
+
|
|
66
|
+
### Note
|
|
67
|
+
- This version was published with incorrect package content and is deprecated. Please use `1.0.4`.
|
|
68
|
+
|
|
69
|
+
## [1.0.1] - 2025-08-27
|
|
70
|
+
|
|
71
|
+
### Changed
|
|
72
|
+
- Updated documentation (`README.md`) to reflect new scoped package import:
|
|
73
|
+
from `./su-visit-tracker.service` → `@su-labs/visit-tracker`.
|
|
74
|
+
|
|
75
|
+
## [1.0.0] - 2024-08-26
|
|
76
|
+
|
|
77
|
+
### Added
|
|
78
|
+
|
|
79
|
+
- Initial public release of the @su-labs/visit-tracker library.
|
|
80
|
+
- Introduction of SuVisitTrackerService, a lightweight service for tracking user visits.
|
|
81
|
+
- Reactive `Signal`s for `count`, `lastVisit`, `isTenthVisit`, and `isHundredthVisit`.
|
|
82
|
+
- Persistent storage of visit data in `localStorage`.
|
|
83
|
+
- Support for custom milestone visits via `milestoneVisits` configuration.
|
|
84
|
+
- Full support for modern Angular applications using `inject()` and `provideAppInitializer`.
|
package/README.md
CHANGED
|
@@ -1,12 +1,50 @@
|
|
|
1
1
|
# SuVisitTrackerService
|
|
2
2
|
|
|
3
|
+
`@su-labs/visit-tracker`
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
3
14
|
A lightweight Angular service to track user visits. Provides reactive signals for visit count, last visit date, and milestone visits.
|
|
4
15
|
|
|
16
|
+
> **Not using Angular?** The same visit tracker is available for React, Vue, Svelte and vanilla JavaScript in [`@su-labs/core`](https://www.npmjs.com/package/@su-labs/core). See the [installation guides](https://github.com/Greezaaa/settings-utils-lib/blob/main/docs/README.md).
|
|
17
|
+
|
|
18
|
+
## Table of Contents
|
|
19
|
+
|
|
20
|
+
- [Why Use This Library?](#why-use-this-library)
|
|
21
|
+
- [Features](#features)
|
|
22
|
+
- [Installation](#installation)
|
|
23
|
+
- [Quick Start](#quick-start)
|
|
24
|
+
- [Usage](#usage)
|
|
25
|
+
- [API Reference](#api-reference)
|
|
26
|
+
- [Configuration Options](#configuration-options)
|
|
27
|
+
- [Browser Compatibility](#browser-compatibility)
|
|
28
|
+
- [Related Libraries](#related-libraries)
|
|
29
|
+
- [Troubleshooting](#troubleshooting)
|
|
30
|
+
- [Support](#support)
|
|
31
|
+
- [Contributing](#contributing)
|
|
32
|
+
- [License](#license)
|
|
33
|
+
|
|
34
|
+
## Why Use This Library?
|
|
35
|
+
|
|
36
|
+
- **Lightweight** - Minimal bundle size
|
|
37
|
+
- **Reactive** - Built with Angular Signals
|
|
38
|
+
- **Type-Safe** - Full TypeScript support
|
|
39
|
+
- **SSR Safe** - No browser APIs are touched on the server
|
|
40
|
+
- **Well Tested** - Comprehensive test coverage
|
|
41
|
+
- **Well Documented** - Clear examples and API docs
|
|
42
|
+
|
|
5
43
|
## Features
|
|
6
44
|
|
|
7
45
|
* Tracks number of visits per user.
|
|
8
46
|
* Persists visit data in `localStorage`.
|
|
9
|
-
*
|
|
47
|
+
* Milestone signal (e.g., 10th, 100th visit).
|
|
10
48
|
* Reactive last visit date signal.
|
|
11
49
|
* Configurable storage key and milestones.
|
|
12
50
|
* Works seamlessly with standalone components and reactive Angular setups.
|
|
@@ -16,37 +54,70 @@ A lightweight Angular service to track user visits. Provides reactive signals fo
|
|
|
16
54
|
You can install this library via npm:
|
|
17
55
|
|
|
18
56
|
```sh
|
|
19
|
-
npm install @su-labs/visit-tracker
|
|
57
|
+
npm install @su-labs/visit-tracker@ng19
|
|
20
58
|
```
|
|
21
59
|
|
|
60
|
+
This is the Angular 19 version. For the newest Angular, install `@su-labs/visit-tracker` without a tag.
|
|
61
|
+
|
|
22
62
|
## Peer Dependencies
|
|
23
63
|
|
|
24
64
|
This library requires the following peer dependencies:
|
|
25
65
|
|
|
26
66
|
```sh
|
|
27
|
-
npm install @angular/common@^
|
|
67
|
+
npm install @angular/common@^19 @angular/core@^19
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
1. Record the visit once at startup in `app.config.ts`:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
|
|
76
|
+
import { SuVisitTrackerService } from '@su-labs/visit-tracker';
|
|
77
|
+
|
|
78
|
+
export const appConfig: ApplicationConfig = {
|
|
79
|
+
providers: [
|
|
80
|
+
provideAppInitializer(() => {
|
|
81
|
+
inject(SuVisitTrackerService).init();
|
|
82
|
+
}),
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
2. Read the signals in any component:
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { Component, inject } from '@angular/core';
|
|
91
|
+
import { SuVisitTrackerService } from '@su-labs/visit-tracker';
|
|
92
|
+
|
|
93
|
+
@Component({
|
|
94
|
+
selector: 'app-root',
|
|
95
|
+
template: `<p>Visits: {{ visitService.count() }}</p>`,
|
|
96
|
+
})
|
|
97
|
+
export class AppComponent {
|
|
98
|
+
protected readonly visitService = inject(SuVisitTrackerService);
|
|
99
|
+
}
|
|
28
100
|
```
|
|
29
101
|
|
|
30
102
|
## Usage
|
|
31
|
-
### Example 1: Basic initialization
|
|
32
|
-
The service should be provided at the root level. To use it in a component, simply inject it:
|
|
33
103
|
|
|
34
|
-
|
|
104
|
+
### Example 1: Welcome back message
|
|
105
|
+
After `init()` has run (see [Quick Start](#quick-start)), inject the service wherever you need it:
|
|
35
106
|
|
|
107
|
+
```TypeScript
|
|
36
108
|
import { Component, inject } from '@angular/core';
|
|
37
|
-
import {
|
|
109
|
+
import { DatePipe } from '@angular/common';
|
|
38
110
|
import { SuVisitTrackerService } from '@su-labs/visit-tracker';
|
|
39
111
|
|
|
40
112
|
@Component({
|
|
41
113
|
selector: 'app-root',
|
|
42
|
-
|
|
43
|
-
imports: [CommonModule, DatePipe],
|
|
114
|
+
imports: [DatePipe],
|
|
44
115
|
template: `
|
|
45
116
|
<h1>Welcome back!</h1>
|
|
46
117
|
<p>You have visited {{ visitService.count() }} times.</p>
|
|
47
|
-
|
|
48
|
-
<p>Last visit: {{ last | date:'medium' }}</p>
|
|
49
|
-
|
|
118
|
+
@if (visitService.lastVisit(); as last) {
|
|
119
|
+
<p>Last visit: {{ last | date: 'medium' }}</p>
|
|
120
|
+
}
|
|
50
121
|
`,
|
|
51
122
|
})
|
|
52
123
|
export class AppComponent {
|
|
@@ -54,29 +125,28 @@ export class AppComponent {
|
|
|
54
125
|
}
|
|
55
126
|
```
|
|
56
127
|
|
|
57
|
-
|
|
128
|
+
Each `init()` call increments the visit count and saves the start of this visit for next time.
|
|
58
129
|
|
|
59
130
|
### Example 2: Checking milestone visits
|
|
60
|
-
|
|
131
|
+
`milestone()` holds the milestone reached on this visit, or `null`:
|
|
61
132
|
|
|
62
133
|
```HTML
|
|
63
|
-
|
|
64
|
-
@
|
|
65
|
-
<p
|
|
134
|
+
@switch (visitService.milestone()) {
|
|
135
|
+
@case (10) {
|
|
136
|
+
<p>Congratulations on your 10th visit!</p>
|
|
66
137
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
<p>🏆 100 visits! You're a power user!</p>
|
|
138
|
+
@case (100) {
|
|
139
|
+
<p>100 visits! You're a power user!</p>
|
|
70
140
|
}
|
|
141
|
+
}
|
|
71
142
|
```
|
|
72
143
|
|
|
73
|
-
|
|
144
|
+
The signal is set when `init()` runs.
|
|
74
145
|
|
|
75
146
|
### Example 3: Custom configuration
|
|
76
147
|
For standalone apps, use provideAppInitializer to initialize the tracker with a custom storage key or milestones:
|
|
77
148
|
|
|
78
149
|
```TypeScript
|
|
79
|
-
|
|
80
150
|
import { provideAppInitializer, inject } from '@angular/core';
|
|
81
151
|
import { SuVisitTrackerService, SuVisitTrackerConfig } from '@su-labs/visit-tracker';
|
|
82
152
|
|
|
@@ -93,24 +163,48 @@ export const appConfig = {
|
|
|
93
163
|
}),
|
|
94
164
|
],
|
|
95
165
|
};
|
|
96
|
-
|
|
97
166
|
```
|
|
98
|
-
✅ Allows overriding the localStorage key and defining custom milestone visits.
|
|
99
167
|
|
|
100
|
-
|
|
168
|
+
Allows overriding the localStorage key and defining custom milestone visits.
|
|
101
169
|
|
|
102
|
-
|
|
170
|
+
### Example 4: Using last visit date
|
|
103
171
|
|
|
104
|
-
|
|
172
|
+
```HTML
|
|
173
|
+
@if (visitService.lastVisit(); as last) {
|
|
105
174
|
<p>
|
|
106
175
|
Your last visit was on {{ last | date:'fullDate' }} at {{ last | date:'shortTime' }}
|
|
107
176
|
</p>
|
|
108
|
-
|
|
177
|
+
}
|
|
109
178
|
```
|
|
110
179
|
|
|
111
180
|
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.
|
|
112
181
|
|
|
113
|
-
##
|
|
182
|
+
## API Reference
|
|
183
|
+
|
|
184
|
+
### Signals
|
|
185
|
+
|
|
186
|
+
| Signal | Type | Description |
|
|
187
|
+
|--------|------|-------------|
|
|
188
|
+
| `count()` | `number` | Visit count including this visit (`0` before `init()`) |
|
|
189
|
+
| `lastVisit()` | `string \| null` | Start of the previous visit as an ISO string, or `null` on the first visit |
|
|
190
|
+
| `milestone()` | `number \| null` | Milestone reached on this visit, or `null` |
|
|
191
|
+
|
|
192
|
+
### Methods
|
|
193
|
+
|
|
194
|
+
| Method | Parameters | Description |
|
|
195
|
+
|--------|------------|-------------|
|
|
196
|
+
| `init(config?)` | `SuVisitTrackerConfig` | Record the current visit. Call once at startup. |
|
|
197
|
+
|
|
198
|
+
### Types
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
interface SuVisitTrackerConfig {
|
|
202
|
+
storageKey?: string; // Default: 'su:visits'
|
|
203
|
+
milestoneVisits?: number[]; // Default: [10, 100]
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Configuration Options
|
|
114
208
|
|
|
115
209
|
The service can be configured to fit your application's needs. You can customize the storage key and milestone values by passing a configuration object to the `init()` method.
|
|
116
210
|
|
|
@@ -119,15 +213,59 @@ The service can be configured to fit your application's needs. You can customize
|
|
|
119
213
|
| `storageKey` | The key used to persist the visit data in `localStorage`. | `'su:visits'` |
|
|
120
214
|
| `milestoneVisits` | An array of numbers representing visits to track as milestones. | `[10, 100]` |
|
|
121
215
|
|
|
122
|
-
##
|
|
216
|
+
## Browser Compatibility
|
|
217
|
+
|
|
218
|
+
Works in all modern browsers that support:
|
|
219
|
+
- localStorage API
|
|
220
|
+
- Angular 19
|
|
221
|
+
- ES2022+
|
|
123
222
|
|
|
124
|
-
|
|
223
|
+
| Browser | Version |
|
|
224
|
+
|---------|---------|
|
|
225
|
+
| Chrome | ≥ 90 |
|
|
226
|
+
| Firefox | ≥ 88 |
|
|
227
|
+
| Safari | ≥ 14 |
|
|
228
|
+
| Edge | ≥ 90 |
|
|
125
229
|
|
|
126
|
-
|
|
230
|
+
## Related Libraries
|
|
127
231
|
|
|
128
|
-
|
|
232
|
+
Part of the **@su-labs** suite:
|
|
129
233
|
|
|
130
|
-
-
|
|
234
|
+
- [@su-labs/theme](https://www.npmjs.com/package/@su-labs/theme) - Theme management with dark mode support
|
|
235
|
+
- [@su-labs/notifications](https://www.npmjs.com/package/@su-labs/notifications) - Toast notification system
|
|
236
|
+
- [@su-labs/scroll-spy](https://www.npmjs.com/package/@su-labs/scroll-spy) - Scroll position tracking
|
|
237
|
+
- [@su-labs/font-size](https://www.npmjs.com/package/@su-labs/font-size) - Accessible font size controls
|
|
238
|
+
|
|
239
|
+
## Troubleshooting
|
|
240
|
+
|
|
241
|
+
### Visit count not persisting?
|
|
242
|
+
|
|
243
|
+
Make sure localStorage is enabled in your browser and not blocked by privacy settings.
|
|
244
|
+
|
|
245
|
+
### Count stays at 0?
|
|
246
|
+
|
|
247
|
+
The visit is only recorded when `init()` runs. Call it once at startup, as shown in [Quick Start](#quick-start).
|
|
248
|
+
|
|
249
|
+
### Milestone signal not updating?
|
|
250
|
+
|
|
251
|
+
Milestones are only checked when `init()` runs, once per visit.
|
|
252
|
+
|
|
253
|
+
### TypeScript errors?
|
|
254
|
+
|
|
255
|
+
Ensure you have Angular 19 and TypeScript 5.5+ installed.
|
|
256
|
+
|
|
257
|
+
## Support
|
|
258
|
+
|
|
259
|
+
- Found a bug? [Open an issue](https://github.com/Greezaaa/settings-utils-lib/issues)
|
|
260
|
+
- Have a feature request? [Start a discussion](https://github.com/Greezaaa/settings-utils-lib/discussions)
|
|
261
|
+
- Like this library? [Give it a star!](https://github.com/Greezaaa/settings-utils-lib)
|
|
262
|
+
|
|
263
|
+
## Notes
|
|
264
|
+
|
|
265
|
+
- **Signals-based API**: Perfect for standalone components and reactive Angular templates.
|
|
266
|
+
- **Persistence**: Visit count and last visit are automatically stored in localStorage.
|
|
267
|
+
- **Lightweight**: Minimal memory footprint.
|
|
268
|
+
- **Custom milestones**: Track any number of user visit milestones reactively.
|
|
131
269
|
|
|
132
270
|
## Contributing
|
|
133
271
|
|
|
@@ -137,5 +275,4 @@ To contribute code, please ensure your changes include unit tests to maintain co
|
|
|
137
275
|
|
|
138
276
|
## License
|
|
139
277
|
|
|
140
|
-
This project is licensed under the MIT License. See the [**LICENSE**](https://github.com/Greezaaa/settings-utils-lib/blob/main/projects/su-labs/visit-tracker/LICENSE) file for details.
|
|
141
|
-
|
|
278
|
+
This project is licensed under the MIT License. See the [**LICENSE**](https://github.com/Greezaaa/settings-utils-lib/blob/main/projects/su-labs/visit-tracker/LICENSE) file for details.
|
|
@@ -1,52 +1,48 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { signal, Injectable } from '@angular/core';
|
|
3
|
+
import { SuVisitTrackerController } from '@su-labs/core/visit-tracker';
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Angular service for tracking user visits.
|
|
7
|
+
*
|
|
8
|
+
* Thin wrapper around the framework-agnostic `SuVisitTrackerController` from
|
|
9
|
+
* `@su-labs/core/visit-tracker` that exposes the visit data as Angular signals.
|
|
10
|
+
*/
|
|
4
11
|
class SuVisitTrackerService {
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
/** Last visit date as ISO string */
|
|
12
|
-
lastVisit = signal(null, ...(ngDevMode ? [{ debugName: "lastVisit" }] : []));
|
|
12
|
+
/** Framework-agnostic visit tracking logic */
|
|
13
|
+
controller = new SuVisitTrackerController();
|
|
14
|
+
/** Current visit count (0 until {@link init} runs) */
|
|
15
|
+
count = signal(0);
|
|
16
|
+
/** Start of the previous visit as an ISO string, or null on the first visit */
|
|
17
|
+
lastVisit = signal(null);
|
|
13
18
|
/** The number of the milestone reached on the current visit, or null */
|
|
14
|
-
milestone = signal(null
|
|
15
|
-
/**
|
|
19
|
+
milestone = signal(null);
|
|
20
|
+
/** Stops syncing the controller's state into the signals */
|
|
21
|
+
unsubscribe = this.controller.visit.subscribe((visit) => {
|
|
22
|
+
this.count.set(visit.count);
|
|
23
|
+
this.lastVisit.set(visit.lastVisit);
|
|
24
|
+
this.milestone.set(visit.milestone);
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Record the current visit and update the signals.
|
|
28
|
+
* Call once at application startup.
|
|
29
|
+
* @param config Optional storage key and milestones.
|
|
30
|
+
*/
|
|
16
31
|
init(config) {
|
|
17
|
-
|
|
18
|
-
this.storageKey = config.storageKey;
|
|
19
|
-
}
|
|
20
|
-
if (config?.milestoneVisits && Array.isArray(config.milestoneVisits)) {
|
|
21
|
-
this._milestones = config.milestoneVisits.sort((a, b) => a - b);
|
|
22
|
-
}
|
|
23
|
-
const storedData = localStorage.getItem(this.storageKey);
|
|
24
|
-
const stored = storedData ? JSON.parse(storedData) : {};
|
|
25
|
-
const prevCount = stored.count ?? 0;
|
|
26
|
-
const prevDate = stored.lastVisit ?? null;
|
|
27
|
-
const newCount = prevCount + 1;
|
|
28
|
-
this.count.set(newCount);
|
|
29
|
-
this.lastVisit.set(prevDate);
|
|
30
|
-
this.updateMilestone(newCount);
|
|
31
|
-
localStorage.setItem(this.storageKey, JSON.stringify({ count: newCount, lastVisit: new Date().toISOString() }));
|
|
32
|
+
this.controller.init(config);
|
|
32
33
|
}
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.milestone.set(reachedMilestone ?? null);
|
|
34
|
+
/** Angular lifecycle hook for service destruction */
|
|
35
|
+
ngOnDestroy() {
|
|
36
|
+
this.unsubscribe();
|
|
37
37
|
}
|
|
38
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
39
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
38
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: SuVisitTrackerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
39
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: SuVisitTrackerService, providedIn: 'root' });
|
|
40
40
|
}
|
|
41
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
41
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: SuVisitTrackerService, decorators: [{
|
|
42
42
|
type: Injectable,
|
|
43
43
|
args: [{ providedIn: 'root' }]
|
|
44
44
|
}] });
|
|
45
45
|
|
|
46
|
-
/*
|
|
47
|
-
* Public API Surface of visit-tracker
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
46
|
/**
|
|
51
47
|
* Generated bundle index. Do not edit.
|
|
52
48
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"su-labs-visit-tracker.mjs","sources":["../../../../
|
|
1
|
+
{"version":3,"file":"su-labs-visit-tracker.mjs","sources":["../../../../compat/angular-19/build/visit-tracker/src/lib/visit-tracker.service.ts","../../../../compat/angular-19/build/visit-tracker/src/su-labs-visit-tracker.ts"],"sourcesContent":["import { Injectable, OnDestroy, signal, WritableSignal } from '@angular/core';\nimport { SuVisitTrackerConfig, SuVisitTrackerController } from '@su-labs/core/visit-tracker';\n\n/**\n * Angular service for tracking user visits.\n *\n * Thin wrapper around the framework-agnostic `SuVisitTrackerController` from\n * `@su-labs/core/visit-tracker` that exposes the visit data as Angular signals.\n */\n@Injectable({ providedIn: 'root' })\nexport class SuVisitTrackerService implements OnDestroy {\n /** Framework-agnostic visit tracking logic */\n private readonly controller = new SuVisitTrackerController();\n\n /** Current visit count (0 until {@link init} runs) */\n public count: WritableSignal<number> = signal(0);\n\n /** Start of the previous visit as an ISO string, or null on the first visit */\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 /** Stops syncing the controller's state into the signals */\n private readonly unsubscribe = this.controller.visit.subscribe((visit) => {\n this.count.set(visit.count);\n this.lastVisit.set(visit.lastVisit);\n this.milestone.set(visit.milestone);\n });\n\n /**\n * Record the current visit and update the signals.\n * Call once at application startup.\n * @param config Optional storage key and milestones.\n */\n public init(config?: SuVisitTrackerConfig): void {\n this.controller.init(config);\n }\n\n /** Angular lifecycle hook for service destruction */\n ngOnDestroy(): void {\n this.unsubscribe();\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAGA;;;;;AAKG;MAEU,qBAAqB,CAAA;;AAEf,IAAA,UAAU,GAAG,IAAI,wBAAwB,EAAE;;AAGrD,IAAA,KAAK,GAA2B,MAAM,CAAC,CAAC,CAAC;;AAGzC,IAAA,SAAS,GAAkC,MAAM,CAAC,IAAI,CAAC;;AAGvD,IAAA,SAAS,GAAkC,MAAM,CAAC,IAAI,CAAC;;AAG7C,IAAA,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,KAAK,KAAI;QACvE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC;AACrC,IAAA,CAAC,CAAC;AAEF;;;;AAIG;AACI,IAAA,IAAI,CAAC,MAA6B,EAAA;AACvC,QAAA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC;IAC9B;;IAGA,WAAW,GAAA;QACT,IAAI,CAAC,WAAW,EAAE;IACpB;wGAhCW,qBAAqB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAArB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,qBAAqB,cADR,MAAM,EAAA,CAAA;;4FACnB,qBAAqB,EAAA,UAAA,EAAA,CAAA;kBADjC,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACTlC;;AAEG;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -1,41 +1,5 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { WritableSignal } from '@angular/core';
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
2
|
+
* Generated bundle index. Do not edit.
|
|
6
3
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
storageKey?: string;
|
|
10
|
-
/** Milestones to track, e.g., 10th visit, 100th visit */
|
|
11
|
-
milestoneVisits?: number[];
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Shape of the data stored in localStorage
|
|
15
|
-
*/
|
|
16
|
-
interface SuVisitData {
|
|
17
|
-
count: number;
|
|
18
|
-
lastVisit: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
declare class SuVisitTrackerService {
|
|
22
|
-
/** Key used for localStorage */
|
|
23
|
-
private storageKey;
|
|
24
|
-
/** Milestones to track */
|
|
25
|
-
private _milestones;
|
|
26
|
-
/** Current visit count */
|
|
27
|
-
count: WritableSignal<number>;
|
|
28
|
-
/** Last visit date as ISO string */
|
|
29
|
-
lastVisit: WritableSignal<string | null>;
|
|
30
|
-
/** The number of the milestone reached on the current visit, or null */
|
|
31
|
-
milestone: WritableSignal<number | null>;
|
|
32
|
-
/** Initialize the service and update signals */
|
|
33
|
-
init(config?: SuVisitTrackerConfig): void;
|
|
34
|
-
/** Update the milestone signal based on the current count */
|
|
35
|
-
private updateMilestone;
|
|
36
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<SuVisitTrackerService, never>;
|
|
37
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<SuVisitTrackerService>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export { SuVisitTrackerService };
|
|
41
|
-
export type { SuVisitData, SuVisitTrackerConfig };
|
|
4
|
+
/// <amd-module name="@su-labs/visit-tracker" />
|
|
5
|
+
export * from './public-api';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { OnDestroy, WritableSignal } from '@angular/core';
|
|
2
|
+
import { SuVisitTrackerConfig } from '@su-labs/core/visit-tracker';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
/**
|
|
5
|
+
* Angular service for tracking user visits.
|
|
6
|
+
*
|
|
7
|
+
* Thin wrapper around the framework-agnostic `SuVisitTrackerController` from
|
|
8
|
+
* `@su-labs/core/visit-tracker` that exposes the visit data as Angular signals.
|
|
9
|
+
*/
|
|
10
|
+
export declare class SuVisitTrackerService implements OnDestroy {
|
|
11
|
+
/** Framework-agnostic visit tracking logic */
|
|
12
|
+
private readonly controller;
|
|
13
|
+
/** Current visit count (0 until {@link init} runs) */
|
|
14
|
+
count: WritableSignal<number>;
|
|
15
|
+
/** Start of the previous visit as an ISO string, or null on the first visit */
|
|
16
|
+
lastVisit: WritableSignal<string | null>;
|
|
17
|
+
/** The number of the milestone reached on the current visit, or null */
|
|
18
|
+
milestone: WritableSignal<number | null>;
|
|
19
|
+
/** Stops syncing the controller's state into the signals */
|
|
20
|
+
private readonly unsubscribe;
|
|
21
|
+
/**
|
|
22
|
+
* Record the current visit and update the signals.
|
|
23
|
+
* Call once at application startup.
|
|
24
|
+
* @param config Optional storage key and milestones.
|
|
25
|
+
*/
|
|
26
|
+
init(config?: SuVisitTrackerConfig): void;
|
|
27
|
+
/** Angular lifecycle hook for service destruction */
|
|
28
|
+
ngOnDestroy(): void;
|
|
29
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SuVisitTrackerService, never>;
|
|
30
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<SuVisitTrackerService>;
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@su-labs/visit-tracker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "19.1.2",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"angular",
|
|
6
6
|
"user-tracking",
|
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
"metrics"
|
|
15
15
|
],
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@angular/common": "^
|
|
18
|
-
"@angular/core": "^
|
|
17
|
+
"@angular/common": "^19.0.0",
|
|
18
|
+
"@angular/core": "^19.0.0"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"@su-labs/core": "1.9.0",
|
|
21
22
|
"tslib": "^2.3.0"
|
|
22
23
|
},
|
|
23
|
-
"homepage": "https://
|
|
24
|
+
"homepage": "https://su-labs.dev/visit-tracker/",
|
|
24
25
|
"author": {
|
|
25
26
|
"name": "Yevheniy Alekseyev",
|
|
26
27
|
"email": "yev.alekseyev@gmail.com",
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
"repository": {
|
|
30
31
|
"type": "git",
|
|
31
32
|
"url": "https://github.com/Greezaaa/settings-utils-lib.git",
|
|
32
|
-
"directory": "projects/su-labs/
|
|
33
|
+
"directory": "projects/su-labs/visit-tracker"
|
|
33
34
|
},
|
|
34
35
|
"bugs": {
|
|
35
36
|
"url": "https://github.com/Greezaaa/settings-utils-lib/issues"
|
package/public-api.d.ts
ADDED