Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

chore: remove deprecated analytics (#3813)

Igor Dykhta841cbda29485
diff --git a/src/utils/src/export-map-html.ts b/src/utils/src/export-map-html.ts
index 3f1768109..47e737764 100644
--- a/src/utils/src/export-map-html.ts
+++ b/src/utils/src/export-map-html.ts
@@ -246,26 +246,6 @@ export const exportMapToHTML = (options, version = KEPLER_GL_VERSION) => {
window.MAPBOX_TOKEN = '${options.mapboxApiAccessToken || 'PROVIDE_MAPBOX_TOKEN'}';
window.WARNING_MESSAGE = 'No Mapbox token provided. Mapbox basemaps will not be available. To enable them, edit this file and set MAPBOX_TOKEN to your Mapbox access key.';
</script>
-
- <!-- GA: Delete this as you wish, However to pat ourselves on the back, we only track anonymous pageview to understand how many people are using kepler.gl. -->
- <script>
- (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', 'UA-64694404-19', {
- 'storage': 'none',
- 'clientId': (function(){try{return localStorage.getItem('ga:clientId')}catch(e){return null}})()
- });
- ga(function(tracker) {
- try{localStorage.setItem('ga:clientId', tracker.get('clientId'));}catch(e){}
- });
- ga('set', 'checkProtocolTask', null); // Disable file protocol checking.
- ga('set', 'checkStorageTask', null); // Disable cookie storage checking.
- ga('set', 'historyImportTask', null); // Disable history checking (requires reading from cookies).
- ga('set', 'page', 'keplergl-html');
- ga('send', 'pageview');
- </script>
</head>
<body>
<!-- We will put our React component inside this div. -->
diff --git a/test/node/index.js b/test/node/index.js
index 07544a9a1..e646fc4ef 100644
--- a/test/node/index.js
+++ b/test/node/index.js
@@ -15,3 +15,6 @@ import './processors';
// docker runtime config (entrypoint merge script)
import './docker';
+
+// demo site shell
+import './website';
diff --git a/test/node/utils/export-utils-test.js b/test/node/utils/export-utils-test.js
index b9b9f5ca0..72de10361 100644
--- a/test/node/utils/export-utils-test.js
+++ b/test/node/utils/export-utils-test.js
@@ -45,6 +45,11 @@ test('exportUtils -> ExportHtml includes map info', t => {
'exported html should restore the map description'
);
t.ok(html.includes('info,'), 'exported html should pass info to addDataToMap');
+ t.notOk(html.includes('google-analytics.com'), 'exported html should not load Google Analytics');
+ t.notOk(
+ html.includes('UA-64694404'),
+ 'exported html should not contain a Universal Analytics id'
+ );
t.end();
});
diff --git a/test/node/website/demo-site-analytics-test.js b/test/node/website/demo-site-analytics-test.js
new file mode 100644
index 000000000..8aa41fbf7
--- /dev/null
+++ b/test/node/website/demo-site-analytics-test.js
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import fs from 'fs';
+import path from 'path';
+import test from 'tape';
+
+const ROOT = path.resolve(__dirname, '../../..');
+
+const DEMO_SITE_SOURCES = [
+ 'website/src/static/index.html',
+ 'website/src/routes.js',
+ 'website/src/reducers/index.js'
+];
+
+test('demo site does not load Google Analytics', t => {
+ DEMO_SITE_SOURCES.forEach(rel => {
+ const source = fs.readFileSync(path.join(ROOT, rel), 'utf8');
+ t.notOk(source.includes('googletagmanager.com'), `${rel} should not load Google Tag Manager`);
+ t.notOk(source.includes('google-analytics.com'), `${rel} should not load Google Analytics`);
+ t.notOk(source.includes('UA-64694404'), `${rel} should not contain a Universal Analytics id`);
+ t.notOk(/\bgtag\b/.test(source), `${rel} should not call gtag`);
+ });
+
+ t.notOk(
+ fs.existsSync(path.join(ROOT, 'website/src/reducers/analytics.js')),
+ 'demo-site analytics middleware should be removed'
+ );
+
+ t.end();
+});
diff --git a/test/node/website/index.js b/test/node/website/index.js
new file mode 100644
index 000000000..f0f0d9b66
--- /dev/null
+++ b/test/node/website/index.js
@@ -0,0 +1,4 @@
+// SPDX-License-Identifier: MIT
+// Copyright contributors to the kepler.gl project
+
+import './demo-site-analytics-test';
diff --git a/website/src/reducers/analytics.js b/website/src/reducers/analytics.js
deleted file mode 100644
index 21b1d09a9..000000000
--- a/website/src/reducers/analytics.js
+++ /dev/null
@@ -1,101 +0,0 @@
-// SPDX-License-Identifier: MIT
-// Copyright contributors to the kepler.gl project
-
-// This file sends actions on the demo app to Google analytics
-
-import {ActionTypes} from '@kepler.gl/actions';
-import Window from 'global/window';
-import {ALL_FIELD_TYPES} from '@kepler.gl/constants';
-import get from 'es-toolkit/compat/get';
-
-const getPayload = action => (action ? action.payload : null);
-
-// Hack, because we don't have a way to access next state
-const getFilterType = (store, idx, value) => {
- const {visState} = store.getState().demo.keplerGl.map;
- const filter = visState.filters[idx];
- const {dataId} = filter;
- if (!dataId) {
- return {};
- }
- const {fields} = visState.datasets[dataId];
- const field = fields.find(f => f.name === value);
-
- // Hack
- switch (field.type) {
- case ALL_FIELD_TYPES.real:
- case ALL_FIELD_TYPES.integer:
- return 'range';
-
- case ALL_FIELD_TYPES.boolean:
- return 'select';
-
- case ALL_FIELD_TYPES.string:
- case ALL_FIELD_TYPES.date:
- return 'multiSelect';
-
- case ALL_FIELD_TYPES.timestamp:
- return 'timeRange';
-
- default:
- return null;
- }
-};
-
-const trackingInformation = {
- [ActionTypes.LOAD_FILES]: payload => payload.files.map(({size, type}) => ({size, type})),
- [ActionTypes.LAYER_TYPE_CHANGE]: ({newType}) => ({
- newType
- }),
- [ActionTypes.MAP_STYLE_CHANGE]: getPayload,
- [ActionTypes.TOGGLE_MODAL]: getPayload,
- [ActionTypes.ADD_LAYER]: (payload, store) => ({
- total: store.getState().demo.keplerGl.map.visState.layers.length + 1
- }),
- [ActionTypes.ADD_FILTER]: (payload, store) => ({
- total: store.getState().demo.keplerGl.map.visState.filters.length + 1
- }),
- [ActionTypes.SET_FILTER]: ({prop, idx, value}, store) => {
- if (prop !== 'name') {
- return {};
- }
- return {
- filterType: getFilterType(store, idx, value)
- };
- },
- [ActionTypes.INTERACTION_CONFIG_CHANGE]: ({config: {id, enabled}}) => ({
- [id]: enabled
- }),
-
- // demo app actions
- ['PUSHING_FILE']: payload => {
- const size = get(payload, ['metadata', 'metadata', 'size']);
- return {
- isLoading: payload.isLoading,
- status: payload.metadata.status,
- filename: payload.metadata.filename,
- size,
- error: payload.error
- };
- }
-};
-
-const EXCLUDED_ACTIONS = [ActionTypes.LAYER_HOVER, ActionTypes.UPDATE_MAP];
-
-const analyticsMiddleware = store => next => action => {
- if (Window.gtag && !EXCLUDED_ACTIONS.includes(action.type)) {
- const payload = action.payload || action;
-
- // eslint-disable-next-line no-undef
- Window.gtag('event', 'action', {
- event_category: action.type,
- event_label: trackingInformation[action.type]
- ? JSON.stringify(trackingInformation[action.type](payload, store))
- : null
- });
- }
-
- return next(action);
-};
-
-export default analyticsMiddleware;
diff --git a/website/src/reducers/index.js b/website/src/reducers/index.js
index 80b3918be..6ea8bd27f 100644
--- a/website/src/reducers/index.js
+++ b/website/src/reducers/index.js
@@ -7,7 +7,6 @@ import thunk from 'redux-thunk';
import appReducer from './app';
import demoReducer from '../../../examples/demo-app/src/reducers';
-import analyticsMiddleware from './analytics';
const initialState = {};
const reducers = {
@@ -17,7 +16,7 @@ const reducers = {
const combinedReducers = combineReducers(reducers);
-export const middlewares = [taskMiddleware, thunk, analyticsMiddleware];
+export const middlewares = [taskMiddleware, thunk];
export const enhancers = [applyMiddleware(...middlewares)];
diff --git a/website/src/routes.js b/website/src/routes.js
index 32ce31644..05203b593 100644
--- a/website/src/routes.js
+++ b/website/src/routes.js
@@ -3,24 +3,11 @@
import React, {useEffect} from 'react';
import {BrowserRouter, Routes, Route, useLocation, useNavigate} from 'react-router-dom';
-import Window from 'global/window';
import Home from './components/home';
import App from './components/app';
import Demo from '../../examples/demo-app/src/app';
import Policy from './components/policy';
-const trackPageChange = location => {
- const links = location.split('/');
-
- if (links.length === 3) {
- const sampleId = links[2];
- Window.gtag('event', 'load_sample', {
- event_label: sampleId,
- value: sampleId
- });
- }
-};
-
/**
* Handles legacy hash URLs (e.g. /#/demo/earthquakes) by redirecting
* to the equivalent path-based URL (/demo/earthquakes).
@@ -38,30 +25,10 @@ function LegacyHashRedirect() {
return null;
}
-/**
- * Tracks page views via Google Analytics on route changes.
- * Replaces the old react-router-redux LOCATION_CHANGE action tracking.
- */
-function LocationTracker() {
- const location = useLocation();
-
- useEffect(() => {
- if (Window.gtag) {
- Window.gtag('event', 'page_view', {
- page_path: location.pathname
- });
- }
- trackPageChange(location.pathname);
- }, [location.pathname]);
-
- return null;
-}
-
// eslint-disable-next-line react/display-name
export default () => (
<BrowserRouter>
<LegacyHashRedirect />
- <LocationTracker />
<Routes>
<Route path="/" element={<App />}>
<Route index element={<Home />} />
diff --git a/website/src/static/index.html b/website/src/static/index.html
index c22801c67..9dd9797d8 100644
--- a/website/src/static/index.html
+++ b/website/src/static/index.html
@@ -30,18 +30,6 @@
<meta name="twitter:description" content="Kepler.gl is a powerful web-based geospatial data analysis tool. Built on a high performance rendering engine and designed for large-scale data sets.">
<meta name="twitter:image" content="https://d1a3f4spazzrp4.cloudfront.net/kepler.gl/kepler.gl-meta-tag.png" />
- <!-- Google Analytics -->
- <!-- Global site tag (gtag.js) - Google Analytics -->
- <script async src="https://www.googletagmanager.com/gtag/js?id=UA-64694404-19"></script>
- <script>
- window.dataLayer = window.dataLayer || [];
- function gtag(){dataLayer.push(arguments);}
- gtag('js', new Date());
- gtag('config', 'UA-64694404-19', {
- page_path: location.pathname + location.search + location.hash
- });
- </script>
-
<style>
html {margin: 0; padding: 0; width: 100%; min-height: 100%; overflow-x: hidden;}
body, #root {margin: 0; padding: 0; width: 100%; min-height: 100%;}