From c286c40a84c55cfd640944b8794d426e090df828 Mon Sep 17 00:00:00 2001 From: Patrick Hooper Date: Wed, 27 Sep 2017 18:33:22 -0400 Subject: [PATCH] Add Google Analytics to static build --- public/googleTagManager.js | 3 +++ public/index.jsx | 5 +++++ src/app/Root.jsx | 5 ++++- src/dev.jsx | 3 +-- src/static.jsx | 17 ++++++++++++++++- 5 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 public/googleTagManager.js diff --git a/public/googleTagManager.js b/public/googleTagManager.js new file mode 100644 index 00000000..9e7a5e4f --- /dev/null +++ b/public/googleTagManager.js @@ -0,0 +1,3 @@ +export const gtmScript = "(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-NT29XCN');"; + +export const gtmNoscript = ''; diff --git a/public/index.jsx b/public/index.jsx index eca1d092..b1f2d9e4 100644 --- a/public/index.jsx +++ b/public/index.jsx @@ -1,12 +1,17 @@ import React from 'react'; import ReactDOMServer from 'react-dom/server'; +import { gtmScript } from './googleTagManager'; + export default function renderHtml(data, body) { return ` ${ReactDOMServer.renderToStaticMarkup( + {(process.env.NODE_ENV === 'production') && +