View Count

A simple, embeddable view counter badge for any website.
Track page views and unique visitors with a beautiful SVG badge.

views visitors

Quick Start

The easiest way to use View Count is with the hosted service. Just embed an image tag on your page.

Customize

preview
<img src="https://view-count.cloudtion.com/views" alt="views" />

How It Works

When the image loads, the counter reads the Referer header to identify which page the badge is embedded on.

Each unique page URL gets its own view/visitor count.

The badge is cached by the browser (default: 30 minutes) to prevent excessive counting.

Unique visitors are tracked by hashing IP + User-Agent.

Self-Hosted

Install view-count as a library to run your own counter service. Powered by Firebase or Express.js with SQLite.

Installation

npm install view-count

Basic Setup

import { createViewCounter } from 'view-count';

const counter = createViewCounter({
  firebaseConfig: {
    projectId: 'your-project-id',
    clientEmail: 'your-service-account@project.iam.gserviceaccount.com',
    privateKey: '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n',
    collectionName: 'view-counts',
  },
});

// Use with Express
app.get('/views', counter.handler);
app.get('/visitors', counter.handler);

See the full documentation for Firebase Functions deployment, Vercel examples, and API reference.

API Reference

createViewCounter(options)

Creates a new view counter instance.

Returns:

  • handler(req, res) - Express-compatible request handler
  • getStats(pageUrl) - Get stats for a page without incrementing
  • recordView(pageUrl, visitorId) - Manually record a view
  • preview(count, mode?, color?) - Generate SVG without recording