From dbfab5b118640c10f40616c7137831fc7190ed0d Mon Sep 17 00:00:00 2001 From: Stuart Taylor Date: Fri, 9 Nov 2018 15:51:50 +0000 Subject: [PATCH] chore: Port over mission statement and gtag (#34262) - [x] I have read [freeCodeCamp's contribution guidelines](https://github.com/freeCodeCamp/freeCodeCamp/blob/master/CONTRIBUTING.md). - [x] My pull request has a descriptive title (not a vague title like `Update index.md`) - [x] My pull request targets the `master` branch of freeCodeCamp. Closes #18184 --- client/src/analytics/gtag.js | 29 +++++++++++++++++++ .../src/components/Header/components/Login.js | 3 ++ client/src/head/index.js | 3 +- client/src/head/scripts.js | 10 +++++++ client/src/pages/index.css | 4 ++- client/src/pages/index.js | 27 ++++++++++++++++- 6 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 client/src/analytics/gtag.js create mode 100644 client/src/head/scripts.js diff --git a/client/src/analytics/gtag.js b/client/src/analytics/gtag.js new file mode 100644 index 0000000000..0d49f3a1e2 --- /dev/null +++ b/client/src/analytics/gtag.js @@ -0,0 +1,29 @@ +const isBrowser = typeof window !== 'undefined'; + +if (isBrowser) { + window.dataLayer = window.dataLayer || []; +} + +function gtag() { + if (isBrowser) { + window.dataLayer.push(arguments); + } +} +gtag('js', new Date()); +gtag('config', 'AW-795617839'); + +export function gtagReportConversion(url) { + var callback = function() { + if (typeof url !== 'undefined' && isBrowser) { + window.location = url; + } + }; + if (isBrowser) { + gtag('event', 'conversion', { + /* eslint-disable camelcase */ + send_to: 'AW-795617839/AmfiCKHHs4gBEK_UsPsC', + event_callback: callback + }); + } + return false; +} diff --git a/client/src/components/Header/components/Login.js b/client/src/components/Header/components/Login.js index 82150a32b3..d7392fc0f7 100644 --- a/client/src/components/Header/components/Login.js +++ b/client/src/components/Header/components/Login.js @@ -6,6 +6,8 @@ import { Button } from '@freecodecamp/react-bootstrap'; import { hardGoTo } from '../../../redux'; import { apiLocation } from '../../../../config/env.json'; +import { gtagReportConversion } from '../../../analytics/gtag'; + import './login.css'; const mapStateToProps = () => ({}); @@ -15,6 +17,7 @@ const mapDispatchToProps = dispatch => ({ const createOnClick = navigate => e => { e.preventDefault(); + gtagReportConversion(); return navigate(`${apiLocation}/signin`); }; diff --git a/client/src/head/index.js b/client/src/head/index.js index 065387a6e4..5f59164e69 100644 --- a/client/src/head/index.js +++ b/client/src/head/index.js @@ -2,9 +2,10 @@ import favicons from './favicons'; import meta from './meta'; import mathjax from './mathjax'; import sassjs from './sassjs'; +import scripts from './scripts'; const metaAndStyleSheets = meta - .concat(favicons, mathjax, sassjs) + .concat(favicons, mathjax, sassjs, scripts) .map((element, i) => ({ ...element, key: `meta-stylesheet-${i}`, diff --git a/client/src/head/scripts.js b/client/src/head/scripts.js new file mode 100644 index 0000000000..dbf3da2f4a --- /dev/null +++ b/client/src/head/scripts.js @@ -0,0 +1,10 @@ +import React from 'react'; + +const scripts = [ +