From 0e956d177e7222fbb48b23171ef2f6bb715044cc Mon Sep 17 00:00:00 2001 From: Ian Ramos <5714212+IanRamosC@users.noreply.github.com> Date: Wed, 17 Jul 2024 17:02:49 -0300 Subject: [PATCH] Prevent fetching experiment if Tracks is disabled --- projects/packages/explat/src/client/assignment.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/projects/packages/explat/src/client/assignment.ts b/projects/packages/explat/src/client/assignment.ts index e1b3040c37556..80bd7d8f80b1c 100644 --- a/projects/packages/explat/src/client/assignment.ts +++ b/projects/packages/explat/src/client/assignment.ts @@ -10,11 +10,16 @@ const fetchExperimentAssignment = experimentName: string; anonId: string | null; } ): Promise< unknown > => { + if ( ! anonId ) { + throw new Error( `Tracking is disabled, can't fetch experimentAssignment` ); + } + const params = { experiment_name: experimentName, anon_id: anonId ?? undefined, as_connected_user: asConnectedUser, }; + const assignmentsRequestUrl = addQueryArgs( 'jetpack/v4/explat/assignments', params ); return await apiFetch( { path: assignmentsRequestUrl } );