From 18186fb4c15f541b7d3334b9ddc5ff6b9339bdc6 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford <cwillisf@media.mit.edu> Date: Tue, 28 Jan 2020 13:28:21 -0800 Subject: [PATCH] provide empty window.ga(...) when GA_ID is absent --- src/lib/analytics.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib/analytics.js b/src/lib/analytics.js index 7a233ff32..cd08719dd 100644 --- a/src/lib/analytics.js +++ b/src/lib/analytics.js @@ -8,6 +8,13 @@ if (GA_ID) { sampleRate: (process.env.NODE_ENV === 'production') ? 100 : 0, forceSSL: true }); +} else { + window.ga = () => { + // The `react-ga` module calls this function to implement all Google Analytics calls. Providing an empty + // function effectively disables `react-ga`. This is similar to the `testModeAPI` feature of `react-ga` except + // that `testModeAPI` logs the arguments of every call into an array. That's nice for testing purposes but + // would look like a memory leak in a live program. + }; } export default GoogleAnalytics; -- GitLab