<script>
window.increase_shows = function ({profiles, route = '{{ app.request.attributes.get('_route') }}', forceSend = false}) {
const data = {
'profiles': profiles,
'source': route,
'forceSend': forceSend
};
const endpoint = '{{ path("profile_ctr.increase_shows") }}';
// При закрытии страницы используем sendBeacon для надежной доставки
if (forceSend && navigator.sendBeacon) {
const blob = new Blob([JSON.stringify(data)], {type: 'application/json'});
try {
navigator.sendBeacon(endpoint, blob);
return Promise.resolve();
} catch (error) {
console.error('Error sendBeacon, falling back to fetch', error);
// Fallback to fetch if sendBeacon fails
}
}
// Обычная асинхронная отправка через fetch
return fetch(endpoint, {
method: 'POST',
headers: {
"X-Requested-With": "XMLHttpRequest"
},
body: JSON.stringify(data)
}).catch(error => {
console.error('Error increase_shows', error);
})
}
window.increase_views = function (profileId) {
fetch('{{ path("profile_ctr.increase_views") }}', {
method: 'POST',
headers: {
"X-Requested-With": "XMLHttpRequest"
},
body: JSON.stringify({
'profile': profileId,
})
}).catch(error => {
console.error('Error increase_views', error);
})
}
</script>