Skip to content

Commit

Permalink
Merge pull request #291 from AuScope/contextbeforega
Browse files Browse the repository at this point in the history
Contextbeforega
  • Loading branch information
jia020 authored Jul 11, 2023
2 parents d1962be + 2414eac commit 5a51da3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 28 additions & 23 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));


0 comments on commit 5a51da3

Please sign in to comment.