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 = [ +