Skip to content

Commit

Permalink
feat(components): add app insights to storybook (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicegginton authored Dec 10, 2023
1 parent c49310c commit e8a3c71
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 1 deletion.
172 changes: 171 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@commitlint/config-conventional": "17.6.5",
"@custom-elements-manifest/analyzer": "0.8.3",
"@lit-labs/ssr": "3.1.7",
"@microsoft/applicationinsights-web": "3.0.6",
"@nx-extend/terraform": "^3.2.0",
"@nx/devkit": "16.8.1",
"@nx/esbuild": "16.9.1",
Expand Down
1 change: 1 addition & 0 deletions packages/components/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { StorybookConfig } from '@storybook/web-components-vite';

const STORYBOOK_CONFIGURATION: StorybookConfig = {
core: { disableTelemetry: true },
features: { storyStoreV7: true },
framework: '@storybook/web-components-vite',
stories: [
Expand Down
21 changes: 21 additions & 0 deletions packages/components/.storybook/manager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { addons } from '@storybook/addons';
import { create } from '@storybook/theming';
import Events from '@storybook/core-events';
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
import arcLogo from '../../../assets/arc-storybook.svg';

const THEME = create({
Expand All @@ -19,3 +21,22 @@ addons.setConfig({
theme: THEME,
showPanel: false,
});

addons.register('application-insights', api => {
const APP_INSIGHTS = new ApplicationInsights({
config: {
ingestionEndpoint: 'https://uksouth-0.in.applicationinsights.azure.com',
instrumentationKey: 'c77ad0b6-1dc7-433d-99df-e164c2b2a11f',
enableDebug: process.env.NODE_ENV === 'development',
},
});
APP_INSIGHTS.loadAppInsights();

api.on(Events.SET_CURRENT_STORY, (eventData) => {
const uri = window.location.pathname;
const storyId = eventData.storyId;
const storyName = eventData.viewMode;
console.log('Storybook event:', uri, storyId, storyName);
APP_INSIGHTS.trackPageView({ name: storyName, uri, properties: { storyId, storyName, storyKind }});
});
});

0 comments on commit e8a3c71

Please sign in to comment.