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