@backstage-community/plugin-analytics-module-newrelic-browser 0.9.0 → 0.11.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 CHANGED
@@ -1,5 +1,33 @@
1
1
  # @backstage-community/plugin-analytics-module-newrelic-browser
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2258b1a: Backstage version bump to v1.43.2
8
+
9
+ ### Patch Changes
10
+
11
+ - 58c21b3: Added support for Backstage's New Frontend System.
12
+
13
+ If you're migrating to the new frontend system, you no longer need to wire up an API implementation in `apis.ts`. Instead, pass the module in to the `createApp()` function:
14
+
15
+ ```tsx
16
+ import newRelicBrowserModule from '@backstage-community/plugin-analytics-module-newrelic-browser/alpha';
17
+
18
+ const app = createApp({
19
+ features: [newRelicBrowserModule],
20
+ });
21
+ ```
22
+
23
+ This can be skipped if you have feature discovery enabled.
24
+
25
+ ## 0.10.0
26
+
27
+ ### Minor Changes
28
+
29
+ - 7eb926b: Adding a sessionReplay config block to the plugin options, allowing users to enable/disable session replay and set options like sampling rate, error sampling rate, masking selectors, and block selectors.
30
+
3
31
  ## 0.9.0
4
32
 
5
33
  ### Minor Changes
package/README.md CHANGED
@@ -15,6 +15,21 @@ yarn --cwd packages/app add @backstage-community/plugin-analytics-module-newreli
15
15
 
16
16
  2. Wire up the API implementation to your App:
17
17
 
18
+ If your App is built using the New Frontend System, it's enough to supply this
19
+ module to `createApp()`:
20
+
21
+ ```tsx
22
+ import newRelicBrowserModule from '@backstage-community/plugin-analytics-module-newrelic-browser/alpha';
23
+
24
+ const app = createApp({
25
+ features: [newRelicBrowserModule],
26
+ });
27
+ ```
28
+
29
+ This can be skipped entirely if you have feature discovery enabled.
30
+
31
+ For all other Backstage apps, wire up the API implementation like this:
32
+
18
33
  ```tsx
19
34
  // packages/app/src/apis.ts
20
35
  import {
@@ -68,8 +83,58 @@ app:
68
83
  ...
69
84
  distributedTracing: true
70
85
  cookiesEnabled: true
86
+ sessionReplay:
87
+ enabled: true
88
+ samplingRate: 90
89
+ errorSamplingRate: 90
90
+ # Optional:
91
+ # maskTextSelector: 'input[type="password"]'
92
+ # maskAllInputs: true
93
+ # blockSelector: '.private'
94
+ ```
95
+
96
+ See [`config.d.ts`](./config.d.ts) for all available options.
97
+
98
+ ## Session Replay
99
+
100
+ Session Replay can be enabled via the `sessionReplay` config block. This allows you to record and replay user sessions for debugging and UX analysis.
101
+
102
+ ### Troubleshooting: Manual Session Replay
103
+
104
+ If you notice that sessions are **not being recorded automatically**, you can force a manual session replay start by injecting the following React component into your app:
105
+
106
+ ```typescript
107
+ import { useEffect } from 'react';
108
+
109
+ const UseStartReplay = () => {
110
+ useEffect(() => {
111
+ const interval = setInterval(() => {
112
+ if ((window?.newrelic as any)?.recordReplay) {
113
+ (window.newrelic as any).recordReplay();
114
+ clearInterval(interval);
115
+ }
116
+ }, 100);
117
+ return () => clearInterval(interval);
118
+ }, []);
119
+ return null;
120
+ };
71
121
  ```
72
122
 
