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:
David Tuite
2020-10-16 13:39:15 +01:00
parent 14f9daf942
commit 71de0d8aee
5 changed files with 23 additions and 0 deletions
+17
View File
@@ -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>