Skip to content

Commit 1db6729

Browse files
authored
Add app insights (#23303)
## Description This PR adds user telemetry to the website through the integration of AppInsights Changes include: - Added AppInsights config - Set essential cookie with uuid to track usage analytics
1 parent 69a755e commit 1db6729

File tree

8 files changed

+286
-5
lines changed

8 files changed

+286
-5
lines changed

docs/.env.template

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
# Flag that determines whether or not repo-local API documentation should be generated and included in the site build.
66
# Only used in local development.
77
LOCAL_API_DOCS=<boolean>
8+
9+
# Key used to authenticate with the Azure Application Insights API. Refer to README.md for more information.
10+
INSTRUMENTATION_KEY=<instrumentation_key>

docs/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,32 @@ To include repo-local API documentation when building the site locally, you will
8686
So long as the `LOCAL_API_DOCS` environment variable is set to `true`, local API documentation will be included when building the site.
8787
To remove the local API docs, simply remove the above variable or set it to `false`, `npm run clean` and rebuild as needed.
8888
89+
## User Telemetry
90+
91+
The Fluid Framework website collects basic user telemetry to help improve the experience for our users.
92+
The telemetry data includes anonymous information such as:
93+
94+
- Daily / Monthly users
95+
- Pages visited
96+
- User flow
97+
98+
This data is collected in compliance with relevant privacy standards.
99+
For more information, please refer to our [privacy policy.](https://www.microsoft.com/privacy/privacystatement).
100+
If you have any concerns about telemetry, please reach out to our team via [GitHub Issues](https://github.com/microsoft/FluidFramework/issues).
101+
102+
To test this telemetry locally add the following key to the .env file.
103+
This key is used to instantiate Application Insights so that usage events can be tracked.
104+
The key can be requested from internal Microsoft Fluid Framework engineers.
105+
106+
```
107+
INSTRUMENTATION_KEY=<key>
108+
```
109+
110+
## Deployment
111+
112+
The Fluid Framework website is deployed using the build-docs pipeline. `INSTRUMENTATION_KEY`
113+
is set as a pipeline variable here.
114+
89115
## Writing site documentation
90116
91117
For details about authoring documentation content in Docusaurus, see [here](https://docusaurus.io/docs/create-doc).

docs/docusaurus.config.ts

+5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
* Licensed under the MIT License.
44
*/
55

6+
import dotenv from "dotenv";
67
import type { VersionOptions } from "@docusaurus/plugin-content-docs";
78
import * as Preset from "@docusaurus/preset-classic";
89
import type { Config } from "@docusaurus/types";
910
import { themes as prismThemes } from "prism-react-renderer";
1011

1112
import DocsVersions from "./config/docs-versions.mjs";
1213

14+
dotenv.config();
1315
const includeLocalApiDocs = process.env.LOCAL_API_DOCS === "true";
1416

1517
const githubUrl = "https://github.com/microsoft/FluidFramework";
@@ -165,6 +167,9 @@ const config: Config = {
165167
},
166168
],
167169
],
170+
customFields: {
171+
INSTRUMENTATION_KEY: process.env.INSTRUMENTATION_KEY,
172+
},
168173
};
169174

170175
export default config;

docs/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
"@fluid-tools/markdown-magic": "file:../tools/markdown-magic",
7575
"@fluidframework/build-common": "^2.0.3",
7676
"@fluidframework/eslint-config-fluid": "^5.5.1",
77+
"@microsoft/applicationinsights-react-js": "^17.3.4",
78+
"@microsoft/applicationinsights-web": "^3.3.4",
7779
"@playwright/test": "^1.49.0",
7880
"@rushstack/node-core-library": "^5.9.0",
7981
"@types/node": "^22.9.1",
@@ -83,6 +85,7 @@
8385
"cross-env": "^7.0.3",
8486
"dill-cli": "^0.1.3",
8587
"docusaurus-plugin-sass": "^0.2.5",
88+
"dotenv": "^16.4.7",
8689
"dotenv-cli": "^7.4.3",
8790
"eslint": "~8.55.0",
8891
"eslint-config-prettier": "~9.1.0",
@@ -99,7 +102,8 @@
99102
"rimraf": "^5.0.10",
100103
"simple-git": "^3.27.0",
101104
"start-server-and-test": "^2.0.8",
102-
"typescript": "~5.5.4"
105+
"typescript": "~5.5.4",
106+
"uuid": "^11.0.3"
103107
},
104108
"packageManager": "[email protected]+sha512.d1a029e1a447ad90bc96cd58b0fad486d2993d531856396f7babf2d83eb1823bb83c5a3d0fc18f675b2d10321d49eb161fece36fe8134aa5823ecd215feed392",
105109
"engines": {

docs/pnpm-lock.yaml

+171-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/src/appInsights.ts

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*!
2+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
// eslint-disable-next-line import/no-unresolved
7+
import siteConfig from "@generated/docusaurus.config";
8+
import { ReactPlugin } from "@microsoft/applicationinsights-react-js";
9+
import { ApplicationInsights } from "@microsoft/applicationinsights-web";
10+
11+
const reactPlugin = new ReactPlugin();
12+
let appInsights: ApplicationInsights | undefined;
13+
14+
if (siteConfig?.customFields?.INSTRUMENTATION_KEY === undefined) {
15+
console.warn("Instrumentation Key is missing. App Insights will not be initialized.");
16+
}
17+
18+
// Only initialize Application Insights if not in local development.
19+
// Remove the condition if you want to run Application Insights locally.
20+
if (typeof window !== "undefined" && window.location.hostname !== "localhost") {
21+
appInsights = new ApplicationInsights({
22+
config: {
23+
connectionString: `InstrumentationKey=${siteConfig?.customFields?.INSTRUMENTATION_KEY}`,
24+
enableAutoRouteTracking: true,
25+
enableDebug: true,
26+
extensions: [reactPlugin],
27+
},
28+
});
29+
appInsights.loadAppInsights();
30+
}
31+
32+
export default appInsights;

0 commit comments

Comments
 (0)