PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 All 128 releases
← All changes | src/AutoLaunch/functions/insights.js +30 -1 3.0.5 → 3.2.2 View file →
@@ -1,7 +1,9 @@
1 1 import { useLaunchDataStore } from '@auto-launch/state/launch-data';
2 2 import { INSIGHTS_HOST } from '@constants';
3 3 import { reqDataBasics } from '@shared/lib/data';
4 +import { track } from '@shared/lib/track';
5 +import apiFetch from '@wordpress/api-fetch';
4 6
5 7 const headers = {
6 8 'Content-type': 'application/json',
7 9 Accept: 'application/json',
@@ -7,11 +9,12 @@
7 9 Accept: 'application/json',
8 10 'X-Extendify': 'true',
9 11 };
10 12
11 -const { urlParams } = window.extLaunchData;
13 +const { urlParams, activeTests } = window.extLaunchData;
12 14 export const checkIn = ({
13 15 stage,
16 + description,
14 17 siteProfile = {},
15 18 sitePlugins = [],
16 19 siteStyle = {},
17 20 } = {}) => {
@@ -22,9 +25,13 @@
22 25 const payload = JSON.stringify({
23 26 ...reqDataBasics,
24 27 autoLaunch: true,
25 28 stage,
29 + description,
26 30 attempt,
31 + activeTests: Object.keys(activeTests ?? {}).length
32 + ? JSON.stringify(activeTests)
33 + : undefined,
27 34 skippedDescription: Boolean(urlParams?.title || urlParams?.description),
28 35 insightsId: siteId,
29 36 hostpartner: partnerId,
30 37 siteURL: homeUrl,
@@ -60,5 +67,27 @@
60 67 headers,
61 68 body: payload,
62 69 keepalive: true,
63 70 });
71 +};
72 +
73 +const probeFailureReason = async () => {
74 + try {
75 + // parse:false so we get the raw Response and can read the HTTP status — the
76 + // default JSON parse throws `invalid_json` on a blocked API's HTML error page.
77 + await apiFetch({ path: '/extendify/v1/shared/ping', parse: false });
78 + return null;
79 + } catch (error) {
80 + if (error?.status === 403) return '403';
81 + if (error?.status === 404) return '404';
82 + // Any other status means the request reached the REST API and errored
83 + // upstream (our ping only ever 200s) — reachable, so not "unreachable".
84 + if (error?.status) return null;
85 + return 'network';
86 + }
87 +};
88 +
89 +export const reportRestApiStatus = async () => {
90 + const reason = await probeFailureReason();
91 + if (!reason) return;
92 + track('rest_api_unreachable', { reason });
64 93 };