{"id":21744315,"url":"https://github.com/oeo/trk2","last_synced_at":"2025-09-20T23:54:57.429Z","repository":{"id":259367640,"uuid":"877638666","full_name":"oeo/trk2","owner":"oeo","description":"a lightweight metrics tracking library for redis","archived":false,"fork":false,"pushed_at":"2024-10-24T16:53:03.000Z","size":571,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-25T22:22:06.458Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"CoffeeScript","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/oeo.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":"2024-10-24T01:33:50.000Z","updated_at":"2024-10-24T16:53:07.000Z","dependencies_parsed_at":"2024-10-24T22:18:14.947Z","dependency_job_id":"d2ccd79e-9234-4cf0-88e4-59fa2573d85c","html_url":"https://github.com/oeo/trk2","commit_stats":null,"previous_names":["oeo/trk2"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oeo%2Ftrk2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oeo%2Ftrk2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oeo%2Ftrk2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oeo%2Ftrk2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oeo","download_url":"https://codeload.github.com/oeo/trk2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244722653,"owners_count":20499151,"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":[],"created_at":"2024-11-26T07:11:06.298Z","updated_at":"2025-09-20T23:54:52.360Z","avatar_url":"https://github.com/oeo.png","language":"CoffeeScript","readme":"# trk2\n\na lightweight metrics tracking library for redis\n\n## installation\n\n```bash\nnpm install trk2 --save\n```\n\n## usage\n\n### basic setup\n\n```javascript\nconst Redis = require('ioredis');\nconst Metrics = require('trk2');\n\nconst redis = new Redis();\n\nconst metrics = new Metrics({\n  redis: redis,\n  key: 'myapp',\n  map: {\n    bmp: ['ip'],\n    add: ['event', 'event~offer'],\n    addv: [{ key: 'offer~event', addKey: 'amount' }],\n    top: ['geo', 'offer']\n  }\n});\n```\n\n### recording events\n\n```javascript\nawait metrics.record({\n  ip: '192.168.1.1',\n  event: 'offer_impression',\n  offer: '123456',\n  geo: 'US',\n  amount: 100\n});\n```\n\n\u003cp\u003e\n    \u003cimg src=\"https://github.com/oeo/trk2/blob/master/assets/redis-insight.png\" width=\"600\"\u003e\n\u003c/p\u003e\n\n### querying data\n\n```javascript\n// query last 10 days\nconst results = await metrics.queryDays(10);\n\n// get unique visitor counts\nconst unique = results.find({\n  type: 'bmp',\n  key: 'ip'\n});\n\n// get add value for amount\nconst addValue = results.find({\n  type: 'addv',\n  key: 'offer~event',\n  addKey: 'amount'\n});\n\n// get event counts\nconst impressions = results.find({\n  type: 'add',\n  key: 'event',\n  merge: false\n});\n\n// get top geos\nconst topGeos = results.find('top/geo');\n\n// get top offers\nconst topOffers = results.find('top/offer');\n```\n\n## api\n\n### `new Metrics(options)`\n\ncreates a new metrics instance.\n\n- `options.redis`: redis client instance\n- `options.key`: prefix for redis keys\n- `options.map`: configuration for tracking different metrics types\n\n### `metrics.record(event)`\n\nrecords a single event.\n\n### `metrics.queryDays(numDays)`\n\nqueries data for the last `numDays` days.\n\n### `results.find(options)`\n\nfinds specific metrics in the query results.\n\n- `options.type`: type of metric ('bmp', 'add', 'addv', 'top')\n- `options.key`: key for the metric\n- `options.addKey`: additional key for 'addv' type\n- `options.merge`: whether to merge results across days\n\n## examples\n\nsee the `src/examples` directory for more detailed usage examples.\n\n## performance\non my apple m2 max w 64gb ram\n\ncoffee/node\n\n```bash\ntaky:~/www/trk2/src$ coffee examples/record-events.coffee\n\nFinished recording 100000 events (series) in 12799ms\nSeries events digested/sec: 7813.110399249942\n\nFinished recording 100000 events (parallel) in 10263ms\nParallel events digested/sec: 9743.739647276625\n```\n\nbun\n\n```bash\ntaky:~/www/trk2/build$ bun examples/record-events.js\n\nFinished recording 100000 events (series) in 10294ms\nSeries events digested/sec: 9714.396735962697\n\nFinished recording 100000 events (parallel) in 7499ms\nParallel events digested/sec: 13335.111348179758\n```\n\n## license\n\nmit\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foeo%2Ftrk2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foeo%2Ftrk2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foeo%2Ftrk2/lists"}