-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathuserInfo.js
36 lines (31 loc) · 1 KB
/
userInfo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export const fetchVisitorInfo = ({ deviceInfo, country }) => {
const encodedDeviceInfo = encodeURIComponent(JSON.stringify(deviceInfo))
const fetchOptions = {
method: 'POST',
credentials: 'include',
mode: 'cors',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: `{ visitorInfo(
country: "${country}",
deviceInfo: "${encodedDeviceInfo}"
) }`
})
}
fetchOptions.headers["disable-set-cookie"] = true
return fetch(`/targeting/graphql`, fetchOptions)
.then(res => {
if (res.status !== 200) {
throw new Error(`targeting responded with statuscode ${res.status}`)
}
return res.json()
})
.then(json => {
if (!json || !json.data || !json.data.visitorInfo) {
throw new Error('response missing required fields')
}
return json.data.visitorInfo
})
}