@plasius/ui-foundry-analytics-appinsights 0.1.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/CHANGELOG.md +38 -0
- package/README.md +133 -0
- package/dist/index.cjs +74 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on **[Keep a Changelog](https://keepachangelog.com/en/1.1.0/)**, and this project adheres to **[Semantic Versioning](https://semver.org/spec/v2.0.0.html)**.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## [Unreleased]
|
|
10
|
+
|
|
11
|
+
- **Added**
|
|
12
|
+
- Added package-local adapter tests covering track, page, identify, group, and flush behavior.
|
|
13
|
+
|
|
14
|
+
- **Changed**
|
|
15
|
+
- Align package metadata for dual ESM/CJS outputs with consistent `main`/`module` fields.
|
|
16
|
+
- Switched App Insights adapter type imports to the public `@plasius/ui-foundry-core` entrypoint.
|
|
17
|
+
|
|
18
|
+
- **Fixed**
|
|
19
|
+
- (placeholder)
|
|
20
|
+
|
|
21
|
+
- **Security**
|
|
22
|
+
- (placeholder)
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Release process (maintainers)
|
|
27
|
+
|
|
28
|
+
1. Update `CHANGELOG.md` under **Unreleased** with user-visible changes.
|
|
29
|
+
2. Bump version in `package.json` following SemVer (major/minor/patch).
|
|
30
|
+
3. Move entries from **Unreleased** to a new version section with the current date.
|
|
31
|
+
4. Tag the release in Git (`vX.Y.Z`) and push tags.
|
|
32
|
+
5. Publish to npm (via CI/CD or `npm publish`).
|
|
33
|
+
|
|
34
|
+
> Tip: Use Conventional Commits in PR titles/bodies to make changelog updates easier.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
[Unreleased]: https://github.com/Plasius-LTD/ui-foundry/compare/main...HEAD
|
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# @plasius/ui-foundry-analytics-appinsights
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@plasius/ui-foundry-analytics-appinsights)
|
|
4
|
+
[](https://github.com/Plasius-LTD/ui-foundry/actions)
|
|
5
|
+
[](https://codecov.io/gh/Plasius-LTD/ui-foundry)
|
|
6
|
+
[](../../LICENSE.md)
|
|
7
|
+
[](./CODE_OF_CONDUCT.md)
|
|
8
|
+
[](./SECURITY.md)
|
|
9
|
+
[](./CHANGELOG.md)
|
|
10
|
+
|
|
11
|
+
> Lightweight adapter to connect **Azure Application Insights** with the `ui-foundry` analytics API.
|
|
12
|
+
|
|
13
|
+
Apache-2.0. ESM + CJS builds. TypeScript types included.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## ✨ What is this?
|
|
18
|
+
|
|
19
|
+
This package provides a **tiny adapter** between:
|
|
20
|
+
|
|
21
|
+
- The `AnalyticsAdapter` interface from [`@plasius/ui-foundry-core`](../ui-foundry-core)
|
|
22
|
+
- An **Application Insights client** from [`@microsoft/applicationinsights-web`](https://www.npmjs.com/package/@microsoft/applicationinsights-web)
|
|
23
|
+
|
|
24
|
+
The adapter lets you use `useAnalytics()` and `AnalyticsProvider` in your app without hard-coding the SDK.
|
|
25
|
+
|
|
26
|
+
**⚠️ Note:** This package does **not** install or configure Application Insights for you.
|
|
27
|
+
The consuming application owns the SDK lifecycle (init, config, consent).
|
|
28
|
+
This keeps `ui-foundry` bundles **lightweight and dependency-free**.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 📦 Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# core + this adapter
|
|
36
|
+
npm install @plasius/ui-foundry-core @plasius/ui-foundry-analytics-appinsights
|
|
37
|
+
|
|
38
|
+
# plus Application Insights in your app
|
|
39
|
+
npm install @microsoft/applicationinsights-web
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 🚀 Usage
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
import React from "react";
|
|
48
|
+
import ReactDOM from "react-dom/client";
|
|
49
|
+
import { ApplicationInsights } from "@microsoft/applicationinsights-web";
|
|
50
|
+
import { AnalyticsProvider } from "@plasius/ui-foundry-core/analytics/context";
|
|
51
|
+
import { createAppInsightsAdapter } from "@plasius/ui-foundry-analytics-appinsights";
|
|
52
|
+
import { App } from "./App";
|
|
53
|
+
|
|
54
|
+
// 1. Create and configure the App Insights client
|
|
55
|
+
const appInsights = new ApplicationInsights({
|
|
56
|
+
config: {
|
|
57
|
+
connectionString: import.meta.env.VITE_APPINSIGHTS_CONNECTION_STRING,
|
|
58
|
+
enableAutoRouteTracking: true,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
appInsights.loadAppInsights();
|
|
62
|
+
|
|
63
|
+
// 2. Create the adapter
|
|
64
|
+
const adapter = createAppInsightsAdapter(appInsights);
|
|
65
|
+
|
|
66
|
+
// 3. Provide it at the root
|
|
67
|
+
ReactDOM.createRoot(document.getElementById("root")!).render(
|
|
68
|
+
<AnalyticsProvider adapter={adapter}>
|
|
69
|
+
<App />
|
|
70
|
+
</AnalyticsProvider>
|
|
71
|
+
);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Tracking in a component:**
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
import { useAnalytics } from "@plasius/ui-foundry-core/analytics/context";
|
|
78
|
+
|
|
79
|
+
export function CheckoutButton() {
|
|
80
|
+
const { track } = useAnalytics();
|
|
81
|
+
return (
|
|
82
|
+
<button
|
|
83
|
+
onClick={() =>
|
|
84
|
+
track({ name: "checkout_clicked", props: { source: "header" } })
|
|
85
|
+
}
|
|
86
|
+
>
|
|
87
|
+
Checkout
|
|
88
|
+
</button>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## 🧪 Testing
|
|
96
|
+
|
|
97
|
+
This package ships with **Vitest tests** using a fake App Insights client.
|
|
98
|
+
You don’t need the real SDK to test integrations.
|
|
99
|
+
|
|
100
|
+
Run them locally with:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
npm test -w @plasius/ui-foundry-analytics-appinsights
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Example from the test suite:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
const fake = {
|
|
110
|
+
trackEvent: vi.fn(),
|
|
111
|
+
setAuthenticatedUserContext: vi.fn(),
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const adapter = createAppInsightsAdapter(fake);
|
|
115
|
+
|
|
116
|
+
adapter.track({ name: "demo", props: { a: 1 } });
|
|
117
|
+
expect(fake.trackEvent).toHaveBeenCalledWith({ name: "demo" }, { a: 1 });
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## ⚡️ Why this package?
|
|
123
|
+
|
|
124
|
+
- **Lightweight**: no runtime dependencies.
|
|
125
|
+
- **Flexible**: app controls when/how App Insights loads.
|
|
126
|
+
- **Testable**: adapter can be unit-tested with a fake client.
|
|
127
|
+
- **Consistent API**: works with `AnalyticsProvider` + `useAnalytics` from `@plasius/ui-foundry-core`.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 📜 License
|
|
132
|
+
|
|
133
|
+
APACHE 2.0 © [Plasius LTD](https://github.com/Plasius-LTD)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
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.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createAppInsightsAdapter: () => createAppInsightsAdapter
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/createAppInsightsAdapter.ts
|
|
28
|
+
function createAppInsightsAdapter(client) {
|
|
29
|
+
return {
|
|
30
|
+
track: ({ name, props }) => {
|
|
31
|
+
client.trackEvent({ name }, props);
|
|
32
|
+
},
|
|
33
|
+
page: (name, props) => {
|
|
34
|
+
if (typeof client.trackPageView === "function") {
|
|
35
|
+
client.trackPageView({ name, ...props ?? {} });
|
|
36
|
+
} else {
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
identify: (userId, traits) => {
|
|
40
|
+
if (typeof client.setAuthenticatedUserContext === "function") {
|
|
41
|
+
client.setAuthenticatedUserContext(
|
|
42
|
+
userId,
|
|
43
|
+
void 0,
|
|
44
|
+
/*storeInCookie*/
|
|
45
|
+
true
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
if (traits && Object.keys(traits).length > 0) {
|
|
49
|
+
client.trackEvent({ name: "$identify" }, traits);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
group: (groupId, traits) => {
|
|
53
|
+
if (typeof client.setAuthenticatedUserContext === "function") {
|
|
54
|
+
client.setAuthenticatedUserContext(
|
|
55
|
+
/*userId*/
|
|
56
|
+
"",
|
|
57
|
+
/*accountId*/
|
|
58
|
+
groupId,
|
|
59
|
+
/*storeInCookie*/
|
|
60
|
+
true
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
if (traits && Object.keys(traits).length > 0) {
|
|
64
|
+
client.trackEvent({ name: "$group" }, { groupId, ...traits });
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
flush: () => client.flush?.()
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
createAppInsightsAdapter
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/createAppInsightsAdapter.ts"],"sourcesContent":["export { createAppInsightsAdapter } from \"./createAppInsightsAdapter.js\";\nexport type {\n AppInsightsClient,\n AppInsightsEvent,\n} from \"./client.js\";\n","import type {\n AnalyticsAdapter,\n AnalyticsEvent,\n} from \"@plasius/ui-foundry-core\";\nimport type { AppInsightsClient } from \"./client.js\";\n\n/**\n * Creates an AnalyticsAdapter backed by an existing Application Insights client.\n * The app is responsible for creating/configuring the client and calling loadAppInsights().\n */\nexport function createAppInsightsAdapter(\n client: AppInsightsClient\n): AnalyticsAdapter {\n return {\n track: ({ name, props }: AnalyticsEvent) => {\n // App Insights requires an event object with name + optional properties\n client.trackEvent({ name }, props);\n },\n\n page: (name?: string, props?: Record<string, unknown>) => {\n if (typeof client.trackPageView === \"function\") {\n client.trackPageView({ name, ...(props ?? {}) });\n } else {\n // no-op if not available\n }\n },\n\n identify: (userId: string, traits?: Record<string, unknown>) => {\n // App Insights supports an authenticated user id and optional \"account\"\n // We’ll store extra traits by sending a special event, leaving the core identity as the userId.\n if (typeof client.setAuthenticatedUserContext === \"function\") {\n client.setAuthenticatedUserContext(\n userId,\n undefined,\n /*storeInCookie*/ true\n );\n }\n if (traits && Object.keys(traits).length > 0) {\n client.trackEvent({ name: \"$identify\" }, traits);\n }\n },\n\n group: (groupId: string, traits?: Record<string, unknown>) => {\n // App Insights doesn't have \"group\" first-class; we model via authenticated account (2nd arg)\n if (typeof client.setAuthenticatedUserContext === \"function\") {\n // Preserve user id if already set; since we can’t read it, we just set account id\n client.setAuthenticatedUserContext(\n /*userId*/ \"\",\n /*accountId*/ groupId,\n /*storeInCookie*/ true\n );\n }\n if (traits && Object.keys(traits).length > 0) {\n client.trackEvent({ name: \"$group\" }, { groupId, ...traits });\n }\n },\n\n flush: () => client.flush?.(),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUO,SAAS,yBACd,QACkB;AAClB,SAAO;AAAA,IACL,OAAO,CAAC,EAAE,MAAM,MAAM,MAAsB;AAE1C,aAAO,WAAW,EAAE,KAAK,GAAG,KAAK;AAAA,IACnC;AAAA,IAEA,MAAM,CAAC,MAAe,UAAoC;AACxD,UAAI,OAAO,OAAO,kBAAkB,YAAY;AAC9C,eAAO,cAAc,EAAE,MAAM,GAAI,SAAS,CAAC,EAAG,CAAC;AAAA,MACjD,OAAO;AAAA,MAEP;AAAA,IACF;AAAA,IAEA,UAAU,CAAC,QAAgB,WAAqC;AAG9D,UAAI,OAAO,OAAO,gCAAgC,YAAY;AAC5D,eAAO;AAAA,UACL;AAAA,UACA;AAAA;AAAA,UACkB;AAAA,QACpB;AAAA,MACF;AACA,UAAI,UAAU,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG;AAC5C,eAAO,WAAW,EAAE,MAAM,YAAY,GAAG,MAAM;AAAA,MACjD;AAAA,IACF;AAAA,IAEA,OAAO,CAAC,SAAiB,WAAqC;AAE5D,UAAI,OAAO,OAAO,gCAAgC,YAAY;AAE5D,eAAO;AAAA;AAAA,UACM;AAAA;AAAA,UACG;AAAA;AAAA,UACI;AAAA,QACpB;AAAA,MACF;AACA,UAAI,UAAU,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG;AAC5C,eAAO,WAAW,EAAE,MAAM,SAAS,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC;AAAA,MAC9D;AAAA,IACF;AAAA,IAEA,OAAO,MAAM,OAAO,QAAQ;AAAA,EAC9B;AACF;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AnalyticsAdapter } from '@plasius/ui-foundry-core';
|
|
2
|
+
|
|
3
|
+
interface AppInsightsEvent {
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
interface AppInsightsClient {
|
|
7
|
+
trackEvent: (event: AppInsightsEvent, props?: Record<string, unknown>) => void;
|
|
8
|
+
trackPageView?: (pageView?: {
|
|
9
|
+
name?: string;
|
|
10
|
+
} & Record<string, unknown>) => void;
|
|
11
|
+
setAuthenticatedUserContext?: (userId: string, accountId?: string | null, storeInCookie?: boolean) => void;
|
|
12
|
+
clearAuthenticatedUserContext?: () => void;
|
|
13
|
+
flush?: () => void | Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates an AnalyticsAdapter backed by an existing Application Insights client.
|
|
18
|
+
* The app is responsible for creating/configuring the client and calling loadAppInsights().
|
|
19
|
+
*/
|
|
20
|
+
declare function createAppInsightsAdapter(client: AppInsightsClient): AnalyticsAdapter;
|
|
21
|
+
|
|
22
|
+
export { type AppInsightsClient, type AppInsightsEvent, createAppInsightsAdapter };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AnalyticsAdapter } from '@plasius/ui-foundry-core';
|
|
2
|
+
|
|
3
|
+
interface AppInsightsEvent {
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
interface AppInsightsClient {
|
|
7
|
+
trackEvent: (event: AppInsightsEvent, props?: Record<string, unknown>) => void;
|
|
8
|
+
trackPageView?: (pageView?: {
|
|
9
|
+
name?: string;
|
|
10
|
+
} & Record<string, unknown>) => void;
|
|
11
|
+
setAuthenticatedUserContext?: (userId: string, accountId?: string | null, storeInCookie?: boolean) => void;
|
|
12
|
+
clearAuthenticatedUserContext?: () => void;
|
|
13
|
+
flush?: () => void | Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates an AnalyticsAdapter backed by an existing Application Insights client.
|
|
18
|
+
* The app is responsible for creating/configuring the client and calling loadAppInsights().
|
|
19
|
+
*/
|
|
20
|
+
declare function createAppInsightsAdapter(client: AppInsightsClient): AnalyticsAdapter;
|
|
21
|
+
|
|
22
|
+
export { type AppInsightsClient, type AppInsightsEvent, createAppInsightsAdapter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/createAppInsightsAdapter.ts
|
|
2
|
+
function createAppInsightsAdapter(client) {
|
|
3
|
+
return {
|
|
4
|
+
track: ({ name, props }) => {
|
|
5
|
+
client.trackEvent({ name }, props);
|
|
6
|
+
},
|
|
7
|
+
page: (name, props) => {
|
|
8
|
+
if (typeof client.trackPageView === "function") {
|
|
9
|
+
client.trackPageView({ name, ...props ?? {} });
|
|
10
|
+
} else {
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
identify: (userId, traits) => {
|
|
14
|
+
if (typeof client.setAuthenticatedUserContext === "function") {
|
|
15
|
+
client.setAuthenticatedUserContext(
|
|
16
|
+
userId,
|
|
17
|
+
void 0,
|
|
18
|
+
/*storeInCookie*/
|
|
19
|
+
true
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
if (traits && Object.keys(traits).length > 0) {
|
|
23
|
+
client.trackEvent({ name: "$identify" }, traits);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
group: (groupId, traits) => {
|
|
27
|
+
if (typeof client.setAuthenticatedUserContext === "function") {
|
|
28
|
+
client.setAuthenticatedUserContext(
|
|
29
|
+
/*userId*/
|
|
30
|
+
"",
|
|
31
|
+
/*accountId*/
|
|
32
|
+
groupId,
|
|
33
|
+
/*storeInCookie*/
|
|
34
|
+
true
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
if (traits && Object.keys(traits).length > 0) {
|
|
38
|
+
client.trackEvent({ name: "$group" }, { groupId, ...traits });
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
flush: () => client.flush?.()
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
createAppInsightsAdapter
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/createAppInsightsAdapter.ts"],"sourcesContent":["import type {\n AnalyticsAdapter,\n AnalyticsEvent,\n} from \"@plasius/ui-foundry-core\";\nimport type { AppInsightsClient } from \"./client.js\";\n\n/**\n * Creates an AnalyticsAdapter backed by an existing Application Insights client.\n * The app is responsible for creating/configuring the client and calling loadAppInsights().\n */\nexport function createAppInsightsAdapter(\n client: AppInsightsClient\n): AnalyticsAdapter {\n return {\n track: ({ name, props }: AnalyticsEvent) => {\n // App Insights requires an event object with name + optional properties\n client.trackEvent({ name }, props);\n },\n\n page: (name?: string, props?: Record<string, unknown>) => {\n if (typeof client.trackPageView === \"function\") {\n client.trackPageView({ name, ...(props ?? {}) });\n } else {\n // no-op if not available\n }\n },\n\n identify: (userId: string, traits?: Record<string, unknown>) => {\n // App Insights supports an authenticated user id and optional \"account\"\n // We’ll store extra traits by sending a special event, leaving the core identity as the userId.\n if (typeof client.setAuthenticatedUserContext === \"function\") {\n client.setAuthenticatedUserContext(\n userId,\n undefined,\n /*storeInCookie*/ true\n );\n }\n if (traits && Object.keys(traits).length > 0) {\n client.trackEvent({ name: \"$identify\" }, traits);\n }\n },\n\n group: (groupId: string, traits?: Record<string, unknown>) => {\n // App Insights doesn't have \"group\" first-class; we model via authenticated account (2nd arg)\n if (typeof client.setAuthenticatedUserContext === \"function\") {\n // Preserve user id if already set; since we can’t read it, we just set account id\n client.setAuthenticatedUserContext(\n /*userId*/ \"\",\n /*accountId*/ groupId,\n /*storeInCookie*/ true\n );\n }\n if (traits && Object.keys(traits).length > 0) {\n client.trackEvent({ name: \"$group\" }, { groupId, ...traits });\n }\n },\n\n flush: () => client.flush?.(),\n };\n}\n"],"mappings":";AAUO,SAAS,yBACd,QACkB;AAClB,SAAO;AAAA,IACL,OAAO,CAAC,EAAE,MAAM,MAAM,MAAsB;AAE1C,aAAO,WAAW,EAAE,KAAK,GAAG,KAAK;AAAA,IACnC;AAAA,IAEA,MAAM,CAAC,MAAe,UAAoC;AACxD,UAAI,OAAO,OAAO,kBAAkB,YAAY;AAC9C,eAAO,cAAc,EAAE,MAAM,GAAI,SAAS,CAAC,EAAG,CAAC;AAAA,MACjD,OAAO;AAAA,MAEP;AAAA,IACF;AAAA,IAEA,UAAU,CAAC,QAAgB,WAAqC;AAG9D,UAAI,OAAO,OAAO,gCAAgC,YAAY;AAC5D,eAAO;AAAA,UACL;AAAA,UACA;AAAA;AAAA,UACkB;AAAA,QACpB;AAAA,MACF;AACA,UAAI,UAAU,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG;AAC5C,eAAO,WAAW,EAAE,MAAM,YAAY,GAAG,MAAM;AAAA,MACjD;AAAA,IACF;AAAA,IAEA,OAAO,CAAC,SAAiB,WAAqC;AAE5D,UAAI,OAAO,OAAO,gCAAgC,YAAY;AAE5D,eAAO;AAAA;AAAA,UACM;AAAA;AAAA,UACG;AAAA;AAAA,UACI;AAAA,QACpB;AAAA,MACF;AACA,UAAI,UAAU,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG;AAC5C,eAAO,WAAW,EAAE,MAAM,SAAS,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC;AAAA,MAC9D;AAAA,IACF;AAAA,IAEA,OAAO,MAAM,OAAO,QAAQ;AAAA,EAC9B;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@plasius/ui-foundry-analytics-appinsights",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"homepage": "https://github.com/Plasius-LTD/ui-foundry#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/Plasius-LTD/ui-foundry/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Plasius-LTD/ui-foundry.git",
|
|
12
|
+
"directory": "packages/integrations/analytics-appinsights"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"main": "./dist/index.cjs",
|
|
22
|
+
"module": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"CHANGELOG.md"
|
|
28
|
+
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=22"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@plasius/ui-foundry-core": "^0.1.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@plasius/ui-foundry-core": "^0.1.0",
|
|
37
|
+
"typescript": "^5.6",
|
|
38
|
+
"tsup": "^8",
|
|
39
|
+
"vitest": "^4.0.18"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup src/index.ts --dts --format cjs,esm --clean",
|
|
43
|
+
"test": "vitest run --config vitest.config.ts",
|
|
44
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
45
|
+
"pack:check": "node scripts/verify-public-package.cjs",
|
|
46
|
+
"prepublishOnly": "npm run build && npm run pack:check"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
}
|
|
51
|
+
}
|