vcomply-analytics 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.
@@ -0,0 +1,43 @@
1
+ // src/core/events.ts
2
+ var EVENTS = {
3
+ BACKEND_SERVICE_CALL: {
4
+ API_CALLED: "api_called"
5
+ },
6
+ FRONTEND_EVENTS: {
7
+ PAGE_VIEWED: "page_viewed",
8
+ FORM_OPENED: "form_opened",
9
+ POLICY_CREATED: "policy_created",
10
+ BUTTON_CLICKED: "button_clicked"
11
+ }
12
+ };
13
+
14
+ // src/runtime/browser.ts
15
+ import posthog from "posthog-js";
16
+ function initBrowser(apiKey, host) {
17
+ posthog.init(apiKey, { api_host: host });
18
+ }
19
+ function trackBrowser(event, distinctId, properties) {
20
+ properties.distinct_id = distinctId;
21
+ posthog.capture(event, properties);
22
+ }
23
+
24
+ // src/core/analytics.browser.ts
25
+ var Analytics = class {
26
+ constructor() {
27
+ this.initialized = false;
28
+ }
29
+ init(config) {
30
+ if (this.initialized) return;
31
+ initBrowser(config.apiKey, config.host);
32
+ this.initialized = true;
33
+ }
34
+ async track(config) {
35
+ if (!this.initialized) return;
36
+ trackBrowser(config.event, config.distinctId, config.properties);
37
+ }
38
+ };
39
+ var analytics = new Analytics();
40
+ export {
41
+ EVENTS,
42
+ analytics
43
+ };
@@ -0,0 +1,32 @@
1
+ declare const EVENTS: {
2
+ readonly BACKEND_SERVICE_CALL: {
3
+ readonly API_CALLED: "api_called";
4
+ };
5
+ readonly FRONTEND_EVENTS: {
6
+ readonly PAGE_VIEWED: "page_viewed";
7
+ readonly FORM_OPENED: "form_opened";
8
+ readonly POLICY_CREATED: "policy_created";
9
+ readonly BUTTON_CLICKED: "button_clicked";
10
+ };
11
+ };
12
+
13
+ interface AnalyticsConfig {
14
+ apiKey: string;
15
+ host?: string;
16
+ serviceName: string;
17
+ environment?: string;
18
+ }
19
+ interface TrackEventPayload {
20
+ event: string;
21
+ distinctId: string;
22
+ properties?: Record<string, unknown>;
23
+ }
24
+
25
+ declare class Analytics {
26
+ private initialized;
27
+ init(config: AnalyticsConfig): void;
28
+ track(config: TrackEventPayload): Promise<void>;
29
+ }
30
+ declare const analytics: Analytics;
31
+
32
+ export { EVENTS, analytics };
@@ -0,0 +1,32 @@
1
+ declare const EVENTS: {
2
+ readonly BACKEND_SERVICE_CALL: {
3
+ readonly API_CALLED: "api_called";
4
+ };
5
+ readonly FRONTEND_EVENTS: {
6
+ readonly PAGE_VIEWED: "page_viewed";
7
+ readonly FORM_OPENED: "form_opened";
8
+ readonly POLICY_CREATED: "policy_created";
9
+ readonly BUTTON_CLICKED: "button_clicked";
10
+ };
11
+ };
12
+
13
+ interface AnalyticsConfig {
14
+ apiKey: string;
15
+ host?: string;
16
+ serviceName: string;
17
+ environment?: string;
18
+ }
19
+ interface TrackEventPayload {
20
+ event: string;
21
+ distinctId: string;
22
+ properties?: Record<string, unknown>;
23
+ }
24
+
25
+ declare class Analytics {
26
+ private initialized;
27
+ init(config: AnalyticsConfig): void;
28
+ track(config: TrackEventPayload): Promise<void>;
29
+ }
30
+ declare const analytics: Analytics;
31
+
32
+ export { EVENTS, analytics };
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.node.ts
21
+ var index_node_exports = {};
22
+ __export(index_node_exports, {
23
+ EVENTS: () => EVENTS,
24
+ analytics: () => analytics
25
+ });
26
+ module.exports = __toCommonJS(index_node_exports);
27
+
28
+ // src/core/events.ts
29
+ var EVENTS = {
30
+ BACKEND_SERVICE_CALL: {
31
+ API_CALLED: "api_called"
32
+ },
33
+ FRONTEND_EVENTS: {
34
+ PAGE_VIEWED: "page_viewed",
35
+ FORM_OPENED: "form_opened",
36
+ POLICY_CREATED: "policy_created",
37
+ BUTTON_CLICKED: "button_clicked"
38
+ }
39
+ };
40
+
41
+ // src/runtime/node.ts
42
+ var import_posthog_node = require("posthog-node");
43
+ var client = null;
44
+ function initNode(apiKey, host) {
45
+ if (!client) {
46
+ client = new import_posthog_node.PostHog(apiKey, { host });
47
+ }
48
+ }
49
+ async function trackNode(event, properties) {
50
+ await client?.capture({
51
+ event,
52
+ distinctId: properties?.distinctId || "server",
53
+ properties
54
+ });
55
+ }
56
+
57
+ // src/core/analytics.node.ts
58
+ var Analytics = class {
59
+ constructor() {
60
+ this.initialized = false;
61
+ }
62
+ init(config) {
63
+ if (this.initialized) return;
64
+ initNode(config.apiKey, config.host);
65
+ this.initialized = true;
66
+ }
67
+ async track(config) {
68
+ if (!this.initialized) return;
69
+ await trackNode(config.event, config.properties);
70
+ }
71
+ };
72
+ var analytics = new Analytics();
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ EVENTS,
76
+ analytics
77
+ });
@@ -0,0 +1,49 @@
1
+ // src/core/events.ts
2
+ var EVENTS = {
3
+ BACKEND_SERVICE_CALL: {
4
+ API_CALLED: "api_called"
5
+ },
6
+ FRONTEND_EVENTS: {
7
+ PAGE_VIEWED: "page_viewed",
8
+ FORM_OPENED: "form_opened",
9
+ POLICY_CREATED: "policy_created",
10
+ BUTTON_CLICKED: "button_clicked"
11
+ }
12
+ };
13
+
14
+ // src/runtime/node.ts
15
+ import { PostHog } from "posthog-node";
16
+ var client = null;
17
+ function initNode(apiKey, host) {
18
+ if (!client) {
19
+ client = new PostHog(apiKey, { host });
20
+ }
21
+ }
22
+ async function trackNode(event, properties) {
23
+ await client?.capture({
24
+ event,
25
+ distinctId: properties?.distinctId || "server",
26
+ properties
27
+ });
28
+ }
29
+
30
+ // src/core/analytics.node.ts
31
+ var Analytics = class {
32
+ constructor() {
33
+ this.initialized = false;
34
+ }
35
+ init(config) {
36
+ if (this.initialized) return;
37
+ initNode(config.apiKey, config.host);
38
+ this.initialized = true;
39
+ }
40
+ async track(config) {
41
+ if (!this.initialized) return;
42
+ await trackNode(config.event, config.properties);
43
+ }
44
+ };
45
+ var analytics = new Analytics();
46
+ export {
47
+ EVENTS,
48
+ analytics
49
+ };
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "vcomply-analytics",
3
+ "version": "1.0.1",
4
+ "main": "dist/index.node.js",
5
+ "module": "dist/index.node.mjs",
6
+ "browser": "dist/index.browser.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "browser": "./dist/index.browser.mjs",
11
+ "require": "./dist/index.node.js",
12
+ "import": "./dist/index.node.mjs"
13
+ }
14
+ },
15
+ "files": ["dist"],
16
+ "scripts": {
17
+ "test": "echo \"Error: no test specified\" && exit 1",
18
+ "build": "tsup src/index.browser.ts --format esm --platform browser --out-dir dist --no-dts && tsup src/index.node.ts --format cjs,esm --platform node --out-dir dist --dts"
19
+ },
20
+ "keywords": [],
21
+ "author": "",
22
+ "license": "ISC",
23
+ "description": "",
24
+ "dependencies": {
25
+ "posthog-js": "^1.353.1",
26
+ "posthog-node": "^5.21.2"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^25.3.0",
30
+ "tsup": "^8.5.1",
31
+ "typescript": "^5.9.3"
32
+ }
33
+ }