123
+ Then, add it to your app’s router:
124
+
125
+ ```tsx
126
+ <AppRouter>
127
+ <UseStartReplay />
128
+ <Root>{routes}</Root>
129
+ </AppRouter>
130
+ ```
131
+
132
+ This will ensure session recording starts as soon as the New Relic agent is ready.
133
+
134
+ ---
135
+
136
+ For more details, see the [New Relic Browser documentation](https://docs.newrelic.com/docs/browser/).
137
+
73
138
  ### User IDs
74
139
 
75
140
  This plugin supports sending user context to New Relic Browser by providing a User ID. This requires instantiating the `NewRelicBrowser` instance with an `identityApi` instance passed to it, but this is optional. If omitted the plugin will not send user context to New Relic Browser.
package/config.d.ts CHANGED
@@ -53,6 +53,41 @@ export interface Config {
53
53
  * @visibility frontend
54
54
  */
55
55
  cookiesEnabled: boolean;
56
+
57
+ /**
58
+ * Session Replay configuration
59
+ * @deepVisibility frontend
60
+ */
61
+ sessionReplay?: {
62
+ /**
63
+ * Whether to enable Session Replay, defaults to false
64
+ */
65
+ enabled: boolean;
66
+ /**
67
+ * Sampling rate for session replay, defaults to 0
68
+ */
69
+ samplingRate?: number;
70
+ /**
71
+ * Error sampling rate for session replay, defaults to 100
72
+ */
73
+ errorSamplingRate?: number;
74
+ /**
75
+ * Whether to mask all inputs, defaults to false
76
+ */
77
+ maskTextSelector?: string;
78
+ /**
79
+ * Whether to mask all inputs, defaults to true
80
+ */
81
+ maskAllInputs?: boolean;
82
+ /**
83
+ * Whether to collect fonts, defaults to true
84
+ */
85
+ collectFonts?: boolean;
86
+ /**
87
+ * Block selector for session replay, defaults to true
88
+ */
89
+ blockSelector?: string;
90
+ };
56
91
  };
57
92
  };
58
93
  };
@@ -0,0 +1,8 @@
1
+ import * as _backstage_frontend_plugin_api from '@backstage/frontend-plugin-api';
2
+
3
+ /**
4
+ * @public
5
+ */
6
+ declare const newRelicBrowserModule: _backstage_frontend_plugin_api.FrontendModule;
7
+
8
+ export { newRelicBrowserModule as default };
@@ -0,0 +1,2 @@
1
+ export { newRelicBrowserModule as default } from './module.esm.js';
2
+ //# sourceMappingURL=alpha.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alpha.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -13,6 +13,36 @@ class NewRelicBrowser {
13
13
  },
14
14
  ajax: {
15
15
  deny_list: [options.endpoint]
16
+ },
17
+ session_replay: {
18
+ enabled: options.sessionReplay?.enabled || false,
19
+ block_selector: options.sessionReplay?.blockSelector || "",
20
+ mask_text_selector: options.sessionReplay?.maskTextSelector || "",
21
+ sampling_rate: options.sessionReplay?.samplingRate || 0,
22
+ error_sampling_rate: options.sessionReplay?.errorSamplingRate || 0,
23
+ mask_all_inputs: options.sessionReplay?.maskAllInputs || false,
24
+ collect_fonts: true,
25
+ inline_images: false,
26
+ inline_stylesheet: true,
27
+ fix_stylesheets: true,
28
+ preload: true,
29
+ mask_input_options: {
30
+ color: true,
31
+ date: true,
32
+ datetime_local: true,
33
+ email: true,
34
+ month: true,
35
+ number: true,
36
+ range: true,
37
+ search: true,
38
+ tel: true,
39
+ text: true,
40
+ time: true,
41
+ url: true,
42
+ week: true,
43
+ select: true,
44
+ textarea: true
45
+ }
16
46
  }
17
47
  },
