diff --git a/src/AddressSearch.js b/src/AddressSearch.js index 0f97691ba862753ff3e16375bb3c41d4f5e3d96e..608cc7d35b0a83087d20f488965729fcc6ca3497 100644 --- a/src/AddressSearch.js +++ b/src/AddressSearch.js @@ -4,6 +4,7 @@ import './index.css'; import Geocoder from 'react-mapbox-gl-geocoder'; import location from './utils/images/location.svg'; // with import import jsonp from "jsonp"; +import ReactGA from 'react-ga'; const mapAccess = { mapboxApiAccessToken: process.env.REACT_APP_MAPBOX_TOKEN @@ -46,6 +47,9 @@ export default class AddressSearch extends React.Component { } } } + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.pageview('/address-search'); + } } handleOnSelected = (viewport, item) => { @@ -64,6 +68,13 @@ export default class AddressSearch extends React.Component { } nextQuestion = () => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Clicked continue button", + label: "address-search" + }); + } this.setState({ loadingAddressSearchBtn: true, disabledAddressSearchBtn: true, diff --git a/src/App.js b/src/App.js index 24d5d31f12449f0152f5e90b16d9e6c490a0b45b..07dc55a5bf9ec70da0009fdfee866c1e8c73357b 100644 --- a/src/App.js +++ b/src/App.js @@ -52,7 +52,7 @@ class App extends React.Component { buildingTypes: '', }, prevQuestion: '', - question: 'addressSearch', + question: 'addressSearch', // Set the first question as address search when initializing reviewQuestions: [], questions: this.resetQuestions(), pages: { @@ -886,11 +886,13 @@ class App extends React.Component { render() { const building = this.props.building; + // TODO: Why did we comment out the section below? // const questions = this.props.questions; const contact = this.props.contact; const complete = this.props.complete; let addressSearchMessage = ""; + // TODO: Explain why search success is set to true in render function? let addressSearchSuccess = true; if (building.data !== undefined && building.data.success === false && building.data.message !== undefined) { addressSearchSuccess = false; @@ -899,6 +901,9 @@ class App extends React.Component { addressSearchSuccess = true; } + // Generating an object to represent all the questions in our survey + // Each key value pair associates a title with a component that either handles one question or a set of questions + // each time we render this is being generated... why? const questions = { addressSearch: -1) { if (this.state.question === 'addressSearch') { - if(this.props.building.data.surveyId === 1) { - content = questions['fuels']; - } else if ([2, 3].includes(this.props.building.data.surveyId)) { - content = questions['buildingTypeSubType']; - } + // If we are in the address search question and we have building data set the content to the next question depending on survey id + if(this.props.building.data.surveyId === 1) { + // For NYC go to the fuel type question + content = questions['fuels']; + } else if ([2, 3].includes(this.props.building.data.surveyId)) { + // For Oakland and NYC go to the Building Type/ Subtype question + content = questions['buildingTypeSubType']; + } } else { content = questions[this.state.question]; } } else if (Object.keys(this.state.pages).indexOf(this.state.question) > -1) { + // If question index is not out of bounds display content of either the Thank you or congrats page content = this.state.pages[this.state.question]; } else { + // TODO: When would we reach this point? What case is this? content = questions[this.state.questions[this.state.question].prev]; } + // TODO: What is this.props.num ? return (
diff --git a/src/BuildingTypes.js b/src/BuildingTypes.js index 1b86d0598075a6c264ecbc2c94ad554db7e69903..bb36fbdff1a0883b5f62e9e46e48734e4d7c3067 100644 --- a/src/BuildingTypes.js +++ b/src/BuildingTypes.js @@ -7,6 +7,7 @@ import church from './utils/images/illustration-church.svg'; import coop from './utils/images/illustration-co-op.svg'; import warehouse from './utils/images/illustration-warehouse.svg'; import './index.css'; +import ReactGA from 'react-ga'; export default class BuildingTypes extends React.Component { @@ -26,11 +27,24 @@ export default class BuildingTypes extends React.Component { ]; } + componentDidMount () { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.pageview('/building-type'); + } + } + prevQuestion = () => { this.props.prevQuestion('buildingTypes'); } nextQuestion = () => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Clicked continue button", + label: "building-type" + }); + } this.props.setBuildingType( this.state.answer, this.names[this.props.answerIds.indexOf(this.state.answer)], @@ -39,6 +53,13 @@ export default class BuildingTypes extends React.Component { } chooseAnswer = (answer) => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Chose building type", + label: "building-type" + }); + } this.setState({ answer }); } diff --git a/src/ComfortIssues.js b/src/ComfortIssues.js index b3aacc522cd80188a41acc7d582dd8aecbfe96f1..a206cca511a47a74c859bb576c2c7f343fa0de66 100644 --- a/src/ComfortIssues.js +++ b/src/ComfortIssues.js @@ -1,5 +1,6 @@ import React from "react"; import { Row, Col, Button } from 'reactstrap'; +import ReactGA from 'react-ga'; export default class ComfortIssues extends React.Component { @@ -18,11 +19,24 @@ export default class ComfortIssues extends React.Component { } } + componentDidMount () { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.pageview('/comfort-issues'); + } + } + prevQuestion = () => { this.props.prevQuestion('comfortIssues'); } nextQuestion = () => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Clicked continue button", + label: "comfort-issues" + }); + } this.props.nextQuestion( 'comfortIssues', this.state.answerIds.map(answerId => this.names[this.props.answers[answerId]]), @@ -31,6 +45,13 @@ export default class ComfortIssues extends React.Component { } chooseAnswer = (answerId) => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Select answer", + label: "comfort-issues" + }); + } let answerIds = this.state.answerIds if (answerIds.includes(answerId)) { answerIds = answerIds.filter(id => id !== answerId); diff --git a/src/Contact.js b/src/Contact.js index 18350b0623f50b4483ae94763da231520d257a3d..30335e16c2577c20e51f69ebb68dfec54a9ccf19 100644 --- a/src/Contact.js +++ b/src/Contact.js @@ -2,6 +2,7 @@ import React from "react"; import { Row, Col, Input, Button } from 'reactstrap'; import './index.css'; import jsonp from "jsonp"; +import ReactGA from 'react-ga'; export default class Contact extends React.Component { constructor(props) { @@ -12,6 +13,12 @@ export default class Contact extends React.Component { }; } + componentDidMount () { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.pageview('/contact-information'); + } + } + handleInputChange = (event) => { const val = event.target.value; const name = event.target.name; @@ -28,6 +35,13 @@ export default class Contact extends React.Component { } submitContact = () => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Clicked continue button", + label: "contact-information" + }); + } if (this.validateContact()) { // Call the function only if the environment is production. if (process.env.NODE_ENV === 'production') { diff --git a/src/FinanceInterest.js b/src/FinanceInterest.js index 7d5edda08bcb4e7418d38a5bf64337488e3095d3..d465d7df3e9dd72ea9181e8adbc5f4165cf2cfa3 100644 --- a/src/FinanceInterest.js +++ b/src/FinanceInterest.js @@ -1,6 +1,7 @@ import React from "react"; import { Row, Col, Button } from 'reactstrap'; import './index.css'; +import ReactGA from 'react-ga'; export default class FinanceInterest extends React.Component { @@ -15,11 +16,24 @@ export default class FinanceInterest extends React.Component { }; } + componentDidMount () { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.pageview('/finance-interest'); + } + } + prevQuestion = () => { this.props.prevQuestion('financeInterest'); } nextQuestion = () => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Clicked continue button", + label: "finance-interest" + }); + } this.props.nextQuestion('financeInterest', this.names[this.state.answer], this.state.answer); } diff --git a/src/Fuels.js b/src/Fuels.js index ccb31436192d8107cbaffd2b296630085eb61630..0453b0ef826413485d6eea03cd04caa6f95da468 100644 --- a/src/Fuels.js +++ b/src/Fuels.js @@ -7,6 +7,7 @@ import dualFuel from './utils/images/icon-dual-fuel.svg'; import other from './utils/images/icon-i-don_t-know.svg'; import starIcon from './utils/images/icon-star.svg'; import './index.css'; +import ReactGA from 'react-ga'; export default class Fuels extends React.Component { @@ -24,11 +25,24 @@ export default class Fuels extends React.Component { }; } + componentDidMount () { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.pageview('/fuel-type'); + } + } + prevQuestion = () => { this.props.prevQuestion('fuels'); } nextQuestion = () => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Clicked continue button", + label: "fuel-type" + }); + } this.props.setFuelType(this.state.answer); this.props.nextQuestion('fuels', this.names[this.state.answer], @@ -38,6 +52,13 @@ export default class Fuels extends React.Component { } chooseFuel = (answer) => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Chose fuel type", + label: "fuel-type" + }); + } this.setState({ answer }); } diff --git a/src/HeatDistribution.js b/src/HeatDistribution.js index 625143a9bb349a5ff679f9f7973c97db99808f11..f94e4f822a777ccb5a7338e6305dfa0291c533eb 100644 --- a/src/HeatDistribution.js +++ b/src/HeatDistribution.js @@ -6,6 +6,7 @@ import hotWater from './utils/images/hot-water-hydronic.png'; import electricBaseboard from './utils/images/electric-baseboard@3x.png'; import forcedAir from './utils/images/forced-air@3x.png'; import other from './utils/images/icon-i-don_t-know.svg'; +import ReactGA from 'react-ga'; export default class HeatDistribution extends React.Component { @@ -23,11 +24,24 @@ export default class HeatDistribution extends React.Component { }; } + componentDidMount () { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.pageview('/heat-distribution'); + } + } + prevQuestion = () => { this.props.prevQuestion('heatDistribution'); } nextQuestion = () => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Clicked continue button", + label: "heat-distribution" + }); + } this.props.setHeatDistribution(this.state.answer); this.props.nextQuestion( 'heatDistribution', @@ -38,6 +52,13 @@ export default class HeatDistribution extends React.Component { } chooseAnswer = (answer) => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Chose type of heat distribution", + label: "heat-distribution" + }); + } this.setState({ answer }); } @@ -59,6 +80,7 @@ export default class HeatDistribution extends React.Component { { this.props.answerIds.map((answerId, id) => { + // TODO: This value is not used it seems const answerName = this.props.answers[answerId]; return ( diff --git a/src/HeatingSystemAge.js b/src/HeatingSystemAge.js index 6d34a6fd3e94ccfc4f2c0aba0414ec7cc3d0ad0c..798caa33d0bc36e3894730e80459f40a6a9b4209 100644 --- a/src/HeatingSystemAge.js +++ b/src/HeatingSystemAge.js @@ -2,6 +2,7 @@ import React from "react"; import { Row, Col, Button } from 'reactstrap'; import starIcon from './utils/images/icon-star.svg'; import './index.css'; +import ReactGA from 'react-ga'; export default class HeatingSystemAge extends React.Component { @@ -19,11 +20,24 @@ export default class HeatingSystemAge extends React.Component { ]; } + componentDidMount () { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.pageview('/heating-system-age'); + } + } + prevQuestion = () => { this.props.prevQuestion('heatingSystemAge'); } nextQuestion = () => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Clicked continue button", + label: "heating-system-age" + }); + } this.props.setHeatingSystemAge(this.state.answer); this.props.nextQuestion( 'heatingSystemAge', @@ -33,6 +47,13 @@ export default class HeatingSystemAge extends React.Component { } chooseAnswer = (answer) => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Chose heating system age", + label: "heating-system-age" + }); + } this.setState({ answer }); } diff --git a/src/HeatingSystemPlan.js b/src/HeatingSystemPlan.js index 7e8949955c97f99973239d73658667631c40421f..aed08c45af19eaae664ed9b19830060a4b43ab13 100644 --- a/src/HeatingSystemPlan.js +++ b/src/HeatingSystemPlan.js @@ -2,6 +2,7 @@ import React from "react"; import { Row, Col, Button } from 'reactstrap'; import './index.css'; import starIcon from './utils/images/icon-star.svg'; +import ReactGA from 'react-ga'; export default class HeatingSystemPlan extends React.Component { @@ -18,11 +19,24 @@ export default class HeatingSystemPlan extends React.Component { ]; } + componentDidMount () { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.pageview('/heating-system-plan'); + } + } + prevQuestion = () => { this.props.prevQuestion('heatingSystemPlan'); } nextQuestion = () => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Clicked continue button", + label: "heating-system-plan" + }); + } this.props.setHeatingSystemPlan(this.state.answer); this.props.nextQuestion( 'heatingSystemPlan', @@ -32,6 +46,13 @@ export default class HeatingSystemPlan extends React.Component { } chooseAnswer = (answer) => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Chose heating system plan", + label: "heating-system-plan" + }); + } this.setState({ answer }); } diff --git a/src/ReviewAnswers.js b/src/ReviewAnswers.js index b294c20c0ece2fd75c0b810a0974e73a535b9a92..89682de6644d8d801f022b1ab62d6744e77dffc5 100644 --- a/src/ReviewAnswers.js +++ b/src/ReviewAnswers.js @@ -1,6 +1,7 @@ import React from "react"; import { Row, Col, Button } from 'reactstrap'; import iconEdit from './utils/images/icon-edit.svg'; +import ReactGA from 'react-ga'; export default class ReviewAnswers extends React.Component { @@ -9,6 +10,12 @@ export default class ReviewAnswers extends React.Component { this.state = {}; } + componentDidMount () { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.pageview('/review-answers'); + } + } + prevQuestion = () => { this.props.prevQuestion('comfortIssues'); } @@ -18,6 +25,13 @@ export default class ReviewAnswers extends React.Component { } submit = () => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Clicked submit button", + label: "review-answers" + }); + } this.props.submit(); } diff --git a/src/UtilityBills.js b/src/UtilityBills.js index e97f9cbe5a99037bc96ab90dfdb9ff1c909a9096..b93ba1a55c10b510a1e0ac42d644064e41c36bc8 100644 --- a/src/UtilityBills.js +++ b/src/UtilityBills.js @@ -1,6 +1,7 @@ import React from "react"; import { Row, Col, Button } from 'reactstrap'; import './index.css'; +import ReactGA from 'react-ga'; export default class UtilityBills extends React.Component { @@ -13,11 +14,24 @@ export default class UtilityBills extends React.Component { this.names = ['Tenant', 'Landlord']; } + componentDidMount () { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.pageview('/utility-bills'); + } + } + prevQuestion = () => { this.props.prevQuestion('utilityBills'); } nextQuestion = () => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Clicked continue button", + label: "utility-bills" + }); + } this.props.nextQuestion( 'utilityBills', [ @@ -29,6 +43,13 @@ export default class UtilityBills extends React.Component { } chooseAnswer = (utility, answer) => { + if(process.env.REACT_APP_ENVIRONMENT==='production'){ + ReactGA.event({ + category: "Intake Survey", + action: "Chose who pays the bills", + label: "utility-bills" + }); + } if (utility === 'electricity') { this.setState({ electricityAnswer: answer }); }