@acmekit/analytics-posthog 2.13.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 ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@acmekit/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("@acmekit/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,oDAAkE;AAClE,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 { Logger, PosthogAnalyticsServiceOptions, ProviderIdentifyAnalyticsEventDTO, ProviderTrackAnalyticsEventDTO } from "@acmekit/framework/types";
2
+ import { AbstractAnalyticsProviderService } from "@acmekit/framework/utils";
3
+ import { PostHog } from "posthog-node";
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,MAAM,EACN,8BAA8B,EAC9B,iCAAiC,EACjC,8BAA8B,EAC/B,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,gCAAgC,EAAE,MAAM,0BAA0B,CAAA;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,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,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PosthogAnalyticsService = void 0;
4
+ const utils_1 = require("@acmekit/framework/utils");
5
+ const posthog_node_1 = require("posthog-node");
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
+ else {
53
+ throw new Error("Actor or group is required when identifying an entity with Posthog");
54
+ }
55
+ }
56
+ async shutdown() {
57
+ await this.client_.shutdown();
58
+ }
59
+ }
60
+ exports.PosthogAnalyticsService = PosthogAnalyticsService;
61
+ PosthogAnalyticsService.identifier = "analytics-posthog";
62
+ //# 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,oDAA2E;AAC3E,+CAAsC;AAMtC,MAAa,uBAAwB,SAAQ,wCAAgC;IAM3E,YACE,EAAE,MAAM,EAAwB,EAChC,OAAuC;QAEvC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,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C,KAAK,CAAC,EAAG;gBACxB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,IAAK;gBAC3B,UAAU,EAAE,IAAI,CAAC,UAAU;gBAC3B,UAAU,EAAE,IAAI,CAAC,QAAQ;aAC1B,CAAC,CAAA;QACJ,CAAC;aAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACzB,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;gBACpB,UAAU,EAAE,IAAI,CAAC,QAAQ;gBACzB,UAAU,EAAE,IAAI,CAAC,UAAU;aAC5B,CAAC,CAAA;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAA;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAA;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.9.3"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@acmekit/analytics-posthog",
3
+ "version": "2.13.1",
4
+ "description": "Posthog analytics provider for AcmeKit",
5
+ "main": "dist/index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/acmekit/acmekit",
9
+ "directory": "packages/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": "AcmeKit",
21
+ "license": "MIT",
22
+ "scripts": {
23
+ "test": "../../../../node_modules/.bin/jest --passWithNoTests src",
24
+ "build": "yarn run -T rimraf dist && yarn run -T tsc --build ./tsconfig.json",
25
+ "watch": "yarn run -T tsc --watch"
26
+ },
27
+ "devDependencies": {
28
+ "@acmekit/framework": "2.13.1",
29
+ "posthog-node": "^5.11.0"
30
+ },
31
+ "peerDependencies": {
32
+ "@acmekit/framework": "2.13.1",
33
+ "posthog-node": "^5.11.0"
34
+ },
35
+ "keywords": [
36
+ "acmekit-plugin",
37
+ "acmekit-plugin-analytics"
38
+ ]
39
+ }