18
48
  info: {
@@ -53,7 +83,11 @@ class NewRelicBrowser {
53
83
  applicationId: newRelicBrowserConfig.getString("applicationId"),
54
84
  licenseKey: newRelicBrowserConfig.getString("licenseKey"),
55
85
  distributedTracingEnabled: newRelicBrowserConfig.getOptionalBoolean("distributedTracingEnabled") ?? false,
56
- cookiesEnabled: newRelicBrowserConfig.getOptionalBoolean("cookiesEnabled") ?? false
86
+ cookiesEnabled: newRelicBrowserConfig.getOptionalBoolean("cookiesEnabled") ?? false,
87
+ sessionReplay: {
88
+ ...newRelicBrowserConfig.getOptionalConfig("sessionReplay")?.get()
89
+ }
90
+ // Ensure we get the session replay config as plain object
57
91
  };
58
92
  return new NewRelicBrowser(
59
93
  browserOptions,
@@ -1 +1 @@
1
- {"version":3,"file":"NewRelicBrowser.esm.js","sources":["../../../../src/apis/implementations/AnalyticsApi/NewRelicBrowser.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Config } from '@backstage/config';\nimport {\n AnalyticsApi,\n IdentityApi,\n AnalyticsEvent,\n} from '@backstage/core-plugin-api';\nimport {\n AnalyticsApi as NewAnalyicsApi,\n AnalyticsEvent as NewAnalyticsEvent,\n} from '@backstage/frontend-plugin-api';\nimport { BrowserAgent } from '@newrelic/browser-agent/loaders/browser-agent';\nimport type { setAPI } from '@newrelic/browser-agent/loaders/api/api';\n\ntype NewRelicAPI = ReturnType<typeof setAPI>;\n\ntype NewRelicBrowserOptions = {\n endpoint: string;\n accountId: string;\n applicationId: string;\n licenseKey: string;\n distributedTracingEnabled: boolean;\n cookiesEnabled: boolean;\n};\n\n/**\n * New Relic Browser API provider for the Backstage Analytics API.\n * @public\n */\nexport class NewRelicBrowser implements AnalyticsApi, NewAnalyicsApi {\n private readonly agent: NewRelicAPI;\n\n private constructor(\n options: NewRelicBrowserOptions,\n identityApi?: IdentityApi,\n userIdTransform?: 'sha-256' | ((userEntityRef: string) => Promise<string>),\n ) {\n // Configure the New Relic Browser agent\n const agentOptions = {\n init: {\n distributed_tracing: {\n enabled: options.distributedTracingEnabled,\n },\n privacy: {\n cookies_enabled: options.cookiesEnabled,\n },\n ajax: {\n deny_list: [options.endpoint],\n },\n },\n info: {\n beacon: options.endpoint,\n errorBeacon: options.endpoint,\n licenseKey: options.licenseKey,\n applicationID: options.applicationId,\n sa: 1,\n },\n loader_config: {\n accountID: options.accountId,\n trustKey: options.accountId,\n agentID: options.applicationId,\n licenseKey: options.licenseKey,\n applicationID: options.applicationId,\n },\n };\n\n // Initialize the agent\n this.agent = new BrowserAgent(agentOptions) as unknown as NewRelicAPI;\n\n // Check if identity has been provided\n if (identityApi) {\n identityApi.getBackstageIdentity().then(identity => {\n if (typeof userIdTransform === 'function') {\n userIdTransform(identity.userEntityRef).then(userId => {\n this.agent.setUserId(userId);\n });\n } else {\n this.hash(identity.userEntityRef).then(userId => {\n this.agent.setUserId(userId);\n });\n }\n });\n }\n }\n\n static fromConfig(\n config: Config,\n options: {\n identityApi?: IdentityApi;\n userIdTransform?:\n | 'sha-256'\n | ((userEntityRef: string) => Promise<string>);\n },\n ) {\n const newRelicBrowserConfig = config.getConfig('app.analytics.newRelic');\n const browserOptions: NewRelicBrowserOptions = {\n endpoint: newRelicBrowserConfig.getString('endpoint'),\n accountId: newRelicBrowserConfig.getString('accountId'),\n applicationId: newRelicBrowserConfig.getString('applicationId'),\n licenseKey: newRelicBrowserConfig.getString('licenseKey'),\n distributedTracingEnabled:\n newRelicBrowserConfig.getOptionalBoolean('distributedTracingEnabled') ??\n false,\n cookiesEnabled:\n newRelicBrowserConfig.getOptionalBoolean('cookiesEnabled') ?? false,\n };\n return new NewRelicBrowser(\n browserOptions,\n options.identityApi,\n options.userIdTransform,\n );\n }\n\n captureEvent(event: AnalyticsEvent | NewAnalyticsEvent) {\n const { context, action, subject, value, attributes } = event;\n\n const extensionId = context.extensionId || context.extension;\n const category = extensionId ? String(extensionId) : 'App';\n\n // The legacy default extension was 'App' and the new one is 'app'\n if (\n action === 'navigate' &&\n category.toLocaleLowerCase('en-US').startsWith('app')\n ) {\n const interaction = this.agent.interaction();\n interaction.setName(subject);\n if (value) {\n interaction.setAttribute('value', value);\n }\n Object.keys(context).forEach(key => {\n if (context[key]) {\n interaction.setAttribute(`context.${key}`, context[key]);\n }\n });\n if (attributes) {\n Object.keys(attributes).forEach(key => {\n interaction.setAttribute(`attributes.${key}`, attributes[key]);\n });\n }\n } else {\n const customAttributes: {\n [x: string]: string | number | boolean | undefined;\n } = {};\n if (value) {\n customAttributes.value = value;\n }\n Object.keys(context).forEach(key => {\n if (context[key]) {\n customAttributes[`context.${key}`] = context[key];\n }\n });\n if (attributes) {\n Object.keys(attributes).forEach(key => {\n customAttributes[`attributes.${key}`] = attributes[key];\n });\n }\n\n this.agent.addPageAction(action, customAttributes);\n }\n }\n\n /**\n * Simple hash function; relies on web cryptography + the sha-256 algorithm.\n * @param value - value to be hashed\n */\n private async hash(value: string): Promise<string> {\n const digest = await window.crypto.subtle.digest(\n 'sha-256',\n new TextEncoder().encode(value),\n );\n const hashArray = Array.from(new Uint8Array(digest));\n return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');\n }\n}\n"],"names":[],"mappings":";;AA2CO,MAAM,eAAwD,CAAA;AAAA,EAClD,KAAA;AAAA,EAET,WAAA,CACN,OACA,EAAA,WAAA,EACA,eACA,EAAA;AAEA,IAAA,MAAM,YAAe,GAAA;AA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A,EAAQ,gBAAgB,CAAA;AAAA;AACnD;AACF;AAAA;AAAA;AAAA;AAAA,EAMA,MAAc,KAAK,KAAgC,EAAA;AACjD,IAAA,MAAM,MAAS,GAAA,MAAM,MAAO,CAAA,MAAA,CAAO,MAAO,CAAA,MAAA;AAAA,MACxC,SAAA;AAAA,MACA,IAAI,WAAA,EAAc,CAAA,MAAA,CAAO,KAAK;AAAA,KAChC;AACA,IAAA,MAAM,YAAY,KAAM,CAAA,IAAA,CAAK,IAAI,UAAA,CAAW,MAAM,CAAC,CAAA;AACnD,IAAA,OAAO,SAAU,CAAA,GAAA,CAAI,CAAK,CAAA,KAAA,CAAA,CAAE,QAAS,CAAA,EAAE,CAAE,CAAA,QAAA,CAAS,CAAG,EAAA,GAAG,CAAC,CAAA,CAAE,KAAK,EAAE,CAAA;AAAA;AAEtE;;;;"}
1
+ {"version":3,"file":"NewRelicBrowser.esm.js","sources":["../../../../src/apis/implementations/AnalyticsApi/NewRelicBrowser.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Config } from '@backstage/config';\nimport {\n AnalyticsApi,\n IdentityApi,\n AnalyticsEvent,\n} from '@backstage/core-plugin-api';\nimport {\n AnalyticsApi as NewAnalyicsApi,\n AnalyticsEvent as NewAnalyticsEvent,\n} from '@backstage/frontend-plugin-api';\nimport { BrowserAgent } from '@newrelic/browser-agent/loaders/browser-agent';\n\ntype NewRelicBrowserOptions = {\n endpoint: string;\n accountId: string;\n applicationId: string;\n licenseKey: string;\n distributedTracingEnabled: boolean;\n cookiesEnabled: boolean;\n sessionReplay?: {\n enabled?: boolean;\n samplingRate?: number;\n errorSamplingRate?: number;\n maskTextSelector?: string;\n maskAllInputs?: boolean;\n blockSelector?: string;\n };\n};\n\n/**\n * New Relic Browser API provider for the Backstage Analytics API.\n * @public\n */\nexport class NewRelicBrowser implements AnalyticsApi, NewAnalyicsApi {\n private readonly agent: BrowserAgent;\n\n private constructor(\n options: NewRelicBrowserOptions,\n identityApi?: IdentityApi,\n userIdTransform?: 'sha-256' | ((userEntityRef: string) => Promise<string>),\n ) {\n // Configure the New Relic Browser agent\n const agentOptions = {\n init: {\n distributed_tracing: {\n enabled: options.distributedTracingEnabled,\n },\n privacy: {\n cookies_enabled: options.cookiesEnabled,\n },\n ajax: {\n deny_list: [options.endpoint],\n },\n session_replay: {\n enabled: options.sessionReplay?.enabled || false,\n block_selector: options.sessionReplay?.blockSelector || '',\n mask_text_selector: options.sessionReplay?.maskTextSelector || '',\n sampling_rate: options.sessionReplay?.samplingRate || 0,\n error_sampling_rate: options.sessionReplay?.errorSamplingRate || 0,\n mask_all_inputs: options.sessionReplay?.maskAllInputs || false,\n collect_fonts: true,\n inline_images: false,\n inline_stylesheet: true,\n fix_stylesheets: true,\n preload: true,\n mask_input_options: {\n color: true,\n date: true,\n datetime_local: true,\n email: true,\n month: true,\n number: true,\n range: true,\n search: true,\n tel: true,\n text: true,\n time: true,\n url: true,\n week: true,\n select: true,\n textarea: true,\n },\n },\n },\n info: {\n beacon: options.endpoint,\n errorBeacon: options.endpoint,\n licenseKey: options.licenseKey,\n applicationID: options.applicationId,\n sa: 1,\n },\n loader_config: {\n accountID: options.accountId,\n trustKey: options.accountId,\n agentID: options.applicationId,\n licenseKey: options.licenseKey,\n applicationID: options.applicationId,\n },\n };\n\n // Initialize the agent\n this.agent = new BrowserAgent(agentOptions);\n\n // Check if identity has been provided\n if (identityApi) {\n identityApi.getBackstageIdentity().then(identity => {\n if (typeof userIdTransform === 'function') {\n userIdTransform(identity.userEntityRef).then(userId => {\n this.agent.setUserId(userId);\n });\n } else {\n this.hash(identity.userEntityRef).then(userId => {\n this.agent.setUserId(userId);\n });\n }\n });\n }\n }\n\n static fromConfig(\n config: Config,\n options: {\n identityApi?: IdentityApi;\n userIdTransform?:\n | 'sha-256'\n | ((userEntityRef: string) => Promise<string>);\n },\n ) {\n const newRelicBrowserConfig = config.getConfig('app.analytics.newRelic');\n const browserOptions: NewRelicBrowserOptions = {\n endpoint: newRelicBrowserConfig.getString('endpoint'),\n accountId: newRelicBrowserConfig.getString('accountId'),\n applicationId: newRelicBrowserConfig.getString('applicationId'),\n licenseKey: newRelicBrowserConfig.getString('licenseKey'),\n distributedTracingEnabled:\n newRelicBrowserConfig.getOptionalBoolean('distributedTracingEnabled') ??\n false,\n cookiesEnabled:\n newRelicBrowserConfig.getOptionalBoolean('cookiesEnabled') ?? false,\n sessionReplay: {\n ...newRelicBrowserConfig.getOptionalConfig('sessionReplay')?.get(),\n }, // Ensure we get the session replay config as plain object\n };\n return new NewRelicBrowser(\n browserOptions,\n options.identityApi,\n options.userIdTransform,\n );\n }\n\n captureEvent(event: AnalyticsEvent | NewAnalyticsEvent) {\n const { context, action, subject, value, attributes } = event;\n\n const extensionId = context.extensionId || context.extension;\n const category = extensionId ? String(extensionId) : 'App';\n\n // The legacy default extension was 'App' and the new one is 'app'\n if (\n action === 'navigate' &&\n category.toLocaleLowerCase('en-US').startsWith('app')\n ) {\n const interaction = this.agent.interaction();\n interaction.setName(subject);\n if (value) {\n interaction.setAttribute('value', value);\n }\n Object.keys(context).forEach(key => {\n if (context[key]) {\n interaction.setAttribute(`context.${key}`, context[key]);\n }\n });\n if (attributes) {\n Object.keys(attributes).forEach(key => {\n interaction.setAttribute(`attributes.${key}`, attributes[key]);\n });\n }\n } else {\n const customAttributes: {\n [x: string]: string | number | boolean | undefined;\n } = {};\n if (value) {\n customAttributes.value = value;\n }\n Object.keys(context).forEach(key => {\n if (context[key]) {\n customAttributes[`context.${key}`] = context[key];\n }\n });\n if (attributes) {\n Object.keys(attributes).forEach(key => {\n customAttributes[`attributes.${key}`] = attributes[key];\n });\n }\n\n this.agent.addPageAction(action, customAttributes);\n }\n }\n\n /**\n * Simple hash function; relies on web cryptography + the sha-256 algorithm.\n * @param value - value to be hashed\n */\n private async hash(value: string): Promise<string> {\n const digest = await window.crypto.subtle.digest(\n 'sha-256',\n new TextEncoder().encode(value),\n );\n const hashArray = Array.from(new Uint8Array(digest));\n return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');\n }\n}\n"],"names":[],"mappings":";;AAgDO,MAAM,eAAwD,CAAA;AAAA,EAClD,KAAA;AAAA,EAET,WAAA,CACN,OACA,EAAA,WAAA,EACA,eACA,EAAA;AAEA,IAAA,MAAM,YAAe,GAAA;AAAA,MACnB,IAAM,EAAA;AAAA,QACJ,mBAAqB,EAAA;AAAA,UACnB,SAAS,OAAQ,CAAA;AAAA,SACnB;AAAA,QACA,OAAS,EAAA;AAAA,UACP,iBAAiB,OAAQ,CAAA;AAAA,SAC3B;AAAA,QACA,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,CAAC,OAAA,CAAQ,QAAQ;AAAA,SAC9B;AAAA,QACA,cAAgB,EAAA;AAAA,UACd,OAAA,EAAS,OAAQ,CAAA,aAAA,EAAe,OAAW,IAAA,KAAA;AAAA,UAC3C,cAAA,EAAgB,OAAQ,CAAA,aAAA,EAAe,aAAiB,IAAA,EAAA;AAAA,UACxD,kBAAA,EAAoB,OAAQ,CAAA,aAAA,EAAe,gBAAoB,IAAA,EAAA;AAAA,UAC/D,aAAA,EAAe,OAAQ,CAAA,aAAA,EAAe,YAAgB,IAAA,CAAA;AAAA,UACtD,mBAAA,EAAqB,OAAQ,CAAA,aAAA,EAAe,iBAAqB,IAAA,CAAA;AAAA,UACjE,eAAA,EAAiB,OAAQ,CAAA,aAAA,EAAe,aAAiB,IAAA,KAAA;AAAA,UACzD,aAAe,EAAA,IAAA;AAAA,UACf,aAAe,EAAA,KAAA;AAAA,UACf,iBAAmB,EAAA,IAAA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AChB,UAAA,gBAAA,CAAiB,CAAW,QAAA,EAAA,GAAG,CAAE,CAAA,CAAA,GAAI,QAAQ,GAAG,CAAA;AAAA;AAClD,OACD,CAAA;AACD,MAAA,IAAI,UAAY,EAAA;AACd,QAAA,MAAA,CAAO,IAAK,CAAA,UAAU,CAAE,CAAA,OAAA,CAAQ,CAAO,GAAA,KAAA;AACrC,UAAA,gBAAA,CAAiB,CAAc,WAAA,EAAA,GAAG,CAAE,CAAA,CAAA,GAAI,WAAW,GAAG,CAAA;AAAA,SACvD,CAAA;AAAA;AAGH,MAAK,IAAA,CAAA,KAAA,CAAM,aAAc,CAAA,MAAA,EAAQ,gBAAgB,CAAA;AAAA;AACnD;AACF;AAAA;AAAA;AAAA;AAAA,EAMA,MAAc,KAAK,KAAgC,EAAA;AACjD,IAAA,MAAM,MAAS,GAAA,MAAM,MAAO,CAAA,MAAA,CAAO,MAAO,CAAA,MAAA;AAAA,MACxC,SAAA;AAAA,MACA,IAAI,WAAA,EAAc,CAAA,MAAA,CAAO,KAAK;AAAA,KAChC;AACA,IAAA,MAAM,YAAY,KAAM,CAAA,IAAA,CAAK,IAAI,UAAA,CAAW,MAAM,CAAC,CAAA;AACnD,IAAA,OAAO,SAAU,CAAA,GAAA,CAAI,CAAK,CAAA,KAAA,CAAA,CAAE,QAAS,CAAA,EAAE,CAAE,CAAA,QAAA,CAAS,CAAG,EAAA,GAAG,CAAC,CAAA,CAAE,KAAK,EAAE,CAAA;AAAA;AAEtE;;;;"}
@@ -0,0 +1,17 @@
1
+ import { AnalyticsImplementationBlueprint, configApiRef, identityApiRef, createFrontendModule } from '@backstage/frontend-plugin-api';
2
+ import { NewRelicBrowser } from './apis/implementations/AnalyticsApi/NewRelicBrowser.esm.js';
3
+
4
+ const newRelicBrowserImplementation = AnalyticsImplementationBlueprint.make({
5
+ name: "newrelic-browser",
6
+ params: (defineParams) => defineParams({
7
+ deps: { configApi: configApiRef, identityApi: identityApiRef },
8
+ factory: ({ configApi, identityApi }) => NewRelicBrowser.fromConfig(configApi, { identityApi })
9
+ })
10
+ });
11
+ const newRelicBrowserModule = createFrontendModule({
12
+ pluginId: "app",
13
+ extensions: [newRelicBrowserImplementation]
14
+ });
15
+
16
+ export { newRelicBrowserModule };
17
+ //# sourceMappingURL=module.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.esm.js","sources":["../src/module.ts"],"sourcesContent":["/*\n * Copyright 2025 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n AnalyticsImplementationBlueprint,\n configApiRef,\n createFrontendModule,\n identityApiRef,\n} from '@backstage/frontend-plugin-api';\nimport { NewRelicBrowser } from './apis/implementations/AnalyticsApi';\n\nconst newRelicBrowserImplementation = AnalyticsImplementationBlueprint.make({\n name: 'newrelic-browser',\n params: defineParams =>\n defineParams({\n deps: { configApi: configApiRef, identityApi: identityApiRef },\n factory: ({ configApi, identityApi }) =>\n NewRelicBrowser.fromConfig(configApi, { identityApi }),\n }),\n});\n\n/**\n * @public\n */\nexport const newRelicBrowserModule = createFrontendModule({\n pluginId: 'app',\n extensions: [newRelicBrowserImplementation],\n});\n"],"names":[],"mappings":";;;AAuBA,MAAM,6BAAA,GAAgC,iCAAiC,IAAK,CAAA;AAAA,EAC1E,IAAM,EAAA,kBAAA;AAAA,EACN,MAAA,EAAQ,kBACN,YAAa,CAAA;AAAA,IACX,IAAM,EAAA,EAAE,SAAW,EAAA,YAAA,EAAc,aAAa,cAAe,EAAA;AAAA,IAC7D,OAAA,EAAS,CAAC,EAAE,SAAW,EAAA,WAAA,EACrB,KAAA,eAAA,CAAgB,UAAW,CAAA,SAAA,EAAW,EAAE,WAAA,EAAa;AAAA,GACxD;AACL,CAAC,CAAA;AAKM,MAAM,wBAAwB,oBAAqB,CAAA;AAAA,EACxD,QAAU,EAAA,KAAA;AAAA,EACV,UAAA,EAAY,CAAC,6BAA6B;AAC5C,CAAC;;;;"}
package/package.json CHANGED
@@ -1,15 +1,40 @@
1
1
  {
2
2
  "name": "@backstage-community/plugin-analytics-module-newrelic-browser",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "backstage": {
5
5
  "role": "frontend-plugin-module",
6
6
  "pluginId": "app",
7
- "pluginPackage": "@backstage/plugin-app-backend"
7
+ "pluginPackage": "@backstage/plugin-app-backend",
8
+ "features": {
9
+ "./alpha": "@backstage/FrontendModule"
10
+ }
8
11
  },
9
12
  "publishConfig": {
10
- "access": "public",
11
- "main": "dist/index.esm.js",
12
- "types": "dist/index.d.ts"
13
+ "access": "public"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/index.esm.js",
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.esm.js"
20
+ },
21
+ "./alpha": {
22
+ "backstage": "@backstage/FrontendModule",
23
+ "import": "./dist/alpha.esm.js",
24
+ "types": "./dist/alpha.d.ts",
25
+ "default": "./dist/alpha.esm.js"
26
+ },
27
+ "./package.json": "./package.json"
28
+ },
29
+ "typesVersions": {
30
+ "*": {
31
+ "alpha": [
32
+ "dist/alpha.d.ts"
33
+ ],
34
+ "package.json": [
35
+ "package.json"
36
+ ]
37
+ }
13
38
  },
14
39
  "repository": {
15
40
  "type": "git",
@@ -18,8 +43,8 @@
18
43
  },
19
44
  "license": "Apache-2.0",
20
45
  "sideEffects": false,
21
- "main": "dist/index.esm.js",
22
- "types": "dist/index.d.ts",
46
+ "main": "./dist/index.esm.js",
47
+ "types": "./dist/index.d.ts",
23
48
  "files": [
24
49
  "dist",
25
50
  "config.d.ts"
@@ -35,14 +60,14 @@
35
60
  },
36
61
  "dependencies": {
37
62
  "@backstage/config": "^1.3.3",
38
- "@backstage/core-components": "^0.17.5",
39
- "@backstage/core-plugin-api": "^1.10.9",
40
- "@backstage/frontend-plugin-api": "^0.11.0",
41
- "@newrelic/browser-agent": "^1.236.0"
63
+ "@backstage/core-components": "^0.18.1",
64
+ "@backstage/core-plugin-api": "^1.11.0",
65
+ "@backstage/frontend-plugin-api": "^0.12.0",
66
+ "@newrelic/browser-agent": "^1.295.0"
42
67
  },
43
68
  "devDependencies": {
44
- "@backstage/cli": "^0.34.1",
45
- "@backstage/dev-utils": "^1.1.13",
69
+ "@backstage/cli": "^0.34.3",
70
+ "@backstage/dev-utils": "^1.1.14",
46
71
  "@testing-library/jest-dom": "^6.0.0",
47
72
  "@testing-library/react": "^15.0.0",
48
73
  "@types/react": "^18.2.58",
@@ -53,12 +78,5 @@
53
78
  "react": "^16.13.1 || ^17.0.0 || ^18.0.0"
54
79
  },
55
80
  "configSchema": "config.d.ts",
56
- "typesVersions": {
57
- "*": {
58
- "package.json": [
59
- "package.json"
60
- ]
61
- }
62
- },
63
81
  "module": "./dist/index.esm.js"
64
82
  }