mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
50479: Google analytics only loaded when tracking id present
This commit is contained in:
@@ -25,14 +25,25 @@ export function main() {
|
||||
}
|
||||
});
|
||||
|
||||
// Add google analytics key
|
||||
const script = document.createElement('script');
|
||||
script.innerHTML = 'ga(\'create\', \'' + ENV_CONFIG.gaTrackingId + '\', \'auto\');';
|
||||
document.body.appendChild(script);
|
||||
addGoogleAnalytics();
|
||||
|
||||
return platformBrowserDynamic().bootstrapModule(BrowserAppModule);
|
||||
}
|
||||
|
||||
function addGoogleAnalytics() {
|
||||
// Add google analytics if key is present in config
|
||||
const trackingId = ENV_CONFIG.gaTrackingId;
|
||||
if (trackingId !== '' && trackingId !== null) {
|
||||
const keyScript = document.createElement('script');
|
||||
keyScript.innerHTML = `(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');`
|
||||
+ 'ga(\'create\', \'' + ENV_CONFIG.gaTrackingId + '\', \'auto\');';
|
||||
document.body.appendChild(keyScript);
|
||||
}
|
||||
}
|
||||
|
||||
// support async tag or hmr
|
||||
if (hasValue(ENV_CONFIG.universal) && ENV_CONFIG.universal.preboot === false) {
|
||||
bootloader(main);
|
||||
|
Reference in New Issue
Block a user