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