From 78df3067078b29e868ca5fbe40e01101cd60982d Mon Sep 17 00:00:00 2001 From: Ahmad Abdolsaheb Date: Tue, 31 Dec 2019 20:59:32 +0300 Subject: [PATCH] feat(client): unify GA and add to donation (#37984) --- .../client-only-routes/ShowCertification.js | 131 +++++++++++------- client/src/components/Donation/DonateForm.js | 4 +- .../Donation/DonateFormChildViewForHOC.js | 8 +- .../src/components/Donation/DonationModal.js | 41 +++++- .../components/Donation/MinimalDonateForm.js | 6 +- client/src/components/Map/components/Block.js | 26 ++-- .../components/Map/components/Block.test.js | 2 + .../YearEndGift/YearEndDonationForm.js | 20 ++- .../src/components/layouts/Certification.js | 8 +- client/src/components/layouts/Default.js | 15 +- client/src/pages/donate.js | 40 +++++- client/src/pages/year-end-gift.js | 53 ++++++- client/src/redux/ga-saga.js | 11 ++ client/src/redux/index.js | 6 + .../Challenges/components/CompletionModal.js | 10 +- .../Challenges/components/HelpModal.js | 9 +- .../Challenges/components/ResetModal.js | 11 +- .../Challenges/components/VideoModal.js | 12 +- 18 files changed, 304 insertions(+), 109 deletions(-) create mode 100644 client/src/redux/ga-saga.js diff --git a/client/src/client-only-routes/ShowCertification.js b/client/src/client-only-routes/ShowCertification.js index 3981692f6d..8848af9bab 100644 --- a/client/src/client-only-routes/ShowCertification.js +++ b/client/src/client-only-routes/ShowCertification.js @@ -15,7 +15,8 @@ import { showCert, userFetchStateSelector, usernameSelector, - isDonatingSelector + isDonatingSelector, + executeGA } from '../redux'; import validCertNames from '../../utils/validCertNames'; import { createFlashMessage } from '../components/Flash/redux'; @@ -37,6 +38,7 @@ const propTypes = { certDashedName: PropTypes.string, certName: PropTypes.string, createFlashMessage: PropTypes.func.isRequired, + executeGA: PropTypes.func, fetchState: PropTypes.shape({ pending: PropTypes.bool, complete: PropTypes.bool, @@ -74,19 +76,20 @@ const mapStateToProps = (state, { certName }) => { }; const mapDispatchToProps = dispatch => - bindActionCreators({ createFlashMessage, showCert }, dispatch); + bindActionCreators({ createFlashMessage, showCert, executeGA }, dispatch); class ShowCertification extends Component { constructor(...args) { super(...args); this.state = { - closeBtn: false, - donationClosed: false + isDonationSubmitted: false, + isDonationDisplayed: false, + isDonationClosed: false }; this.hideDonationSection = this.hideDonationSection.bind(this); - this.showDonationCloseBtn = this.showDonationCloseBtn.bind(this); + this.handleProcessing = this.handleProcessing.bind(this); } componentDidMount() { @@ -97,12 +100,53 @@ class ShowCertification extends Component { return null; } - hideDonationSection() { - this.setState({ donationClosed: true }); + shouldComponentUpdate(nextProps) { + const { + userFetchState: { complete: userComplete }, + signedInUserName, + isDonating, + cert: { username = '' }, + executeGA + } = nextProps; + const { isDonationDisplayed } = this.state; + + if ( + !isDonationDisplayed && + userComplete && + signedInUserName === username && + !isDonating + ) { + this.setState({ + isDonationDisplayed: true + }); + + executeGA({ + type: 'event', + data: { + category: 'Donation', + action: 'Displayed Certificate Donation', + nonInteraction: true + } + }); + } + return true; } - showDonationCloseBtn() { - this.setState({ closeBtn: true }); + hideDonationSection() { + this.setState({ isDonationDisplayed: false, isDonationClosed: true }); + } + + handleProcessing(duration, amount) { + this.props.executeGA({ + type: 'event', + data: { + category: 'donation', + action: 'certificate stripe form submission', + label: duration, + value: amount + } + }); + this.setState({ isDonationSubmitted: true }); } render() { @@ -111,13 +155,14 @@ class ShowCertification extends Component { fetchState, validCertName, createFlashMessage, - certName, - signedInUserName, - isDonating, - userFetchState + certName } = this.props; - const { donationClosed, closeBtn } = this.state; + const { + isDonationSubmitted, + isDonationDisplayed, + isDonationClosed + } = this.state; if (!validCertName) { createFlashMessage(standardErrorMessage); @@ -125,7 +170,6 @@ class ShowCertification extends Component { } const { pending, complete, errored } = fetchState; - const { complete: userComplete } = userFetchState; if (pending) { return ; @@ -149,8 +193,6 @@ class ShowCertification extends Component { completionTime } = cert; - let conditionalDonationSection = ''; - const donationCloseBtn = (