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
extendify / src / AutoLaunch / functions / insights.js

insights.js in Extendify 3.2.2, at src/AutoLaunch/functions/insights.js

94 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useLaunchDataStore } from '@auto-launch/state/launch-data';
2 import { INSIGHTS_HOST } from '@constants';
3 import { reqDataBasics } from '@shared/lib/data';
4 import { track } from '@shared/lib/track';
5 import apiFetch from '@wordpress/api-fetch';
6
7 const headers = {
8 'Content-type': 'application/json',
9 Accept: 'application/json',
10 'X-Extendify': 'true',
11 };
12
13 const { urlParams, activeTests } = window.extLaunchData;
14 export const checkIn = ({
15 stage,
16 description,
17 siteProfile = {},
18 sitePlugins = [],
19 siteStyle = {},
20 } = {}) => {
21 const { type, category, structure, objective } = siteProfile;
22 const { siteId, partnerId, homeUrl, wpLanguage } = reqDataBasics;
23 const attempt = useLaunchDataStore.getState()?.attempt || 1;
24
25 const payload = JSON.stringify({
26 ...reqDataBasics,
27 autoLaunch: true,
28 stage,
29 description,
30 attempt,
31 activeTests: Object.keys(activeTests ?? {}).length
32 ? JSON.stringify(activeTests)
33 : undefined,
34 skippedDescription: Boolean(urlParams?.title || urlParams?.description),
35 insightsId: siteId,
36 hostpartner: partnerId,
37 siteURL: homeUrl,
38 language: wpLanguage,
39 sitePlugins: sitePlugins?.map((p) => p?.name),
40 urlParameters: urlParams,
41 siteStyle,
42 style: siteStyle?.colorPalette,
43 siteProfile,
44 siteType: type,
45 siteCategory: category,
46 siteStructure: structure,
47 siteObjective: objective,
48 extra: {
49 userAgent: window?.navigator?.userAgent,
50 vendor: window?.navigator?.vendor || 'unknown',
51 platform:
52 window?.navigator?.userAgentData?.platform ||
53 window?.navigator?.platform ||
54 'unknown',
55 mobile: window?.navigator?.userAgentData?.mobile,
56 width: window.innerWidth,
57 height: window.innerHeight,
58 screenHeight: window.screen.height,
59 screenWidth: window.screen.width,
60 orientation: window.screen.orientation?.type,
61 touchSupport: 'ontouchstart' in window || navigator.maxTouchPoints > 0,
62 },
63 });
64
65 return fetch(`${INSIGHTS_HOST}/api/v1/launch`, {
66 method: 'POST',
67 headers,
68 body: payload,
69 keepalive: true,
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 });
93 };
94