diff --git a/.github/workflows/azure-static-web-apps-thankful-flower-08081a31e.yml b/.github/workflows/azure-static-web-apps-thankful-flower-08081a31e.yml index 046455a0..f5e1db2b 100644 --- a/.github/workflows/azure-static-web-apps-thankful-flower-08081a31e.yml +++ b/.github/workflows/azure-static-web-apps-thankful-flower-08081a31e.yml @@ -23,7 +23,7 @@ jobs: - uses: jsdaniell/create-json@v1.2.2 with: name: "context.json" - json: '{"portalBaseUrl":"${{ vars.AZURE_PORTAL_API_URL_PROD }}","hostUrl":"${{ vars.AZURE_PORTAL_URL_PROD }}","authBaseUrl":"${{ vars.AZURE_PORTAL_URL_PROD }}/api/"}' + json: '{"portalBaseUrl":"${{ vars.AZURE_PORTAL_API_URL_PROD }}","hostUrl":"${{ vars.AZURE_PORTAL_URL_PROD }}","authBaseUrl":"${{ vars.AZURE_PORTAL_URL_PROD }}/api/", "googleAnalyticsKey": "${{ secrets.PROD_GOOGLE_ANALYTICS_KEY }}" }' dir: 'src/contexts/' - name: Build And Deploy id: builddeploy diff --git a/src/main.ts b/src/main.ts index 864336f0..3c53c763 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,20 +6,33 @@ import { AppModule } from './app/app.module'; import { environment } from './environments/environment'; import { ContextService, ContextConfig, CONTEXT_CONFIG } from "@csiro-geoanalytics/ng"; -if (environment.production) { - enableProdMode(); -} - -if (environment.googleAnalyticsKey) { - const gtagscript = document.createElement('script'); - gtagscript.src = 'https://www.googletagmanager.com/gtag/js?id=' + environment.googleAnalyticsKey; - gtagscript.async = true; - document.head.appendChild(gtagscript); - const gtaginitscript = document.createElement('script'); - gtaginitscript.innerHTML = 'window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag(\'js\', new Date());gtag(\'config\', \'' + - environment.googleAnalyticsKey + '\');'; - document.head.appendChild(gtaginitscript); -} +ContextService.load() + .then(context => { + /* + each property of the context file is copied over to the environment object, replacing any that share the same name. + */ + Object.keys(context).forEach(key => environment[key]=context[key]); + + if (environment.production) { + enableProdMode(); + } + + if (environment.googleAnalyticsKey) { + const gtagscript = document.createElement('script'); + gtagscript.src = 'https://www.googletagmanager.com/gtag/js?id=' + environment.googleAnalyticsKey; + gtagscript.async = true; + document.head.appendChild(gtagscript); + const gtaginitscript = document.createElement('script'); + gtaginitscript.innerHTML = 'window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag(\'js\', new Date());gtag(\'config\', \'' + + environment.googleAnalyticsKey + '\');'; + document.head.appendChild(gtaginitscript); + } + + return platformBrowserDynamic().bootstrapModule(AppModule) + }) + .catch(err => console.error(err)); + + declare var require; @@ -31,13 +44,5 @@ window['CESIUM_BASE_URL'] = '/assets/cesium/'; To run the application under a different execution context provide a path to context configuration file into the ContextService.load() method below. Or just accept the default ./contexts/context.json */ -ContextService.load() - .then(context => { - /* - each property of the context file is copied over to the environment object, replacing any that share the same name. - */ - Object.keys(context).forEach(key => environment[key]=context[key]); - return platformBrowserDynamic().bootstrapModule(AppModule) - }) - .catch(err => console.error(err)); +