Skip to content

Commit 8dc44ab

Browse files
committed
Purchases: Add analytics for sections in /purchases
1 parent f102e28 commit 8dc44ab

File tree

7 files changed

+73
-8
lines changed

7 files changed

+73
-8
lines changed

client/components/data/purchases/edit-card-details/index.jsx

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ const EditCardDetailsData = React.createClass( {
3535
sites: React.PropTypes.object.isRequired
3636
},
3737

38+
getDefaultProps() {
39+
return {
40+
trackingSlug: 'edit_card_details'
41+
};
42+
},
43+
3844
mixins: [ observe( 'sites' ) ],
3945

4046
componentWillMount() {

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Card from 'components/card';
1313
import Main from 'components/main';
1414
import HeaderCake from 'components/header-cake';
1515
import paths from '../paths';
16+
import purchasesMixin from '../purchases-mixin';
1617
import { isRefundable } from 'lib/purchases';
1718
import { cancelPrivateRegistration } from 'lib/upgrades/actions';
1819
import SimpleNotice from 'notices/simple-notice';
@@ -24,12 +25,14 @@ const CancelPrivateRegistration = React.createClass( {
2425
};
2526
},
2627

27-
goToManagePurchase() {
28-
const { domain, id } = this.props.selectedPurchase.data;
29-
30-
page( paths.managePurchase( domain, id ) );
28+
getDefaultProps() {
29+
return {
30+
trackingSlug: 'cancel_private_registration'
31+
};
3132
},
3233

34+
mixins: [ purchasesMixin ],
35+
3336
cancel() {
3437
const { domain, id } = this.props.selectedPurchase.data;
3538

@@ -44,10 +47,6 @@ const CancelPrivateRegistration = React.createClass( {
4447
} );
4548
},
4649

47-
isDataLoading() {
48-
return ( ! this.props.selectedSite || ! this.props.selectedPurchase.hasLoadedFromServer );
49-
},
50-
5150
renderDescriptionText() {
5251
const purchase = this.props.selectedPurchase.data;
5352

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

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ const CancelPurchase = React.createClass( {
2525
selectedSite: React.PropTypes.object
2626
},
2727

28+
getDefaultProps() {
29+
return {
30+
trackingSlug: 'cancel'
31+
};
32+
},
33+
2834
mixins: [ purchasesMixin ],
2935

3036
componentDidMount() {

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

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ const ConfirmCancelPurchase = React.createClass( {
2222
selectedSite: React.PropTypes.object
2323
},
2424

25+
getDefaultProps() {
26+
return {
27+
trackingSlug: 'confirm_cancel'
28+
};
29+
},
30+
2531
mixins: [ purchasesMixin ],
2632

2733
componentDidMount() {

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

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ const ManagePurchase = React.createClass( {
5454
destinationType: React.PropTypes.string
5555
},
5656

57+
getDefaultProps() {
58+
return {
59+
trackingSlug: 'manage'
60+
};
61+
},
62+
5763
mixins: [ purchasesMixin ],
5864

5965
isDataFetchingAfterRenewal() {

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

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ const EditPaymentMethod = React.createClass( {
1919
selectedSite: React.PropTypes.object.isRequired
2020
},
2121

22+
getDefaultProps() {
23+
return {
24+
trackingSlug: 'edit_payment_method'
25+
};
26+
},
27+
2228
mixins: [ purchasesMixin ],
2329

2430
render() {

client/me/purchases/purchases-mixin.js

+36
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,45 @@ import page from 'page';
66
/**
77
* Internal Dependencies
88
*/
9+
import analytics from 'analytics';
910
import paths from './paths';
1011

1112
export default {
13+
componentWillMount() {
14+
if ( this.isDataLoading() ) {
15+
return;
16+
}
17+
18+
const purchase = this.getPurchase();
19+
this.recordPageView( purchase );
20+
},
21+
22+
componentWillReceiveProps( nextProps ) {
23+
// Return if the purchases haven't loaded yet
24+
if ( ! nextProps.selectedPurchase.hasLoadedFromServer ) {
25+
return;
26+
}
27+
28+
// Return if the purchases have already been loaded into the props
29+
if ( this.props.selectedPurchase.data && nextProps.selectedPurchase.data.id === this.props.selectedPurchase.data.id ) {
30+
return;
31+
}
32+
33+
// We should only reach this part of the code whenever list of purchases changes
34+
// which will only be once per session
35+
const purchase = nextProps.selectedPurchase.data;
36+
this.recordPageView( purchase );
37+
},
38+
39+
recordPageView( purchase ) {
40+
if ( this.props.trackingSlug ) {
41+
analytics.tracks.recordEvent(
42+
`calypso_${ this.props.trackingSlug }_purchase_view`,
43+
{ product_slug: purchase.productSlug }
44+
);
45+
}
46+
},
47+
1248
getPurchase() {
1349
return this.props.selectedPurchase.data;
1450
},

0 commit comments

Comments
 (0)