Skip to content

Commit

Permalink
restore sendEventContributionCheckoutConversion
Browse files Browse the repository at this point in the history
  • Loading branch information
GHaberis committed Oct 28, 2024
1 parent 4c208f7 commit 8f78a65
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { currencies } from 'helpers/internationalisation/currency';
import type { ContributionsStartListening } from 'helpers/redux/contributionsStore';
import * as storage from 'helpers/storage/storage';
import { trackComponentClick } from 'helpers/tracking/behaviour';
// import { sendEventContributionCartValue } from 'helpers/tracking/quantumMetric';
// import { threeTierCheckoutEnabled } from 'pages/supporter-plus-landing/setup/threeTierChecks';
import { sendEventContributionCartValue } from 'helpers/tracking/quantumMetric';
import { threeTierCheckoutEnabled } from 'pages/supporter-plus-landing/setup/threeTierChecks';
import { validateForm } from '../checkoutActions';
import {
// setAllAmounts,
setAllAmounts,
setOtherAmountError,
setProductType,
setSelectedAmount,
Expand All @@ -21,53 +21,50 @@ import {
isContribution,
} from './selectors/productType';

// const shouldSendEventContributionCartValue = isAnyOf(
// setAllAmounts,
// setProductType,
// setSelectedAmount,
// );
const shouldSendEventContributionCartValue = isAnyOf(
setAllAmounts,
setProductType,
setSelectedAmount,
);

const validatesOtherAmountField = isAnyOf(validateForm, validateOtherAmount);

export function addProductSideEffects(
startListening: ContributionsStartListening,
): void {
// startListening({
// matcher: shouldSendEventContributionCartValue,
// effect(_, listenerApi) {
// const {
// contributionAmount,
// contributionType,
// // contributionCurrency
// } = getContributionCartValueData(listenerApi.getState());

// if (!contributionAmount) {
// return;
// }

// const isMonthlyOrAnnual = ['MONTHLY', 'ANNUAL'].includes(
// contributionType,
// );

// const commonState = listenerApi.getState().common;

// if (
// threeTierCheckoutEnabled(
// commonState.abParticipations,
// commonState.amounts,
// ) &&
// isMonthlyOrAnnual
// ) {
// return;
// }

// sendEventContributionCartValue(
// contributionAmount.toString(),
// contributionType,
// contributionCurrency,
// );
// },
// });
startListening({
matcher: shouldSendEventContributionCartValue,
effect(_, listenerApi) {
const { contributionAmount, contributionType, contributionCurrency } =
getContributionCartValueData(listenerApi.getState());

if (!contributionAmount) {
return;
}

const isMonthlyOrAnnual = ['MONTHLY', 'ANNUAL'].includes(
contributionType,
);

const commonState = listenerApi.getState().common;

if (
threeTierCheckoutEnabled(
commonState.abParticipations,
commonState.amounts,
) &&
isMonthlyOrAnnual
) {
return;
}

sendEventContributionCartValue(
contributionAmount.toString(),
contributionType,
contributionCurrency,
);
},
});

startListening({
actionCreator: setProductType,
Expand Down
73 changes: 37 additions & 36 deletions support-frontend/assets/helpers/tracking/quantumMetric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ enum SendEventSubscriptionCheckoutConversion {
GuardianWeeklySubGift = 70,
}

// enum SendEventContributionAmountUpdate {
// SingleContribution = 71,
// RecurringContribution = 72,
// }
enum SendEventContributionAmountUpdate {
SingleContribution = 71,
RecurringContribution = 72,
}

enum SendEventContributionPaymentMethodUpdate {
PaymentMethod = 103,
Expand All @@ -70,7 +70,7 @@ type SendEventId =
| SendEventTestParticipationId
| SendEventSubscriptionCheckoutStart
| SendEventSubscriptionCheckoutConversion
// | SendEventContributionAmountUpdate
| SendEventContributionAmountUpdate
| SendEventContributionCheckoutConversion
| SendEventContributionPaymentMethodUpdate
| SendEventAcquisitionDataFromQueryParam
Expand All @@ -87,17 +87,17 @@ const {
GuardianWeeklySubGift,
} = SendEventSubscriptionCheckoutStart;

// const { SingleContribution, RecurringContribution } =
// SendEventContributionAmountUpdate;
const { SingleContribution, RecurringContribution } =
SendEventContributionAmountUpdate;

const cartValueEventIds: SendEventId[] = [
DigiSub,
PaperSub,
GuardianWeeklySub,
DigiSubGift,
GuardianWeeklySubGift,
// SingleContribution,
// RecurringContribution,
SingleContribution,
RecurringContribution,
];

async function ifQmPermitted(callback: () => void) {
Expand Down Expand Up @@ -361,32 +361,33 @@ function sendEventContributionCheckoutConversion(
});
}

// function sendEventContributionCartValue(
// amount: string,
// contributionType: ContributionType,
// sourceCurrency: IsoCurrency,
// ): void {
// if (amount === 'other' || Number.isNaN(parseInt(amount))) {
// return;
// }
// void ifQmPermitted(() => {
// const sendEventWhenReady = () => {
// const sendEventId =
// contributionType === 'ONE_OFF'
// ? SendEventContributionAmountUpdate.SingleContribution
// : SendEventContributionAmountUpdate.RecurringContribution;
// const convertedValue = getCheckoutAnnualValue(
// contributionType,
// parseInt(amount),
// sourceCurrency,
// );
// if (convertedValue) {
// sendEvent(sendEventId, false, Math.round(convertedValue).toString());
// }
// };
// sendEventWhenReadyTrigger(sendEventWhenReady);
// });
// }
// TODO: To be deleted with the 2-step checkout
function sendEventContributionCartValue(
amount: string,
contributionType: ContributionType,
sourceCurrency: IsoCurrency,
): void {
if (amount === 'other' || Number.isNaN(parseInt(amount))) {
return;
}
void ifQmPermitted(() => {
const sendEventWhenReady = () => {
const sendEventId =
contributionType === 'ONE_OFF'
? SendEventContributionAmountUpdate.SingleContribution
: SendEventContributionAmountUpdate.RecurringContribution;
const convertedValue = getCheckoutAnnualValue(
contributionType,
parseInt(amount),
sourceCurrency,
);
if (convertedValue) {
sendEvent(sendEventId, false, Math.round(convertedValue).toString());
}
};
sendEventWhenReadyTrigger(sendEventWhenReady);
});
}

function sendEventPaymentMethodSelected(
paymentMethod: PaymentMethod | 'StripeExpressCheckoutElement' | null,
Expand Down Expand Up @@ -499,7 +500,7 @@ export {
sendEventSubscriptionCheckoutStart,
sendEventSubscriptionCheckoutConversion,
sendEventContributionCheckoutConversion,
// sendEventContributionCartValue,
sendEventContributionCartValue,
sendEventPaymentMethodSelected,
sendEventConversionPaymentMethod,
sendEventAcquisitionDataFromQueryParamEvent,
Expand Down

0 comments on commit 8f78a65

Please sign in to comment.