Skip to content

Commit 5f9270b

Browse files
feat(analytics-module-segment): adopt new frontend system (#35)
Signed-off-by: Alec Jacobs <charles.jacobs@segment.com>
1 parent 93d3191 commit 5f9270b

5 files changed

Lines changed: 74 additions & 3 deletions

File tree

plugins/analytics-module-segment/README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,25 @@ This plugin requires an active workspace with [Segment][segment]. Please referen
1717
yarn --cwd packages/app add @segment/backstage-plugin-analytics-module-segment
1818
```
1919

20-
### Wire up the API implementation to your App:
20+
### New frontend system
21+
22+
Add the module to your app's frontend features:
23+
24+
```ts
25+
// packages/app/src/App.tsx
26+
import segmentAnalyticsModule from '@segment/backstage-plugin-analytics-module-segment/alpha';
27+
28+
const app = createApp({
29+
features: [segmentAnalyticsModule],
30+
});
31+
```
32+
33+
The module uses the configured Backstage identity when identifying users in
34+
Segment.
35+
36+
### Legacy frontend system
37+
38+
Wire up the API implementation to your app:
2139

2240
```ts
2341
// packages/app/src/apis.ts

plugins/analytics-module-segment/package.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,25 @@
1111
"main": "dist/index.esm.js",
1212
"types": "dist/index.d.ts"
1313
},
14+
"exports": {
15+
".": "./src/index.ts",
16+
"./alpha": "./src/alpha.ts",
17+
"./package.json": "./package.json"
18+
},
19+
"typesVersions": {
20+
"*": {
21+
"alpha": [
22+
"src/alpha.ts"
23+
],
24+
"package.json": [
25+
"package.json"
26+
]
27+
}
28+
},
1429
"backstage": {
1530
"role": "frontend-plugin-module",
1631
"pluginId": "app",
17-
"pluginPackage": "@backstage/plugin-app-backend"
32+
"pluginPackage": "@backstage/plugin-app"
1833
},
1934
"repository": {
2035
"type": "git",
@@ -32,6 +47,8 @@
3247
"postpack": "backstage-cli package postpack"
3348
},
3449
"dependencies": {
50+
"@backstage/frontend-plugin-api": "^0.17.3",
51+
"@backstage/plugin-app-react": "^0.2.6",
3552
"@segment/analytics-next": "^1.72.1"
3653
},
3754
"peerDependencies": {
@@ -44,7 +61,6 @@
4461
"@backstage/core-components": "^0.18.12",
4562
"@backstage/core-plugin-api": "^1.12.8",
4663
"@backstage/dev-utils": "^1.1.25",
47-
"@backstage/frontend-plugin-api": "^0.17.3",
4864
"react": "^16.13.1 || ^17.0.0 || ^18.0.0"
4965
},
5066
"files": [
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { segmentAnalyticsModule as default } from './module';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import segmentModule from './alpha';
2+
import { segmentAnalyticsModule } from './module';
3+
4+
describe('segmentAnalyticsModule', () => {
5+
it('provides an app frontend module through the alpha entry point', () => {
6+
expect(segmentModule).toBe(segmentAnalyticsModule);
7+
expect(segmentAnalyticsModule).toMatchObject({
8+
$$type: '@backstage/FrontendModule',
9+
pluginId: 'app',
10+
});
11+
});
12+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
configApiRef,
3+
createFrontendModule,
4+
identityApiRef,
5+
} from '@backstage/frontend-plugin-api';
6+
import { AnalyticsImplementationBlueprint } from '@backstage/plugin-app-react';
7+
8+
import { SegmentAnalytics } from './apis';
9+
10+
const segmentAnalyticsImplementation = AnalyticsImplementationBlueprint.make({
11+
name: 'segment',
12+
params: defineParams =>
13+
defineParams({
14+
deps: { configApi: configApiRef, identityApi: identityApiRef },
15+
factory: ({ configApi, identityApi }) =>
16+
SegmentAnalytics.fromConfig(configApi, { identityApi }),
17+
}),
18+
});
19+
20+
/** @public */
21+
export const segmentAnalyticsModule = createFrontendModule({
22+
pluginId: 'app',
23+
extensions: [segmentAnalyticsImplementation],
24+
});

0 commit comments

Comments
 (0)