Skip to content

Commit 41c5157

Browse files
drewblaisdellscruffian
authored andcommitted
Purchases: Add analytics for single-purchase sections in /purchases
1 parent 7eeb1c1 commit 41c5157

File tree

7 files changed

+69
-7
lines changed

7 files changed

+69
-7
lines changed

client/me/purchases/cancel-private-registration/index.jsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import paths from '../paths';
1616
import { isRefundable } from 'lib/purchases';
1717
import { cancelPrivateRegistration } from 'lib/upgrades/actions';
1818
import SimpleNotice from 'notices/simple-notice';
19-
import { goToManagePurchase, isDataLoading } from '../utils';
19+
import { goToManagePurchase, isDataLoading, recordPageView } from '../utils';
2020

2121
const CancelPrivateRegistration = React.createClass( {
2222
getInitialState() {
@@ -25,6 +25,14 @@ const CancelPrivateRegistration = React.createClass( {
2525
};
2626
},
2727

28+
componentWillMount() {
29+
recordPageView( 'cancel_private_registration', this.props );
30+
},
31+
32+
componentWillReceiveProps( nextProps ) {
33+
recordPageView( 'cancel_private_registration', this.props, nextProps );
34+
},
35+
2836
cancel() {
2937
const { domain, id } = this.props.selectedPurchase.data;
3038

client/me/purchases/cancel-purchase/index.jsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,22 @@ import HeaderCake from 'components/header-cake';
1717
import Main from 'components/main';
1818
import paths from '../paths';
1919
import { getName, isCancelable } from 'lib/purchases';
20-
import { getPurchase, goToManagePurchase, isDataLoading } from '../utils';
20+
import { getPurchase, goToManagePurchase, isDataLoading, recordPageView } from '../utils';
2121

2222
const CancelPurchase = React.createClass( {
2323
propTypes: {
2424
selectedPurchase: React.PropTypes.object.isRequired,
2525
selectedSite: React.PropTypes.object
2626
},
2727

28+
componentWillMount() {
29+
recordPageView( 'cancel_purchase', this.props );
30+
},
31+
32+
componentWillReceiveProps( nextProps ) {
33+
recordPageView( 'cancel_purchase', this.props, nextProps );
34+
},
35+
2836
componentDidMount() {
2937
this.ensurePageCanLoad();
3038
},

client/me/purchases/confirm-cancel-purchase/index.jsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,22 @@ import HeaderCake from 'components/header-cake';
1515
import Main from 'components/main';
1616
import notices from 'notices';
1717
import paths from 'me/purchases/paths';
18-
import { getPurchase, goToManagePurchase } from '../utils';
18+
import { getPurchase, goToManagePurchase, recordPageView } from '../utils';
1919

2020
const ConfirmCancelPurchase = React.createClass( {
2121
propTypes: {
2222
selectedPurchase: React.PropTypes.object,
2323
selectedSite: React.PropTypes.object
2424
},
2525

26+
componentWillMount() {
27+
recordPageView( 'confirm_cancel_purchase', this.props );
28+
},
29+
30+
componentWillReceiveProps( nextProps ) {
31+
recordPageView( 'confirm_cancel_purchase', this.props, nextProps );
32+
},
33+
2634
componentDidMount() {
2735
if ( ! this.props.selectedPurchase.hasLoadedFromServer || ! this.props.selectedSite ) {
2836
return;

client/me/purchases/manage-purchase/index.jsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
showCreditCardExpiringWarning,
4646
showEditPaymentDetails
4747
} from 'lib/purchases';
48-
import { getPurchase, goToList, isDataLoading } from '../utils';
48+
import { getPurchase, goToList, isDataLoading, recordPageView } from '../utils';
4949

5050
const ManagePurchase = React.createClass( {
5151
propTypes: {
@@ -55,6 +55,14 @@ const ManagePurchase = React.createClass( {
5555
destinationType: React.PropTypes.string
5656
},
5757

58+
componentWillMount() {
59+
recordPageView( 'manage', this.props );
60+
},
61+
62+
componentWillReceiveProps( nextProps ) {
63+
recordPageView( 'manage', this.props, nextProps );
64+
},
65+
5866
isDataFetchingAfterRenewal() {
5967
return 'thank-you' === this.props.destinationType && this.props.selectedPurchase.isFetching;
6068
},

client/me/purchases/payment/edit-card-details/index.jsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import ValidationErrorList from 'notices/validation-error-list';
2626
import { createPaygateToken } from 'lib/store-transactions';
2727
import wpcomFactory from 'lib/wp';
2828
import paths from 'me/purchases/paths';
29-
import { getPurchase, goToManagePurchase, isDataLoading } from 'me/purchases/utils';
29+
import { getPurchase, goToManagePurchase, isDataLoading, recordPageView } from 'me/purchases/utils';
3030

3131
const wpcom = wpcomFactory.undocumented();
3232

@@ -55,6 +55,8 @@ const EditCardDetails = React.createClass( {
5555
],
5656

5757
componentWillReceiveProps( nextProps ) {
58+
recordPageView( 'edit_card_details', this.props, nextProps );
59+
5860
// Updates the form once with the stored credit card data as soon as they are available
5961
if ( nextProps.card && ( ! this.props.card || ( nextProps.card.id !== this.props.card.id ) ) ) {
6062
this.setState( {
@@ -77,6 +79,8 @@ const EditCardDetails = React.createClass( {
7779
},
7880

7981
componentWillMount() {
82+
recordPageView( 'edit_card_details', this.props );
83+
8084
const options = {
8185
validatorFunction: this.validate,
8286
onNewState: this.setFormState

client/me/purchases/payment/edit-payment-method/index.jsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@ import EditPaymentMethodCreditCard from './credit-card';
1111
import HeaderCake from 'components/header-cake';
1212
import { isPaidWithCreditCard, isPaidWithPaypal } from 'lib/purchases';
1313
import Main from 'components/main';
14-
import { getPurchase, goToManagePurchase, isDataLoading } from 'me/purchases/utils';
14+
import { getPurchase, goToManagePurchase, isDataLoading, recordPageView } from 'me/purchases/utils';
1515

1616
const EditPaymentMethod = React.createClass( {
1717
propTypes: {
1818
selectedPurchase: React.PropTypes.object.isRequired,
1919
selectedSite: React.PropTypes.object.isRequired
2020
},
2121

22+
componentWillMount() {
23+
recordPageView( 'edit_payment_method', this.props );
24+
},
25+
26+
componentWillReceiveProps( nextProps ) {
27+
recordPageView( 'edit_payment_method', this.props, nextProps );
28+
},
29+
2230
render() {
2331
if ( isDataLoading( this.props ) ) {
2432
return (

client/me/purchases/utils.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import page from 'page';
66
/**
77
* Internal dependencies
88
*/
9+
import analytics from 'analytics';
910
import paths from './paths';
1011

1112
function getPurchase( props ) {
@@ -32,10 +33,27 @@ function isDataLoading( props ) {
3233
return ( ! props.selectedSite || ! props.selectedPurchase.hasLoadedFromServer );
3334
}
3435

36+
function recordPageView( trackingSlug, props, nextProps = null ) {
37+
if ( isDataLoading( nextProps || props ) ) {
38+
return null;
39+
}
40+
41+
if ( nextProps &&
42+
( props.selectedPurchase.hasLoadedFromServer || ! nextProps.selectedPurchase.hasLoadedFromServer ) ) {
43+
// only record the page view the first time the purchase loads from the server
44+
return null;
45+
}
46+
47+
const { productSlug } = getPurchase( nextProps || props );
48+
49+
analytics.tracks.recordEvent( `calypso_${ trackingSlug }_purchase_view`, { product_slug: productSlug } );
50+
}
51+
3552
export {
3653
getPurchase,
3754
goToList,
3855
goToEditCardDetails,
3956
goToManagePurchase,
40-
isDataLoading
57+
isDataLoading,
58+
recordPageView
4159
}

0 commit comments

Comments
 (0)