From a3162f1d32baf48e562940b4afbfe83a42883652 Mon Sep 17 00:00:00 2001 From: sveinpg Date: Sun, 9 Dec 2018 22:57:14 +0100 Subject: [PATCH] Add GA script for tracking 404s --- website/pages/en/404.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/website/pages/en/404.js b/website/pages/en/404.js index d75d0a99ca..96b01f2c36 100644 --- a/website/pages/en/404.js +++ b/website/pages/en/404.js @@ -1,9 +1,29 @@ const React = require("react"); +const siteConfig = require(`${process.cwd()}/siteConfig.js`); class ErrorPage extends React.Component { + getTrackingScript() { + if (!siteConfig.gaTrackingId) { + return null; + } + + return {__html:` + ga('create', "${siteConfig.gaTrackingId}"); + ga('send', { + hitType: 'event', + eventCategory: '404 Response', + eventAction: window.location.href, + eventLabel: document.referrer + });` + } + } + render() { + const trackingScript = this.getTrackingScript(); + return (
+ {trackingScript &&