diff --git a/plugins/analytics-module-ga/README.md b/plugins/analytics-module-ga/README.md index ac79978676..a7e681bbe5 100644 --- a/plugins/analytics-module-ga/README.md +++ b/plugins/analytics-module-ga/README.md @@ -4,16 +4,28 @@ This plugin provides an opinionated implementation of the Backstage Analytics API for Google Analytics. Once installed and configured, analytics events will be sent to GA as your users navigate and use your Backstage instance. -This plugin contains no (and will never contain any) other functionality. +This plugin contains no other functionality. ## Installation 1. Install this plugin in your Backstage app: `cd packages/app && yarn add @backstage/plugin-analytics-module-ga` -2. Register the plugin with your App. In most instances of Backstage, this is - as simple as adding `export { analyticsModuleGA } from '@backstage/plugin-analytics-module-ga';` - to your `packages/app/src/plugins.ts` file. -3. Configure the plugin (see below). +2. Add the API implementation to your App and configure the plugin (see below). + +```tsx +// packages/app/src/apis.ts +import { analyticsApiRef, configApiRef } from '@backstage/core-plugin-api'; +import { GoogleAnalytics } from '@backstage/plugin-analytics-module-ga'; + +export const apis: AnyApiFactory[] = [ + // Instantiate and register the GA Analytics API Implementation. + createApiFactory({ + api: analyticsApiRef, + deps: { configApi: configApiRef }, + factory: ({ configApi }) => GoogleAnalytics.fromConfig(configApi), + }), +]; +``` ## Configuration diff --git a/plugins/analytics-module-ga/api-report.md b/plugins/analytics-module-ga/api-report.md index 6208ebe795..7ca3b1646f 100644 --- a/plugins/analytics-module-ga/api-report.md +++ b/plugins/analytics-module-ga/api-report.md @@ -3,12 +3,29 @@ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts +import { AnalyticsApi } from '@backstage/core-plugin-api'; +import { AnalyticsEvent } from '@backstage/core-plugin-api'; import { BackstagePlugin } from '@backstage/core-plugin-api'; +import { Config } from '@backstage/config'; // Warning: (ae-missing-release-tag) "analyticsModuleGA" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) export const analyticsModuleGA: BackstagePlugin<{}, {}>; +// Warning: (ae-missing-release-tag) "GoogleAnalytics" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public +export class GoogleAnalytics implements AnalyticsApi { + captureEvent({ + context, + action, + subject, + value, + attributes, + }: AnalyticsEvent): void; + static fromConfig(config: Config): GoogleAnalytics; +} + // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/analytics-module-ga/src/index.ts b/plugins/analytics-module-ga/src/index.ts index d9d3222ac0..17a3213c6d 100644 --- a/plugins/analytics-module-ga/src/index.ts +++ b/plugins/analytics-module-ga/src/index.ts @@ -13,4 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + export { analyticsModuleGA } from './plugin'; +export { GoogleAnalytics } from './apis/implementations/AnalyticsApi'; diff --git a/plugins/analytics-module-ga/src/plugin.ts b/plugins/analytics-module-ga/src/plugin.ts index e339965d91..d63ae6616f 100644 --- a/plugins/analytics-module-ga/src/plugin.ts +++ b/plugins/analytics-module-ga/src/plugin.ts @@ -13,21 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { - analyticsApiRef, - configApiRef, - createApiFactory, - createPlugin, -} from '@backstage/core-plugin-api'; -import { GoogleAnalytics } from './apis/implementations/AnalyticsApi'; +import { createPlugin } from '@backstage/core-plugin-api'; export const analyticsModuleGA = createPlugin({ id: 'analytics-provider-ga', - apis: [ - createApiFactory({ - api: analyticsApiRef, - deps: { config: configApiRef }, - factory: ({ config }) => GoogleAnalytics.fromConfig(config), - }), - ], });