|
1 | 1 | import { useCallback } from '@wordpress/element';
|
2 | 2 | import { dispatch, useSelect } from '@wordpress/data';
|
| 3 | +import apiFetch from '@wordpress/api-fetch'; |
3 | 4 | import { Container, Title, Spinner } from '@newfold/ui-component-library';
|
4 | 5 | import { ExclamationCircleIcon } from '@heroicons/react/24/solid';
|
5 | 6 | import { nfdOnboardingStore } from '@/data/store';
|
6 | 7 | import { Navigate, Step } from '@/components';
|
7 |
| -import { getSiteMigrateUrl, getWpSettings } from '@/utils/api'; |
| 8 | +import { getSiteMigrateUrl, getWpSettings, migrateRestURL } from '@/utils/api'; |
8 | 9 | import migrationFigureUrl from '@/assets/nfd-migration.png';
|
9 |
| -import { OnboardingEvent, sendOnboardingEvent, trackOnboardingEvent } from '@/utils/analytics/hiive'; |
| 10 | +import { OnboardingEvent, trackOnboardingEvent } from '@/utils/analytics/hiive'; |
10 | 11 | import { ACTION_ERROR_STATE_TRIGGERED, ACTION_MFE_MIGRATION_INITIATED, ACTION_MIGRATION_INITIATED } from '@/utils/analytics/hiive/constants';
|
11 | 12 |
|
12 | 13 | const MigrationStep = () => {
|
@@ -36,13 +37,21 @@ const MigrationStep = () => {
|
36 | 37 | initiationSource = ACTION_MIGRATION_INITIATED;
|
37 | 38 | }
|
38 | 39 |
|
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 | + } ); |
46 | 55 | };
|
47 | 56 |
|
48 | 57 | const prepareMigration = useCallback( async () => {
|
|
0 commit comments