Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion plugins/analytics-module-segment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,25 @@ This plugin requires an active workspace with [Segment][segment]. Please referen
yarn --cwd packages/app add @segment/backstage-plugin-analytics-module-segment
```

### Wire up the API implementation to your App:
### New frontend system

Add the module to your app's frontend features:

```ts
// packages/app/src/App.tsx
import segmentAnalyticsModule from '@segment/backstage-plugin-analytics-module-segment/alpha';

const app = createApp({
features: [segmentAnalyticsModule],
});
```

The module uses the configured Backstage identity when identifying users in
Segment.

### Legacy frontend system

Wire up the API implementation to your app:

```ts
// packages/app/src/apis.ts
Expand Down
20 changes: 18 additions & 2 deletions plugins/analytics-module-segment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,25 @@
"main": "dist/index.esm.js",
"types": "dist/index.d.ts"
},
"exports": {
".": "./src/index.ts",
"./alpha": "./src/alpha.ts",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"alpha": [
"src/alpha.ts"
],
"package.json": [
"package.json"
]
}
},
"backstage": {
"role": "frontend-plugin-module",
"pluginId": "app",
"pluginPackage": "@backstage/plugin-app-backend"
"pluginPackage": "@backstage/plugin-app"
},
"repository": {
"type": "git",
Expand All @@ -32,6 +47,8 @@
"postpack": "backstage-cli package postpack"
},
"dependencies": {
"@backstage/frontend-plugin-api": "^0.17.3",
"@backstage/plugin-app-react": "^0.2.6",
"@segment/analytics-next": "^1.72.1"
},
"peerDependencies": {
Expand All @@ -44,7 +61,6 @@
"@backstage/core-components": "^0.18.12",
"@backstage/core-plugin-api": "^1.12.8",
"@backstage/dev-utils": "^1.1.25",
"@backstage/frontend-plugin-api": "^0.17.3",
"react": "^16.13.1 || ^17.0.0 || ^18.0.0"
},
"files": [
Expand Down
1 change: 1 addition & 0 deletions plugins/analytics-module-segment/src/alpha.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { segmentAnalyticsModule as default } from './module';
12 changes: 12 additions & 0 deletions plugins/analytics-module-segment/src/module.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import segmentModule from './alpha';
import { segmentAnalyticsModule } from './module';

describe('segmentAnalyticsModule', () => {
it('provides an app frontend module through the alpha entry point', () => {
expect(segmentModule).toBe(segmentAnalyticsModule);
expect(segmentAnalyticsModule).toMatchObject({
$$type: '@backstage/FrontendModule',
pluginId: 'app',
});
});
});
24 changes: 24 additions & 0 deletions plugins/analytics-module-segment/src/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
configApiRef,
createFrontendModule,
identityApiRef,
} from '@backstage/frontend-plugin-api';
import { AnalyticsImplementationBlueprint } from '@backstage/plugin-app-react';

import { SegmentAnalytics } from './apis';

const segmentAnalyticsImplementation = AnalyticsImplementationBlueprint.make({
name: 'segment',
params: defineParams =>
defineParams({
deps: { configApi: configApiRef, identityApi: identityApiRef },
factory: ({ configApi, identityApi }) =>
SegmentAnalytics.fromConfig(configApi, { identityApi }),
}),
});

/** @public */
export const segmentAnalyticsModule = createFrontendModule({
pluginId: 'app',
extensions: [segmentAnalyticsImplementation],
});