Skip to content

Commit

Permalink
Only check abParticipations in session storage if persistPage is defi…
Browse files Browse the repository at this point in the history
…ned in the abTestDefinition (#6691)

* only check abParticipations in session storage if persistPage defined

* small refactor

* store participations which use the persistPage prop in sessionStorage
  • Loading branch information
GHaberis authored Jan 17, 2025
1 parent 8fc3d61 commit 020e30e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 9 additions & 0 deletions support-frontend/assets/helpers/abTests/abtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ function getParticipations(

// Is the user already in this test in the current browser session?
if (
test.persistPage &&
!!sessionParticipations[testId] &&
targetPageMatches(path, test.persistPage)
) {
Expand Down Expand Up @@ -263,6 +264,14 @@ function getParticipations(
});
}

// Store participations which use the persistPage prop in sessionStorage
Object.keys(participations).forEach((testId) => {
if (abTests[testId]?.persistPage) {
sessionParticipations[testId] = participations[testId];
}
});
storage.setSession('abParticipations', JSON.stringify(sessionParticipations));

return participations;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import {
import type { BillingPeriod } from 'helpers/productPrice/billingPeriods';
import type { Promotion } from 'helpers/productPrice/promotions';
import { getPromotion } from 'helpers/productPrice/promotions';
import * as storage from 'helpers/storage/storage';
import type { GeoId } from 'pages/geoIdConfig';
import { getGeoIdConfig } from 'pages/geoIdConfig';
import Countdown from '../components/countdown';
Expand Down Expand Up @@ -292,9 +291,6 @@ export function ThreeTierLanding({
subPath: '/contribute',
};

// Persist any tests for tracking in the checkout page
storage.setSession('abParticipations', JSON.stringify(abParticipations));

const campaignSettings = getCampaignSettings(
countryGroupId,
urlSearchParamsPromoCode,
Expand Down

0 comments on commit 020e30e

Please sign in to comment.