Skip to content

Commit

Permalink
Add GA script for tracking 404s
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinpg committed Dec 9, 2018
1 parent 74bf011 commit a3162f1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 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 (
<div className="error-page">
{trackingScript && <script dangerouslySetInnerHTML={trackingScript}/>}
<div className="error-message">
<div className=" error-message-container container">
<span>404 </span>
Expand Down

0 comments on commit a3162f1

Please sign in to comment.