New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

anonymous-analytics

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anonymous-analytics

A privacy-friendly server-side analytics library.

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

anonymous-analytics

A privacy-friendly server-side analytics library.

Getting started

Install

From npm

  • yarn install anonymous-analytics

or

  • npm install anonymous analytics

Usage

Create a new analytics database (e.g. named test).

const
    Analytics = require('anonymous-analytics'),
    testAnalytics = new Analytics('test');

Populate the database with your endpoint's data.

  • Default fingerprint : IP address (+ eventual reverse proxy IP) + user agent.
  • Default extra payload : IP address country.
Express
const
    express = require('express'),
    app = express();
app.get('/test', async (request, response) => {
    await testAnalytics.addFromExpress(request);
    res.status(204).send();
});
Fastify
const
    fastify = require('fastify'),
    app = fastify();
app.get('/test', async (request, reply) => {
    await testAnalytics.addFromFastify(request);
    reply.code(204).send();
});
Custom
myTestHandler((myRequestContext, myResponseHandler) => {
    const {
        uniqueProperty1,
        uniqueProperty2,
        usefulPropertyA,
        usefulPropertyB
    } = myResponseHandler;
    testAnalytics.add(
        uniqueProperty1 + uniqueProperty2, // Fingerprint (string)
        { usefulPropertyA, usefulPropertyB } // Extra payload (object)
    );
    myResponseHandler(myResponseContext);
});

Read the data as stats.

await testAnalytics.getStats(
    fromDayTimestamp,
    toDayTimestamp,
    convertToYYYYMMDD
);
{
    "uniqueCount": 321,
    "totalCount": 654,
    "days": {
        "2020-01-01": {
            "uniqueCount": 123,
            "totalCount": 456
        }
    },
    "countries": {
        "France": {
            "uniqueCount": 12,
            "totalCount": 345
        }
    }
}

FAQ

How is user privacy protected ?

User fingerprints are hashed using SHA256 and timestamps are rounded to the day.

Changelog

  • 1.0.0 (2021-01-22) • Initial release

FAQs

Package last updated on 22 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc