feat(analytics-module-ga): support self hosted analytics.js
Signed-off-by: Phil Kuang <pkuang@factset.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-analytics-module-ga': patch
|
||||
---
|
||||
|
||||
Support self hosted analytics.js script via `gaAddress` config option
|
||||
+7
@@ -27,6 +27,13 @@ export interface Config {
|
||||
*/
|
||||
trackingId: string;
|
||||
|
||||
/**
|
||||
* URL to Google Analytics analytics.js script
|
||||
* Defaults to https://www.google-analytics.com/analytics.js
|
||||
* @visibility frontend
|
||||
*/
|
||||
gaAddress?: string;
|
||||
|
||||
/**
|
||||
* Whether or not to log analytics debug statements to the console.
|
||||
* Defaults to false.
|
||||
|
||||
+12
-1
@@ -42,18 +42,25 @@ export class GoogleAnalytics implements AnalyticsApi {
|
||||
private constructor({
|
||||
cdmConfig,
|
||||
trackingId,
|
||||
gaAddress,
|
||||
testMode,
|
||||
debug,
|
||||
}: {
|
||||
cdmConfig: CustomDimensionOrMetricConfig[];
|
||||
trackingId: string;
|
||||
gaAddress: string;
|
||||
testMode: boolean;
|
||||
debug: boolean;
|
||||
}) {
|
||||
this.cdmConfig = cdmConfig;
|
||||
|
||||
// Initialize Google Analytics.
|
||||
ReactGA.initialize(trackingId, { testMode, debug, titleCase: false });
|
||||
ReactGA.initialize(trackingId, {
|
||||
gaAddress,
|
||||
testMode,
|
||||
debug,
|
||||
titleCase: false,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,6 +69,9 @@ export class GoogleAnalytics implements AnalyticsApi {
|
||||
static fromConfig(config: Config) {
|
||||
// Get all necessary configuration.
|
||||
const trackingId = config.getString('app.analytics.ga.trackingId');
|
||||
const gaAddress =
|
||||
config.getOptionalString('app.analytics.ga.gaAddress') ??
|
||||
'https://www.google-analytics.com/analytics.js';
|
||||
const debug = config.getOptionalBoolean('app.analytics.ga.debug') ?? false;
|
||||
const testMode =
|
||||
config.getOptionalBoolean('app.analytics.ga.testMode') ?? false;
|
||||
@@ -82,6 +92,7 @@ export class GoogleAnalytics implements AnalyticsApi {
|
||||
// Return an implementation instance.
|
||||
return new GoogleAnalytics({
|
||||
trackingId,
|
||||
gaAddress,
|
||||
cdmConfig,
|
||||
testMode,
|
||||
debug,
|
||||
|
||||
Reference in New Issue
Block a user