Add google analytics scripts in template for standalone app

Signed-off-by: r.bideau <7304827+rbideau@users.noreply.github.com>
This commit is contained in:
r.bideau
2021-02-18 17:13:00 +01:00
parent 1add977bae
commit 4594f7efc2
2 changed files with 45 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
---
'@backstage/create-app': patch
---
Add the google analytics scripts in the `index.html` template for new applications.
To apply this change to an existing application, change the following in `packages\app\public\index.html`:
```diff
<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>
```
@@ -48,6 +48,22 @@
}
</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>