Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

move gtm id to env variable, move getipaddress to gtm js util file, update 2021

Ed Platoe99f4a4fa467
diff --git a/config/default/common/features.json b/config/default/common/features.json
index 329e5a8e0..03ba093d7 100644
--- a/config/default/common/features.json
+++ b/config/default/common/features.json
@@ -8,9 +8,7 @@
"tour": true,
"feedback": true,
"previewSnapshots": true,
- "googleTagManager": {
- "id": "GTM-WNP7MLF"
- },
+ "googleTagManager": true,
"notification": {
"url": "https://status.earthdata.nasa.gov/api/v1/notifications",
"releases": "https://github.com/nasa-gibs/worldview/releases"
diff --git a/doc/features.md b/doc/features.md
index 0b85ad24d..ebaf6bf43 100644
--- a/doc/features.md
+++ b/doc/features.md
@@ -48,3 +48,14 @@ This feature uses
```
> Caution: Do not commit this file to a public repo, and make sure the `build/options` directory is not publicly accessible on your web server to protect the privacy of your API key.
+
+## Google Tag Manager
+
+Worldview uses the analytics framework [Google Tag Manager](https://developers.google.com/tag-manager) to collect user interface interaction metrics. To use this feature, obtain a Google Tag Manager ID formatted as "GTM-XXXXXX", and add the ID as environment variable `GTM_ID` that can be accessed during the build process to inject your ID into the necessary code. This feature is turned on by default:
+
+```json
+"googleTagManager": true
+```
+
+to disable this feature, set:
+`"googleTagManager": false`
diff --git a/tasks/dist.js b/tasks/dist.js
index 15b695472..2c867495c 100755
--- a/tasks/dist.js
+++ b/tasks/dist.js
@@ -12,7 +12,7 @@ shell.mkdir('-p', 'build/worldview');
shell.cp('-rf', 'web/*', 'build/worldview');
// Remove preview images, if that feature is disabled, for smaller dist file size
-const { CONFIG_ENV } = process.env;
+const { CONFIG_ENV, GTM_ID } = process.env;
const featuresConfigPath = CONFIG_ENV
? `config/active/${CONFIG_ENV}/features.json`
: 'config/default/common/features.json';
@@ -53,6 +53,10 @@ shell.sed('-i', /@BUILD_NONCE/g, buildNonce, applyTo);
shell.sed('-i', /@BUILD_TIMESTAMP@/g, buildTimestamp, applyTo);
shell.sed('-i', /@BUILD_VERSION@/g, pkg.version, applyTo);
+// replace google tag manager id
+const googleTagManagerID = GTM_ID || '';
+shell.sed('-i', /@GTM_ID@/g, googleTagManagerID, applyTo);
+
const dist = 'dist/worldview.tar.gz';
console.log(`Creating distribution: ${dist}`);
shell.mkdir('-p', 'dist');
diff --git a/web/index.html b/web/index.html
index ee3b35b67..438dde53a 100644
--- a/web/index.html
+++ b/web/index.html
@@ -4,12 +4,11 @@ NASA Worldview (https://github.com/nasa-gibs/worldview)
This code was originally developed at NASA/Goddard Space Flight Center for the Earth Science Data and Information System (ESDIS) project.
-Copyright (C) 2013 - 2019 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All Rights Reserved.
+Copyright (C) 2013 - 2021 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All Rights Reserved.
Licensed under the NASA Open Source Agreement, Version 1.3 (https://opensource.gsfc.nasa.gov/nosa.php)
-->
<html lang="en" prefix="og: https://ogp.me/ns#">
-
<head>
<!-- Google Tag Manager -->
<script async>(function (w, d, s, l, i) {
@@ -19,13 +18,14 @@ Licensed under the NASA Open Source Agreement, Version 1.3 (https://opensource.g
}); var f = d.getElementsByTagName(s)[0],
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src =
'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f);
- })(window, document, 'script', 'dataLayer', 'GTM-WNP7MLF');
+ })(window, document, 'script', 'dataLayer', '@GTM_ID@');
- window.dataLayer = window.dataLayer || [];
+ if ('@GTM_ID@') {
+ window.dataLayer = window.dataLayer || [];
+ }
</script>
<!-- End Google Tag Manager -->
<title>@OFFICIAL_NAME@</title>
- <meta name="google-site-verification" content="cX2U525Pb71Qs92wY4LTYsP_Eu1Y9dMaLgE2XQU9-Pw" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script type="text/javascript">
@@ -66,7 +66,7 @@ Licensed under the NASA Open Source Agreement, Version 1.3 (https://opensource.g
<body>
<!-- Google Tag Manager (noscript) -->
- <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-WNP7MLF" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
+ <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=@GTM_ID@" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<div data-role="page" id="app">
</div>
diff --git a/web/js/app.js b/web/js/app.js
index a10fb7004..5cf8edddd 100644
--- a/web/js/app.js
+++ b/web/js/app.js
@@ -3,7 +3,7 @@ import { connect } from 'react-redux';
import PropTypes from 'prop-types';
// eslint-disable-next-line no-unused-vars
import whatInput from 'what-input';
-// import googleTagManager from 'googleTagManager';
+import googleTagManager from 'googleTagManager';
// Utils
import { calculateResponsiveState } from 'redux-responsive';
@@ -127,29 +127,16 @@ class App extends React.Component {
const { config } = self.props;
config.parameters = state;
- // get user IP address for GTM/GA using https://www.ipify.org/ API
- // const getIpAddress = async() => {
- // const response = await fetch('https://api.ipify.org?format=json');
- // const json = await response.json();
- // const ipAddress = json.ip;
-
- // googleTagManager.pushEvent({
- // event: 'ipAddress',
- // ipAddress,
- // });
- // };
-
const main = function() {
// Load any additional scripts as needed
if (config.scripts) {
util.loadScipts(config.scripts);
}
- // if (config.features.googleTagManager) {
- // googleTagManager.init(config.features.googleTagManager.id); // Insert google tag manager
- // if (!/localhost/.test(window.location.href)) {
- // getIpAddress();
- // }
- // }
+ if (config.features.googleTagManager) {
+ if (!/localhost/.test(window.location.href)) {
+ googleTagManager.getIpAddress();
+ }
+ }
// Console notifications
if (Brand.release()) {
diff --git a/web/js/components/about/about-page.js b/web/js/components/about/about-page.js
index 70fd7cc4e..0e47a7413 100644
--- a/web/js/components/about/about-page.js
+++ b/web/js/components/about/about-page.js
@@ -297,7 +297,7 @@ export default function AboutPage() {
<hr />
<h2>License</h2>
<p>
- Copyright &copy; 2013 - 2020 United States Government as represented by the Administrator of the National Aeronautics and
+ Copyright &copy; 2013 - 2021 United States Government as represented by the Administrator of the National Aeronautics and
Space Administration. All Rights Reserved. This software is licensed under the
{' '}
<a href="https://ti.arc.nasa.gov/opensource/nosa/" target="_blank" rel="noopener noreferrer">NASA Open Source Software Agreement, Version 1.3</a>
diff --git a/web/js/components/util/google-tag-manager.js b/web/js/components/util/google-tag-manager.js
index 4015b1a5b..25106e293 100644
--- a/web/js/components/util/google-tag-manager.js
+++ b/web/js/components/util/google-tag-manager.js
@@ -2,46 +2,36 @@
export default {
/*
- * Initialize GTM tracking if tracking
- * code is present - will add to head in document
- * noscript will not be handled
- *
- * @func init
+ * @func dataLayerPush object to GoogleTagManager
+ * can add custom javascript object that can be retrieved as custom data layer variables
* @static
*
- * @param Category {id} GTM tracking code
+ * @param EventObject {object}
*
* @return {void}
*/
- init(id) {
- if(id) {
- (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
- new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
- j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
- 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
- })(window,document,'script','dataLayer',id);
-
- // create inline SCRIPT tag with dataLayer array and push to HEAD after TITLE tag
- let dataLayerScript = document.createElement('script');
- dataLayerScript.type = 'text/javascript';
- let inlineScript = document.createTextNode('window.dataLayer = window.dataLayer || [];');
- dataLayerScript.appendChild(inlineScript);
- document.head.insertBefore(dataLayerScript, document.head.firstElementChild.nextSibling);
+ pushEvent(eventObject) {
+ if (typeof (dataLayer) !== 'undefined') {
+ window.dataLayer.push(eventObject);
}
},
/*
- * @func dataLayerPush object to GoogleTagManager
- * can add custom javascript object that can be retrieved as custom data layer variables
+ * @func getIpAddress
+ * get user IP address for GTM/GA using https://www.ipify.org/ API
* @static
*
- * @param EventObject {object}
- *
* @return {void}
*/
- pushEvent(eventObject) {
- if (typeof (dataLayer) !== 'undefined') {
- window.dataLayer.push(eventObject);
- }
+ // get user IP address for GTM/GA using https://www.ipify.org/ API
+ async getIpAddress() {
+ const response = await fetch('https://api.ipify.org?format=json');
+ const json = await response.json();
+ const ipAddress = json.ip;
+
+ pushEvent({
+ event: 'ipAddress',
+ ipAddress,
+ });
}
};