Skip to content

Commit

Permalink
feat: abtest initialised with valid selectedAmountsVariant
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-daniel-dempsey committed Jan 16, 2025
1 parent 4dcb79b commit c18fd57
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 39 deletions.
26 changes: 6 additions & 20 deletions support-frontend/assets/helpers/abTests/abtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function init({
selectedAmountsVariant,
sessionParticipations,
);
console.log('*** init.participations', participations);

const urlParticipations = getParticipationsFromUrl();
const serverSideParticipations = getServerSideParticipations();
return {
Expand Down Expand Up @@ -171,10 +171,9 @@ function getParticipations(
sessionParticipations: Participations = {},
): Participations {
const participations: Participations = {};

Object.entries(abTests).forEach(([testId, test]) => {
console.log('*** testId:', testId);
if (!test.isActive) {
console.log('*** getParticipations 0');
return;
}

Expand Down Expand Up @@ -224,7 +223,6 @@ function getParticipations(
selectedAmountsVariant.testName !== contributionsOnlyAmountsTestName &&
includeOnlyContributionsOnlyCountries
) {
console.log('*** getParticipations 6');
return;
}

Expand All @@ -242,20 +240,13 @@ function getParticipations(
}

const variantAssignment = assignUserToVariant(mvtId, test, participation);
console.log(
'*** getParticipations 9, test, participation',
test,
participation,
);

if (variantAssignment.type === 'NOT_ASSIGNED') {
return;
}
console.log(
'*** getParticipations 9, variantAssignment',
variantAssignment,
);

const testVariantId = test.variants[variantAssignment.variantIndex]?.id;
console.log('*** getParticipations 9, testVariantId', testVariantId);

if (testVariantId) {
participations[testId] = testVariantId;
}
Expand Down Expand Up @@ -651,14 +642,9 @@ function assignUserToVariant(
): VariantAssignment {
// For non-referrrer controlled tests we assign the user randomly
if (participation.type === 'ACTIVE_PARTICIPATION') {
console.log(
'*** assignUserToVariant.ACTIVE_PARTICIPATION (non-referrrer controlled)',
randomNumber(mvtId, test.seed) % test.variants.length,
assigned(randomNumber(mvtId, test.seed) % test.variants.length),
);
return assigned(randomNumber(mvtId, test.seed) % test.variants.length);
}
console.log('*** assignUserToVariant. referrrer controlled ');

// For referrrer controlled tests the assignment comes from the acquisition data.
// If the variant in the acquisition data doesn't match up with any defined in
// the test, we log an error and don't assign the user to the test.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const tests: Tests = {
size: 1,
},
},
isActive: true,
isActive: false,
referrerControlled: false, // ab-test name not needed to be in paramURL
seed: 9,
targetPage: pageUrlRegexes.contributions.allLandingPagesAndThankyouPages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,10 @@ const router = () => {
abParticipations={commonState.abParticipations}
/>
) : showNewContributionsOnly ? (
<ContributionsOnlyLanding
geoId={countryId}
abParticipations={commonState.abParticipations}
/>
<ContributionsOnlyLanding geoId={countryId} />
) : (
<SupporterPlusInitialLandingPage
thankYouRoute={thankYouRoute}
abParticipations={commonState.abParticipations}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ import { useState } from 'preact/hooks';
import { Header } from 'components/headers/simpleHeader/simpleHeader';
import { PageScaffold } from 'components/page/pageScaffold';
import { PaymentFrequencyButtons } from 'components/paymentFrequencyButtons/paymentFrequencyButtons';
import type { Participations } from 'helpers/abTests/abtest';
import { getAmountsTestVariant } from 'helpers/abTests/abtest';
import type { ContributionType } from 'helpers/contributions';
import { Country } from 'helpers/internationalisation/classes/country';
// import * as storage from 'helpers/storage/storage';
import type { GeoId } from 'pages/geoIdConfig';
import { getGeoIdConfig } from 'pages/geoIdConfig';
import { AmountsCard } from '../components/amountsCard';
Expand Down Expand Up @@ -138,22 +136,17 @@ const paymentFrequencyMap = {

type ContributionsOnlyLandingProps = {
geoId: GeoId;
abParticipations: Participations;
};
export function ContributionsOnlyLanding({
geoId,
}: // abParticipations,
ContributionsOnlyLandingProps): JSX.Element {
}: ContributionsOnlyLandingProps): JSX.Element {
const urlSearchParams = new URLSearchParams(window.location.search);
const urlSearchParamsRatePlan = urlSearchParams.get('ratePlan');
const urlSearchParamsOneTime = urlSearchParams.has('oneTime');

const { currencyKey: currencyId, countryGroupId } = getGeoIdConfig(geoId);
const countryId = Country.detect();

// Persist any tests for tracking from this contribute page
// storage.setSession('abParticipations', JSON.stringify(abParticipations));

const getInitialContributionType = () => {
if (urlSearchParamsOneTime) {
return 'ONE_OFF';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ import { useEffect } from 'preact/hooks';
import { Box } from 'components/checkoutBox/checkoutBox';
import { BrandedIcons } from 'components/paymentMethodSelector/creditDebitIcons';
import { PaypalIcon } from 'components/paymentMethodSelector/paypalIcon';
import type { Participations } from 'helpers/abTests/abtest';
import { resetValidation } from 'helpers/redux/checkout/checkoutActions';
import { getContributionType } from 'helpers/redux/checkout/product/selectors/productType';
import { getUserSelectedAmount } from 'helpers/redux/checkout/product/selectors/selectedAmount';
import {
useContributionsDispatch,
useContributionsSelector,
} from 'helpers/redux/storeHooks';
// import * as storage from 'helpers/storage/storage';
import { getThresholdPrice } from 'helpers/supporterPlus/benefitsThreshold';
import { AmountAndBenefits } from '../formSections/amountAndBenefits';
import { PatronsPriceCards } from '../formSections/patronsPriceCards';
Expand Down Expand Up @@ -89,7 +87,6 @@ export function SupporterPlusInitialLandingPage({
thankYouRoute,
}: {
thankYouRoute: string;
abParticipations: Participations;
}): JSX.Element {
const dispatch = useContributionsDispatch();
const { countryGroupId } = useContributionsSelector(
Expand All @@ -102,8 +99,6 @@ export function SupporterPlusInitialLandingPage({
getThresholdPrice(contributionType, state),
);

// Persist any tests for tracking from this contribute page
// storage.setSession('abParticipations', JSON.stringify(abParticipations));
const { abParticipations } = useContributionsSelector(
(state) => state.common,
);
Expand Down

0 comments on commit c18fd57

Please sign in to comment.