@ooneex/analytics 0.0.19 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,8 @@
1
1
  # @ooneex/analytics
2
2
 
3
- An analytics and event tracking integration library for TypeScript applications. This package provides seamless integration with PostHog for user behavior insights, product analytics, and event tracking across your applications.
3
+ PostHog-powered analytics integration for tracking user behavior, product events, and feature usage with decorator-based service registration.
4
4
 
5
5
  ![Bun](https://img.shields.io/badge/Bun-Compatible-orange?style=flat-square&logo=bun)
6
- ![Deno](https://img.shields.io/badge/Deno-Compatible-blue?style=flat-square&logo=deno)
7
- ![Node.js](https://img.shields.io/badge/Node.js-Compatible-green?style=flat-square&logo=node.js)
8
6
  ![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue?style=flat-square&logo=typescript)
9
7
  ![MIT License](https://img.shields.io/badge/License-MIT-yellow?style=flat-square)
10
8
 
@@ -24,26 +22,10 @@ An analytics and event tracking integration library for TypeScript applications.
24
22
 
25
23
  ## Installation
26
24
 
27
- ### Bun
28
25
  ```bash
29
26
  bun add @ooneex/analytics
30
27
  ```
31
28
 
32
- ### pnpm
33
- ```bash
34
- pnpm add @ooneex/analytics
35
- ```
36
-
37
- ### Yarn
38
- ```bash
39
- yarn add @ooneex/analytics
40
- ```
41
-
42
- ### npm
43
- ```bash
44
- npm install @ooneex/analytics
45
- ```
46
-
47
29
  ## Usage
48
30
 
49
31
  ### Basic Event Tracking
@@ -132,12 +114,12 @@ Main analytics class for PostHog integration.
132
114
 
133
115
  **Constructor:**
134
116
  ```typescript
135
- new PostHogAnalytics(options?: { apiKey?: string; host?: string })
117
+ new PostHogAnalytics(config?: PostHogConfigType)
136
118
  ```
137
119
 
138
120
  **Parameters:**
139
- - `options.apiKey` - PostHog API key (optional if set via environment variable)
140
- - `options.host` - PostHog host URL (optional, defaults to EU region)
121
+ - `config.apiKey` - PostHog API key (optional if set via environment variable)
122
+ - `config.host` - PostHog host URL (optional, defaults to EU region)
141
123
 
142
124
  **Methods:**
143
125
 
@@ -175,6 +157,15 @@ interface IAnalytics<T = any> {
175
157
 
176
158
  ### Types
177
159
 
160
+ #### `PostHogConfigType`
161
+
162
+ ```typescript
163
+ type PostHogConfigType = {
164
+ apiKey?: string;
165
+ host?: string;
166
+ };
167
+ ```
168
+
178
169
  #### `PostHogCaptureOptionsType`
179
170
 
180
171
  ```typescript
package/dist/index.d.ts CHANGED
@@ -7,6 +7,10 @@ type AnalyticsClassType = new (...args: any[]) => IAnalytics;
7
7
  interface IAnalytics<T = any> {
8
8
  capture: (options: T) => void;
9
9
  }
10
+ type PostHogConfigType = {
11
+ apiKey?: string;
12
+ host?: string;
13
+ };
10
14
  type PostHogCaptureOptionsType = {
11
15
  id: string;
12
16
  event: string;
@@ -18,7 +22,7 @@ declare const decorator: {
18
22
  };
19
23
  declare class PostHogAnalytics<T extends PostHogCaptureOptionsType = PostHogCaptureOptionsType> implements IAnalytics<T> {
20
24
  private client;
21
- constructor();
25
+ constructor(config?: PostHogConfigType);
22
26
  capture(options: T): void;
23
27
  }
24
- export { decorator, PostHogCaptureOptionsType, PostHogAnalytics, IAnalytics, AnalyticsException, AnalyticsClassType };
28
+ export { decorator, PostHogConfigType, PostHogCaptureOptionsType, PostHogAnalytics, IAnalytics, AnalyticsException, AnalyticsClassType };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- var l=function(t,e,r,n){var s=arguments.length,o=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,p;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")o=Reflect.decorate(t,e,r,n);else for(var c=t.length-1;c>=0;c--)if(p=t[c])o=(s<3?p(o):s>3?p(e,r,o):p(e,r))||o;return s>3&&o&&Object.defineProperty(e,r,o),o};var u=(t,e)=>{if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(t,e)};import{Exception as y}from"@ooneex/exception";import{HttpStatus as d}from"@ooneex/http-status";class i extends y{constructor(t,e={}){super(t,{status:d.Code.InternalServerError,data:e});this.name="AnalyticsException"}}import{container as A,EContainerScope as T}from"@ooneex/container";var m={analytics:(t=T.Singleton)=>{return(e)=>{A.add(e,t)}}};import{PostHog as h}from"posthog-node";class a{client=null;constructor(){let t=Bun.env.ANALYTICS_POSTHOG_API_KEY;if(!t)throw new i("PostHog API key is required. Please provide an API key either through the constructor options or set the ANALYTICS_POSTHOG_API_KEY environment variable.");this.client=new h(t,{host:Bun.env.ANALYTICS_POSTHOG_HOST||"https://eu.i.posthog.com"})}capture(t){this.client?.capture({distinctId:t.id,event:t.event,properties:{$set:t.properties},timestamp:new Date,...t.groups&&{groups:t.groups}}),this.client?.shutdown()}}a=l([m.analytics(),u("design:paramtypes",[])],a);export{m as decorator,a as PostHogAnalytics,i as AnalyticsException};
2
+ var l=function(t,e,r,n){var s=arguments.length,o=s<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,p;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")o=Reflect.decorate(t,e,r,n);else for(var c=t.length-1;c>=0;c--)if(p=t[c])o=(s<3?p(o):s>3?p(e,r,o):p(e,r))||o;return s>3&&o&&Object.defineProperty(e,r,o),o};var y=(t,e)=>{if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(t,e)};import{Exception as u}from"@ooneex/exception";import{HttpStatus as d}from"@ooneex/http-status";class i extends u{constructor(t,e={}){super(t,{status:d.Code.InternalServerError,data:e});this.name="AnalyticsException"}}import{container as T,EContainerScope as h}from"@ooneex/container";var m={analytics:(t=h.Singleton)=>{return(e)=>{T.add(e,t)}}};import{PostHog as A}from"posthog-node";class a{client=null;constructor(t){let e=t?.apiKey||Bun.env.ANALYTICS_POSTHOG_API_KEY?.trim();if(!e)throw new i("PostHog API key is required. Please provide an API key either through the constructor options or set the ANALYTICS_POSTHOG_API_KEY environment variable.");this.client=new A(e,{host:t?.host||Bun.env.ANALYTICS_POSTHOG_HOST?.trim()||"https://eu.i.posthog.com"})}capture(t){this.client?.capture({distinctId:t.id,event:t.event,properties:{$set:t.properties},timestamp:new Date,...t.groups&&{groups:t.groups}}),this.client?.shutdown()}}a=l([m.analytics(),y("design:paramtypes",[typeof PostHogConfigType==="undefined"?Object:PostHogConfigType])],a);export{m as decorator,a as PostHogAnalytics,i as AnalyticsException};
3
3
 
4
- //# debugId=21DFF7C92F21B38E64756E2164756E21
4
+ //# debugId=C749A77AE7365C8764756E2164756E21
package/dist/index.js.map CHANGED
@@ -4,9 +4,9 @@
4
4
  "sourcesContent": [
5
5
  "import { Exception } from \"@ooneex/exception\";\nimport { HttpStatus } from \"@ooneex/http-status\";\n\nexport class AnalyticsException extends Exception {\n constructor(message: string, data: Record<string, unknown> = {}) {\n super(message, {\n status: HttpStatus.Code.InternalServerError,\n data,\n });\n\n this.name = \"AnalyticsException\";\n }\n}\n",
6
6
  "import { container, EContainerScope } from \"@ooneex/container\";\nimport type { AnalyticsClassType } from \"./types\";\n\nexport const decorator = {\n analytics: (scope: EContainerScope = EContainerScope.Singleton) => {\n return (target: AnalyticsClassType): void => {\n container.add(target, scope);\n };\n },\n};\n",
7
- "import { PostHog } from \"posthog-node\";\nimport { AnalyticsException } from \"./AnalyticsException\";\nimport { decorator } from \"./decorators\";\nimport type { IAnalytics, PostHogCaptureOptionsType } from \"./types\";\n\n@decorator.analytics()\nexport class PostHogAnalytics<T extends PostHogCaptureOptionsType = PostHogCaptureOptionsType>\n implements IAnalytics<T>\n{\n private client: PostHog | null = null;\n\n constructor() {\n const apiKey = Bun.env.ANALYTICS_POSTHOG_API_KEY;\n\n if (!apiKey) {\n throw new AnalyticsException(\n \"PostHog API key is required. Please provide an API key either through the constructor options or set the ANALYTICS_POSTHOG_API_KEY environment variable.\",\n );\n }\n\n this.client = new PostHog(apiKey, {\n host: Bun.env.ANALYTICS_POSTHOG_HOST || \"https://eu.i.posthog.com\",\n });\n }\n\n public capture(options: T): void {\n this.client?.capture({\n distinctId: options.id,\n event: options.event,\n properties: {\n $set: options.properties,\n },\n timestamp: new Date(),\n ...(options.groups && { groups: options.groups }),\n });\n this.client?.shutdown();\n }\n}\n"
7
+ "import { PostHog } from \"posthog-node\";\nimport { AnalyticsException } from \"./AnalyticsException\";\nimport { decorator } from \"./decorators\";\nimport type { IAnalytics, PostHogCaptureOptionsType, PostHogConfigType } from \"./types\";\n\n@decorator.analytics()\nexport class PostHogAnalytics<T extends PostHogCaptureOptionsType = PostHogCaptureOptionsType>\n implements IAnalytics<T>\n{\n private client: PostHog | null = null;\n\n constructor(config?: PostHogConfigType) {\n const apiKey = config?.apiKey || Bun.env.ANALYTICS_POSTHOG_API_KEY?.trim();\n\n if (!apiKey) {\n throw new AnalyticsException(\n \"PostHog API key is required. Please provide an API key either through the constructor options or set the ANALYTICS_POSTHOG_API_KEY environment variable.\",\n );\n }\n\n this.client = new PostHog(apiKey, {\n host: config?.host || Bun.env.ANALYTICS_POSTHOG_HOST?.trim() || \"https://eu.i.posthog.com\",\n });\n }\n\n public capture(options: T): void {\n this.client?.capture({\n distinctId: options.id,\n event: options.event,\n properties: {\n $set: options.properties,\n },\n timestamp: new Date(),\n ...(options.groups && { groups: options.groups }),\n });\n this.client?.shutdown();\n }\n}\n"
8
8
  ],
9
- "mappings": ";ybAAA,oBAAS,0BACT,qBAAS,4BAEF,MAAM,UAA2B,CAAU,CAChD,WAAW,CAAC,EAAiB,EAAgC,CAAC,EAAG,CAC/D,MAAM,EAAS,CACb,OAAQ,EAAW,KAAK,oBACxB,MACF,CAAC,EAED,KAAK,KAAO,qBAEhB,CCZA,oBAAS,qBAAW,0BAGb,IAAM,EAAY,CACvB,UAAW,CAAC,EAAyB,EAAgB,YAAc,CACjE,MAAO,CAAC,IAAqC,CAC3C,EAAU,IAAI,EAAQ,CAAK,GAGjC,ECTA,kBAAS,qBAMF,MAAM,CAEb,CACU,OAAyB,KAEjC,WAAW,EAAG,CACZ,IAAM,EAAS,IAAI,IAAI,0BAEv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AE,OAAQ,EAAQ,MAAO,CACjD,CAAC,EACD,KAAK,QAAQ,SAAS,EAE1B,CA/Ba,EAAN,GADN,EAAU,UAAU,EACd,0FAAM",
10
+ "debugId": "C749A77AE7365C8764756E2164756E21",
11
11
  "names": []
12
12
  }
package/package.json CHANGED
@@ -1,16 +1,13 @@
1
1
  {
2
2
  "name": "@ooneex/analytics",
3
- "description": "Analytics and event tracking integration with PostHog for user behavior insights and product analytics",
4
- "version": "0.0.19",
5
- "type": "module",
6
- "files": [
7
- "dist",
8
- "LICENSE",
9
- "README.md",
10
- "package.json"
11
- ],
3
+ "version": "1.0.1",
12
4
  "module": "./dist/index.js",
13
- "types": "./dist/index.d.ts",
5
+ "dependencies": {
6
+ "@ooneex/container": "1.0.1",
7
+ "@ooneex/exception": "1.0.1",
8
+ "@ooneex/http-status": "1.0.1",
9
+ "posthog-node": "^5.11.0"
10
+ },
14
11
  "exports": {
15
12
  ".": {
16
13
  "import": {
@@ -20,19 +17,13 @@
20
17
  },
21
18
  "./package.json": "./package.json"
22
19
  },
23
- "license": "MIT",
24
- "scripts": {
25
- "test": "bun test tests",
26
- "build": "bunup",
27
- "lint": "tsgo --noEmit && bunx biome lint",
28
- "npm:publish": "bun publish --tolerate-republish --access public"
29
- },
30
- "dependencies": {
31
- "@ooneex/container": "0.0.18",
32
- "@ooneex/exception": "0.0.17",
33
- "@ooneex/http-status": "0.0.17",
34
- "posthog-node": "^5.11.0"
35
- },
20
+ "description": "PostHog-powered analytics integration for tracking user behavior, product events, and feature usage with decorator-based service registration",
21
+ "files": [
22
+ "dist",
23
+ "LICENSE",
24
+ "README.md",
25
+ "package.json"
26
+ ],
36
27
  "keywords": [
37
28
  "analytics",
38
29
  "bun",
@@ -42,5 +33,14 @@
42
33
  "statistics",
43
34
  "tracking",
44
35
  "typescript"
45
- ]
36
+ ],
37
+ "license": "MIT",
38
+ "scripts": {
39
+ "test": "bun test tests",
40
+ "build": "bunup",
41
+ "lint": "tsgo --noEmit && bunx biome lint",
42
+ "npm:publish": "bun publish --tolerate-republish --force --production --access public"
43
+ },
44
+ "type": "module",
45
+ "types": "./dist/index.d.ts"
46
46
  }