Skip to content

Commit 18186fb

Browse files
author
Christopher Willis-Ford
committed
provide empty window.ga(...) when GA_ID is absent
1 parent e91713c commit 18186fb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/lib/analytics.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ if (GA_ID) {
88
sampleRate: (process.env.NODE_ENV === 'production') ? 100 : 0,
99
forceSSL: true
1010
});
11+
} else {
12+
window.ga = () => {
13+
// The `react-ga` module calls this function to implement all Google Analytics calls. Providing an empty
14+
// function effectively disables `react-ga`. This is similar to the `testModeAPI` feature of `react-ga` except
15+
// that `testModeAPI` logs the arguments of every call into an array. That's nice for testing purposes but
16+
// would look like a memory leak in a live program.
17+
};
1118
}
1219

1320
export default GoogleAnalytics;

0 commit comments

Comments
 (0)