Skip to content

Commit 433f681

Browse files
authored
Merge pull request #796 from newfold-labs/fix/migration-endpoint
Fix Migration Event Endpoint
2 parents 9c300ef + 27ae4a8 commit 433f681

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/app/steps/Migration/MigrationStep.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { useCallback } from '@wordpress/element';
22
import { dispatch, useSelect } from '@wordpress/data';
3+
import apiFetch from '@wordpress/api-fetch';
34
import { Container, Title, Spinner } from '@newfold/ui-component-library';
45
import { ExclamationCircleIcon } from '@heroicons/react/24/solid';
56
import { nfdOnboardingStore } from '@/data/store';
67
import { Navigate, Step } from '@/components';
7-
import { getSiteMigrateUrl, getWpSettings } from '@/utils/api';
8+
import { getSiteMigrateUrl, getWpSettings, migrateRestURL } from '@/utils/api';
89
import migrationFigureUrl from '@/assets/nfd-migration.png';
9-
import { OnboardingEvent, sendOnboardingEvent, trackOnboardingEvent } from '@/utils/analytics/hiive';
10+
import { OnboardingEvent, trackOnboardingEvent } from '@/utils/analytics/hiive';
1011
import { ACTION_ERROR_STATE_TRIGGERED, ACTION_MFE_MIGRATION_INITIATED, ACTION_MIGRATION_INITIATED } from '@/utils/analytics/hiive/constants';
1112

1213
const MigrationStep = () => {
@@ -36,13 +37,21 @@ const MigrationStep = () => {
3637
initiationSource = ACTION_MIGRATION_INITIATED;
3738
}
3839

39-
// Analytics: migration initiated event
40-
return sendOnboardingEvent(
41-
new OnboardingEvent(
42-
initiationSource,
43-
instaWpMigrationUrl
44-
)
45-
);
40+
/*
41+
Send analytics event to custom migration endpoint. This uses the application endpoint (via the worker)
42+
to ensure reliable event delivery The `await` ensures the request completes before navigation, preventing it from being cancelled on redirect.
43+
*/
44+
await apiFetch( {
45+
url: migrateRestURL( 'migrate/events' ),
46+
method: 'POST',
47+
data: {
48+
key: initiationSource,
49+
data: {
50+
path: instaWpMigrationUrl,
51+
page: window.location.href,
52+
},
53+
},
54+
} );
4655
};
4756

4857
const prepareMigration = useCallback( async () => {

0 commit comments

Comments
 (0)