npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@su-labs/visit-tracker

v21.0.5

Published

`@su-labs/visit-tracker`

Readme

SuVisitTrackerService

@su-labs/visit-tracker

Angular Angular Version TypeScript License NPM Size Downloads Version

A lightweight Angular service to track user visits. Provides reactive signals for visit count, last visit date, and milestone visits.

📚 Table of Contents

💡 Why Use This Library?

  • 🎯 Lightweight - Only ~5KB minified
  • Reactive - Built with Angular Signals
  • 🔒 Type-Safe - Full TypeScript support
  • 📦 Zero Dependencies - No bloat
  • 🧪 Well Tested - Comprehensive test coverage
  • 📝 Well Documented - Clear examples and API docs

Features

  • Tracks number of visits per user.
  • Persists visit data in localStorage.
  • Signals for milestones (e.g., 10th, 100th visit).
  • Reactive last visit date signal.
  • Configurable storage key and milestones.
  • Works seamlessly with standalone components and reactive Angular setups.

Installation

You can install this library via npm:

npm install @su-labs/visit-tracker

Peer Dependencies

This library requires the following peer dependencies:

npm install @angular/common@^21 @angular/core@^21

🚀 Quick Start

// 1. Install
npm install @su-labs/visit-tracker

// 2. Inject in your component
import { Component, inject } from '@angular/core';
import { SuVisitTrackerService } from '@su-labs/visit-tracker';

@Component({
  selector: 'app-root',
  template: `<p>Visits: {{ visitService.count() }}</p>`
})
export class AppComponent {
  visitService = inject(SuVisitTrackerService);
}

Usage

Example 1: Basic initialization

The service should be provided at the root level. To use it in a component, simply inject it:

import { Component, inject } from '@angular/core';
import { CommonModule, DatePipe } from '@angular/common';
import { SuVisitTrackerService } from '@su-labs/visit-tracker';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [CommonModule, DatePipe],
  template: `
    <h1>Welcome back!</h1>
    <p>You have visited {{ visitService.count() }} times.</p>
    <ng-container *ngIf="visitService.lastVisit() as last">
      <p>Last visit: {{ last | date:'medium' }}</p>
    </ng-container>
  `,
})
export class AppComponent {
  public readonly visitService = inject(SuVisitTrackerService);
}

✅ Automatically increments the visit count and updates the last visit timestamp.

Example 2: Checking milestone visits

You can reactively check if a milestone visit has been reached:

@if(visitService.isTenthVisit()){
  <p>🎉 Congratulations on your 10th visit!</p>
}

@if(visitService.isHundredthVisit()){
  <p>🏆 100 visits! You're a power user!</p>
}

Signals isTenthVisit and isHundredthVisit update automatically on service initialization.

Example 3: Custom configuration

For standalone apps, use provideAppInitializer to initialize the tracker with a custom storage key or milestones:

import { provideAppInitializer, inject } from '@angular/core';
import { SuVisitTrackerService, SuVisitTrackerConfig } from '@su-labs/visit-tracker';

const visitConfig: SuVisitTrackerConfig = {
  storageKey: 'myApp:visits',
  milestoneVisits: [5, 50, 500], // custom milestones
};

export const appConfig = {
  providers: [
    provideAppInitializer(() => {
      const tracker = inject(SuVisitTrackerService);
      tracker.init(visitConfig);
    }),
  ],
};

✅ Allows overriding the localStorage key and defining custom milestone visits.

Example 4: Using last visit date

@if(visitService.lastVisit() as last) {
  <p>
    Your last visit was on {{ last | date:'fullDate' }} at {{ last | date:'shortTime' }}
  </p>
}

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.

📖 API Reference

Signals

| Signal | Type | Description | |--------|------|-------------| | count() | number | Current visit count | | lastVisit() | string \| null | ISO string of last visit date | | isTenthVisit() | boolean | True if current count is 10 | | isHundredthVisit() | boolean | True if current count is 100 |

Methods

| Method | Parameters | Description | |--------|------------|-------------| | init(config?) | SuVisitTrackerConfig | Initialize with custom configuration |

Types

interface SuVisitTrackerConfig {
  storageKey?: string;        // Default: 'su:visits'
  milestoneVisits?: number[]; // Default: [10, 100]
}

Configuration Options

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.

| Option | Description | Default Value | |-------------------|---------------------------------------------------------------|------------------| | storageKey | The key used to persist the visit data in localStorage. | 'su:visits' | | milestoneVisits | An array of numbers representing visits to track as milestones. | [10, 100] |

🌐 Browser Compatibility

Works in all modern browsers that support:

  • ✅ localStorage API
  • ✅ Angular 21+
  • ✅ ES2022+

| Browser | Version | |---------|---------| | Chrome | ≥ 90 | | Firefox | ≥ 88 | | Safari | ≥ 14 | | Edge | ≥ 90 |

🔗 Related Libraries

Part of the @su-labs suite:

🔧 Troubleshooting

Visit count not persisting?

Make sure localStorage is enabled in your browser and not blocked by privacy settings.

Milestone signals not updating?

Milestones are only checked during service initialization. Call init() to recalculate.

TypeScript errors?

Ensure you have Angular 21+ and TypeScript 5.7+ installed.

💬 Support

Notes

  • Signals-based API: Perfect for standalone components and reactive Angular templates.
  • Persistence: Visit count and last visit are automatically stored in localStorage.
  • Lightweight: No external dependencies and minimal memory footprint.
  • Custom milestones: Track any number of user visit milestones reactively.

Contributing

If you find any bugs or have feature requests, please open an issue or submit a pull request on our GitHub repository.

To contribute code, please ensure your changes include unit tests to maintain code quality. Please see the main repository's README.md for details on the monorepo structure.

License

This project is licensed under the MIT License. See the LICENSE file for details.