diff --git a/components/helmet/index.js b/components/helmet/index.js
index c4e141bc7..5c9072c9a 100644
--- a/components/helmet/index.js
+++ b/components/helmet/index.js
@@ -1,3 +1,4 @@
+const { PHASE_DEVELOPMENT_SERVER } = require('next/constants');
import NextHead from 'next/head';
import siteConfig from 'storage/site';
import { GA_TRACKING_ID } from 'lib/gtag';
@@ -22,13 +23,13 @@ const Helmet = (props) => (
-
+
-
+
@@ -55,15 +56,19 @@ const Helmet = (props) => (
{ /* Global Site Tag (gtag.js) - Google Analytics */ }
-
-
+ { !PHASE_DEVELOPMENT_SERVER && (
+ <>
+
+
+ >
+ )}
);
diff --git a/lib/gtag.js b/lib/gtag.js
index ee264269f..f05a9dbd6 100644
--- a/lib/gtag.js
+++ b/lib/gtag.js
@@ -2,6 +2,11 @@ export const GA_TRACKING_ID = 'UA-139582634-1';
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
export const firePageView = url => {
+ if (!window.gtag) {
+ console.warn('Missing GTAG – Analytics disabled');
+ return;
+ }
+
window.gtag('config', GA_TRACKING_ID, {
page_path: url,
})
@@ -9,6 +14,11 @@ export const firePageView = url => {
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
export const event = ({ action, category, label, value }) => {
+ if (!window.gtag) {
+ console.warn('Missing GTAG – Analytics disabled');
+ return;
+ }
+
window.gtag('event', action, {
event_category: category,
event_label: label,