Add Google Analytics
Specity a Google Analytics Tracking ID in the `app-config.yaml` to enable Google Analytics tracking. ``` app: title: baseUrl: googleAnalyticsTrackingId: UA-000000-0 ``` If the `googleAnalyticsTrackingId` is not supplied, no tracking script is added to the application and no tracking can occur. Includes Helm chart changes to allow overriding the GA Tracking ID.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
app:
|
||||
title: Backstage Example App
|
||||
baseUrl: http://localhost:7000
|
||||
googleAnalyticsTrackingId: # UA-000000-0
|
||||
|
||||
backend:
|
||||
baseUrl: http://localhost:7000
|
||||
|
||||
@@ -13,6 +13,7 @@ metadata:
|
||||
data:
|
||||
APP_CONFIG_app_baseUrl: {{ .Values.appConfig.app.baseUrl | quote | quote }}
|
||||
APP_CONFIG_app_title: {{ .Values.appConfig.app.title | quote | quote }}
|
||||
APP_CONFIG_app_googleAnalyticsTrackingId: {{ .Values.appConfig.app.googleAnalyticsTrackingId | quote | quote }}
|
||||
APP_CONFIG_backend_baseUrl: {{ .Values.appConfig.backend.baseUrl | quote | quote }}
|
||||
APP_CONFIG_backend_cors_origin: {{ .Values.appConfig.backend.cors.origin | quote | quote }}
|
||||
APP_CONFIG_techdocs_storageUrl: {{ .Values.appConfig.techdocs.storageUrl | quote | quote }}
|
||||
|
||||
@@ -86,6 +86,7 @@ appConfig:
|
||||
app:
|
||||
baseUrl: https://demo.example.com
|
||||
title: Backstage
|
||||
googleAnalyticsTrackingId:
|
||||
backend:
|
||||
baseUrl: https://demo.example.com
|
||||
listen:
|
||||
|
||||
@@ -48,6 +48,23 @@
|
||||
}
|
||||
</style>
|
||||
<title><%= app.title %></title>
|
||||
|
||||
<% if (app.googleAnalyticsTrackingId && typeof app.googleAnalyticsTrackingId
|
||||
=== 'string') { %>
|
||||
<script
|
||||
async
|
||||
src="https://www.googletagmanager.com/gtag/js?id=<%= app.googleAnalyticsTrackingId %>"
|
||||
></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag() {
|
||||
dataLayer.push(arguments);
|
||||
}
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', '<%= app.googleAnalyticsTrackingId %>');
|
||||
</script>
|
||||
<% } %>
|
||||
</head>
|
||||
<body style="margin: 0;">
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
|
||||
@@ -111,6 +111,9 @@ export async function createConfig(
|
||||
app: {
|
||||
title: options.config.getString('app.title'),
|
||||
baseUrl: validBaseUrl.href,
|
||||
googleAnalyticsTrackingId: options.config.getOptionalString(
|
||||
'app.googleAnalyticsTrackingId',
|
||||
),
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user