Upload beautify
This commit is contained in:
18
resources/js/lib/feedAnalytics.js
Normal file
18
resources/js/lib/feedAnalytics.js
Normal file
@@ -0,0 +1,18 @@
|
||||
export function sendFeedAnalyticsEvent(payload) {
|
||||
const endpoint = '/api/analytics/feed'
|
||||
const body = JSON.stringify(payload)
|
||||
|
||||
if (typeof navigator !== 'undefined' && typeof navigator.sendBeacon === 'function') {
|
||||
const blob = new Blob([body], { type: 'application/json' })
|
||||
navigator.sendBeacon(endpoint, blob)
|
||||
return
|
||||
}
|
||||
|
||||
fetch(endpoint, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body,
|
||||
keepalive: true,
|
||||
}).catch(() => {
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user