Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@upstash/core-analytics

Package Overview
Dependencies
Maintainers
6
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@upstash/core-analytics

@upstash/core-analytics Serverless Analytics for Redis

  • 0.0.10
  • latest
  • npm
  • Socket score

Version published
Maintainers
6
Created
Source

@upstash/core-analytics

Serverless Analytics for Redis

This library offers some low level building blocks to record and analyze custom events in Redis. It's main purpose is to provide a simple way to record and query events in Redis without having to worry about the underlying data structure so we can build more advanced analytics features on top of it.

The quickstart below is slightly outdated. We're working on it.


Quickstart

  1. Create a redis database

Go to console.upstash.com/redis and create a new global database.

After creating the db, copy the UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN to your .env file.

  1. Install @upstash/core-analytics in your project
npm install @upstash/analytics @upstash/redis
  1. Create an analytics client
import { Analytics } from "@upstash/core-analytics";
import { Redis } from "@upstash/redis";

const analytics = new Analytics({
  redis: Redis.fromEnv(),
  window: "1d",
});
  1. Ingest some events

An event consists of a time field and any additional key-value pairs that you can use to record any information you want.

const event = {
  time: Date.now() // optional (default: Date.now())
  userId: "chronark",
  page: "/auth/login",
  country: "DE",
}

await analytics.ingest("pageviews", event);
  1. Query your events
const result = await analytics.query("pageviews");

Development

This project uses bun for dependency management.

Install dependencies
bun install
Build
bun build

Database Schema

All metrics are stored in Redis Hash data types and sharded into buckets based on the window option.

@upstash/analytics:{TABLE}:{TIMESTAMP}
  • TABLE is a namespace to group events together. ie for managing multiple projects int a single database
  • TIMESTAMP is the starting timestamp of each window

The field of each hash is a serialized JSON object with the user's event data and the value is the number of times this event has been recorded.

{
  "{\"page\": \"/auth/login\",\"country\": \"DE\"}": 5,
  "{\"page\": \"/auth/login\",\"country\": \"US\"}": 2
}

Keywords

FAQs

Package last updated on 19 Jul 2024

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