@etohq/analytics-posthog 1.5.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Etohq
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@etohq/types").ModuleProviderExports;
2
+ export default _default;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAKA,wBAEE"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@etohq/framework/utils");
4
+ const posthog_analytics_1 = require("./services/posthog-analytics");
5
+ const services = [posthog_analytics_1.PosthogAnalyticsService];
6
+ exports.default = (0, utils_1.ModuleProvider)(utils_1.Modules.ANALYTICS, {
7
+ services,
8
+ });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,kDAAgE;AAChE,oEAAsE;AAEtE,MAAM,QAAQ,GAAG,CAAC,2CAAuB,CAAC,CAAA;AAE1C,kBAAe,IAAA,sBAAc,EAAC,eAAO,CAAC,SAAS,EAAE;IAC/C,QAAQ;CACT,CAAC,CAAA"}
@@ -0,0 +1,18 @@
1
+ import { PosthogAnalyticsServiceOptions, Logger, ProviderIdentifyAnalyticsEventDTO, ProviderTrackAnalyticsEventDTO } from "@etohq/framework/types";
2
+ import { PostHog } from "posthog-node";
3
+ import { AbstractAnalyticsProviderService } from "@etohq/framework/utils";
4
+ type InjectedDependencies = {
5
+ logger: Logger;
6
+ };
7
+ export declare class PosthogAnalyticsService extends AbstractAnalyticsProviderService {
8
+ static identifier: string;
9
+ protected config_: PosthogAnalyticsServiceOptions;
10
+ protected logger_: Logger;
11
+ protected client_: PostHog;
12
+ constructor({ logger }: InjectedDependencies, options: PosthogAnalyticsServiceOptions);
13
+ track(data: ProviderTrackAnalyticsEventDTO): Promise<void>;
14
+ identify(data: ProviderIdentifyAnalyticsEventDTO): Promise<void>;
15
+ shutdown(): Promise<void>;
16
+ }
17
+ export {};
18
+ //# sourceMappingURL=posthog-analytics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"posthog-analytics.d.ts","sourceRoot":"","sources":["../../src/services/posthog-analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,EAC9B,MAAM,EACN,iCAAiC,EACjC,8BAA8B,EAC/B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,gCAAgC,EAAE,MAAM,wBAAwB,CAAA;AAEzE,KAAK,oBAAoB,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,qBAAa,uBAAwB,SAAQ,gCAAgC;IAC3E,MAAM,CAAC,UAAU,SAAsB;IACvC,SAAS,CAAC,OAAO,EAAE,8BAA8B,CAAA;IACjD,SAAS,CAAC,OAAO,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,OAAO,EAAE,OAAO,CAAA;gBAGxB,EAAE,MAAM,EAAE,EAAE,oBAAoB,EAChC,OAAO,EAAE,8BAA8B;IAenC,KAAK,CAAC,IAAI,EAAE,8BAA8B,GAAG,OAAO,CAAC,IAAI,CAAC;IA6B1D,QAAQ,CAAC,IAAI,EAAE,iCAAiC,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBhE,QAAQ;CAGf"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PosthogAnalyticsService = void 0;
4
+ const posthog_node_1 = require("posthog-node");
5
+ const utils_1 = require("@etohq/framework/utils");
6
+ class PosthogAnalyticsService extends utils_1.AbstractAnalyticsProviderService {
7
+ constructor({ logger }, options) {
8
+ super();
9
+ this.config_ = options;
10
+ this.logger_ = logger;
11
+ if (!options.posthogEventsKey) {
12
+ throw new Error("Posthog API key is not set, but is required");
13
+ }
14
+ this.client_ = new posthog_node_1.PostHog(options.posthogEventsKey, {
15
+ host: options.posthogHost || "https://eu.i.posthog.com",
16
+ });
17
+ }
18
+ async track(data) {
19
+ if (!data.event) {
20
+ throw new Error("Event name is required when tracking an event with Posthog");
21
+ }
22
+ if (!data.actor_id) {
23
+ throw new Error("Actor ID is required when tracking an event with Posthog");
24
+ }
25
+ if (data.group?.id && !data.group?.type) {
26
+ throw new Error("Group type is required if passing group id when tracking an event with Posthog");
27
+ }
28
+ this.client_.capture({
29
+ event: data.event,
30
+ distinctId: data.actor_id,
31
+ properties: data.properties,
32
+ groups: data.group?.id
33
+ ? { [data.group.type]: data.group.id }
34
+ : undefined,
35
+ });
36
+ }
37
+ async identify(data) {
38
+ if ("group" in data) {
39
+ this.client_.groupIdentify({
40
+ groupKey: data.group.id,
41
+ groupType: data.group.type,
42
+ properties: data.properties,
43
+ distinctId: data.actor_id,
44
+ });
45
+ }
46
+ else if (data.actor_id) {
47
+ this.client_.identify({
48
+ distinctId: data.actor_id,
49
+ properties: data.properties,
50
+ });
51
+ }
52
+ throw new Error("Actor or group is required when identifying an entity with Posthog");
53
+ }
54
+ async shutdown() {
55
+ await this.client_.shutdown();
56
+ }
57
+ }
58
+ exports.PosthogAnalyticsService = PosthogAnalyticsService;
59
+ PosthogAnalyticsService.identifier = "analytics-posthog";
60
+ //# sourceMappingURL=posthog-analytics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"posthog-analytics.js","sourceRoot":"","sources":["../../src/services/posthog-analytics.ts"],"names":[],"mappings":";;;AAMA,+CAAsC;AACtC,kDAAyE;AAMzE,MAAa,uBAAwB,SAAQ,wCAAgC;IAM3E,YACE,EAAE,MAAM,EAAwB,EAChC,OAAuC;QAEvC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QAErB,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;QAChE,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,IAAI,sBAAO,CAAC,OAAO,CAAC,gBAAgB,EAAE;YACnD,IAAI,EAAE,OAAO,CAAC,WAAW,IAAI,0BAA0B;SACxD,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAoC;QAC9C,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAA;QACH,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,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AAA;IAC/B,CAAC;;AA1EH,0DA2EC;AA1EQ,kCAAU,GAAG,mBAAmB,CAAA"}
@@ -0,0 +1 @@
1
+ {"root":["../src/index.ts","../src/services/posthog-analytics.ts"],"version":"5.8.3"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@etohq/analytics-posthog",
3
+ "version": "1.5.0",
4
+ "description": "Posthog analytics provider for Eto",
5
+ "main": "dist/index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/etohq/eto",
9
+ "directory": "packages/core/modules/providers/analytics-posthog"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "!dist/**/__tests__",
14
+ "!dist/**/__mocks__",
15
+ "!dist/**/__fixtures__"
16
+ ],
17
+ "engines": {
18
+ "node": ">=20"
19
+ },
20
+ "author": "Eto",
21
+ "license": "MIT",
22
+ "devDependencies": {
23
+ "@swc/core": "1.7.28",
24
+ "@swc/jest": "0.2.36",
25
+ "@types/jest": "29.5.14",
26
+ "jest": "29.7.0",
27
+ "rimraf": "5.0.2",
28
+ "tsc-alias": "1.8.6",
29
+ "typescript": "5.8.3",
30
+ "posthog-node": "^4.17.1",
31
+ "@etohq/framework": "1.5.0"
32
+ },
33
+ "peerDependencies": {
34
+ "posthog-node": "^4.17.1",
35
+ "@etohq/framework": "1.5.0"
36
+ },
37
+ "keywords": [
38
+ "eto-plugin",
39
+ "eto-plugin-analytics"
40
+ ],
41
+ "scripts": {
42
+ "test": "jest --passWithNoTests src",
43
+ "build": "rimraf dist && tsc --build ./tsconfig.json",
44
+ "watch": "tsc --watch"
45
+ }
46
+ }