Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tracks to Place Order button #7854

Merged
merged 6 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/add-place-order-tracks
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: dev

Place order button Tracks
20 changes: 20 additions & 0 deletions client/checkout/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
} from '../constants.js';
import { getDeferredIntentCreationUPEFields } from './payment-elements';
import { handleWooPayEmailInput } from '../woopay/email-input-iframe';
import wcpayTracks from 'tracks';
import wooPayExpressCheckoutPaymentMethod from '../woopay/express-button/woopay-express-checkout-payment-method';
import { isPreviewing } from '../preview';

Expand Down Expand Up @@ -113,6 +114,24 @@ Object.entries( enabledPaymentMethodsConfig )
} );
} );

const addCheckoutTracking = () => {
const placeOrderButton = document.getElementsByClassName(
'wc-block-components-checkout-place-order-button'
);
if ( placeOrderButton.length ) {
placeOrderButton[ 0 ].addEventListener( 'click', () => {
const blocksCheckbox = document.getElementById(
'radio-control-wc-payment-method-options-woocommerce_payments'
);
if ( ! blocksCheckbox?.checked ) {
return;
}

wcpayTracks.recordUserEvent( wcpayTracks.events.PLACE_ORDER_CLICK );
} );
}
};

// Call handleWooPayEmailInput if woopay is enabled and this is the checkout page.
if ( getUPEConfig( 'isWooPayEnabled' ) ) {
if (
Expand All @@ -131,4 +150,5 @@ if ( getUPEConfig( 'isWooPayEnabled' ) ) {
registerExpressPaymentMethod( paymentRequestPaymentMethod( api ) );
window.addEventListener( 'load', () => {
enqueueFraudScripts( getUPEConfig( 'fraudServices' ) );
addCheckoutTracking();
} );
13 changes: 13 additions & 0 deletions client/checkout/classic/event-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import WCPayAPI from 'wcpay/checkout/api';
import apiRequest from '../utils/request';
import { handleWooPayEmailInput } from 'wcpay/checkout/woopay/email-input-iframe';
import { isPreviewing } from 'wcpay/checkout/preview';
import wcpayTracks from 'tracks';

jQuery( function ( $ ) {
enqueueFraudScripts( getUPEConfig( 'fraudServices' ) );
Expand Down Expand Up @@ -58,6 +59,18 @@ jQuery( function ( $ ) {
return processPaymentIfNotUsingSavedMethod( $( this ) );
} );

$( 'form.checkout' ).on( 'click', '#place_order', function () {
const isWCPay = document.getElementById(
'payment_method_woocommerce_payments'
).checked;

if ( ! isWCPay ) {
return;
}

wcpayTracks.recordUserEvent( wcpayTracks.events.PLACE_ORDER_CLICK );
} );

window.addEventListener( 'hashchange', () => {
if ( window.location.hash.startsWith( '#wcpay-confirm-' ) ) {
showAuthenticationModalIfRequired( api );
Expand Down
1 change: 1 addition & 0 deletions client/tracks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const events = {
MULTI_CURRENCY_ENABLED_CURRENCIES_UPDATED:
'wcpay_multi_currency_enabled_currencies_updated',
PAYMENT_REQUEST_SETTINGS_CHANGE: 'wcpay_payment_request_settings_change',
PLACE_ORDER_CLICK: 'checkout_place_order_button_click',
// WCPay Subscriptions empty state - prompts to connect to WCPay or create product.
SUBSCRIPTIONS_EMPTY_STATE_VIEW: 'wcpay_subscriptions_empty_state_view',
SUBSCRIPTIONS_EMPTY_STATE_FINISH_SETUP:
Expand Down
Loading