{"id":29029390,"url":"https://github.com/upstash/core-analytics","last_synced_at":"2025-06-26T08:06:55.211Z","repository":{"id":156579748,"uuid":"599480382","full_name":"upstash/core-analytics","owner":"upstash","description":"Low level analytics building blocks for redis ","archived":false,"fork":false,"pushed_at":"2024-07-19T09:54:35.000Z","size":499,"stargazers_count":16,"open_issues_count":1,"forks_count":0,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-06-05T22:38:37.485Z","etag":null,"topics":["analytics","edge","redis","serverless","upstash","upstash-sdk"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/upstash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-09T08:20:09.000Z","updated_at":"2025-04-09T10:24:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"a25554e4-9fac-48db-bbf1-151fee0fe7f9","html_url":"https://github.com/upstash/core-analytics","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/upstash/core-analytics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upstash%2Fcore-analytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upstash%2Fcore-analytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upstash%2Fcore-analytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upstash%2Fcore-analytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/upstash","download_url":"https://codeload.github.com/upstash/core-analytics/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upstash%2Fcore-analytics/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259576736,"owners_count":22879173,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics","edge","redis","serverless","upstash","upstash-sdk"],"created_at":"2025-06-26T08:06:53.900Z","updated_at":"2025-06-26T08:06:55.206Z","avatar_url":"https://github.com/upstash.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003ch1 align=\"center\"\u003e@upstash/core-analytics\u003c/h1\u003e\n    \u003ch5\u003eServerless Analytics for Redis\u003c/h5\u003e\n\u003c/div\u003e\n\n\u003cbr/\u003e\n\nThis library offers some low level building blocks to record and analyze custom events in Redis.\nIt'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.\n\nThe quickstart below is slightly outdated. We're working on it.\n\n\u003cbr/\u003e\n\n## Quickstart\n\n1. Create a redis database\n\nGo to [console.upstash.com/redis](https://console.upstash.com/redis) and create\na new global database.\n\nAfter creating the db, copy the `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` to your `.env` file.\n\n3. Install `@upstash/core-analytics` in your project\n\n```bash\nnpm install @upstash/analytics @upstash/redis\n```\n\n4. Create an analytics client\n\n```ts\nimport { Analytics } from \"@upstash/core-analytics\";\nimport { Redis } from \"@upstash/redis\";\n\nconst analytics = new Analytics({\n  redis: Redis.fromEnv(),\n  window: \"1d\",\n});\n```\n\n5. Ingest some events\n\nAn event consists of a `time` field and any additional key-value pairs that you can use to record any information you want.\n\n```ts\nconst event = {\n  time: Date.now() // optional (default: Date.now())\n  userId: \"chronark\",\n  page: \"/auth/login\",\n  country: \"DE\",\n}\n\nawait analytics.ingest(\"pageviews\", event);\n```\n\n4. Query your events\n\n```ts\nconst result = await analytics.query(\"pageviews\");\n```\n\n## Development\n\nThis project uses `bun` for dependency management.\n\n#### Install dependencies\n\n```bash\nbun install\n```\n\n#### Build\n\n```bash\nbun build\n```\n\n## Database Schema\n\nAll metrics are stored in Redis `Hash` data types and sharded into buckets based on the `window` option.\n\n```\n@upstash/analytics:{TABLE}:{TIMESTAMP}\n```\n\n- `TABLE` is a namespace to group events together. ie for managing multiple projects int a single database\n- `TIMESTAMP` is the starting timestamp of each window\n\nThe 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.\n\n```json\n{\n  \"{\\\"page\\\": \\\"/auth/login\\\",\\\"country\\\": \\\"DE\\\"}\": 5,\n  \"{\\\"page\\\": \\\"/auth/login\\\",\\\"country\\\": \\\"US\\\"}\": 2\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupstash%2Fcore-analytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fupstash%2Fcore-analytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupstash%2Fcore-analytics/lists"}