emile 11 months ago
parent 8d3d1f99d3
commit 671fbe34d3

Binary file not shown.

@ -9,11 +9,6 @@ import requests
class OsitcomVisitor(WebsocketConsumer): class OsitcomVisitor(WebsocketConsumer):
def connect(self): def connect(self):
session = self.scope["session"]
if not session.session_key:
session.create()
session.save()
self.session_id = session.session_key
async_to_sync(self.channel_layer.group_add)( async_to_sync(self.channel_layer.group_add)(
'ositcom_visitors', self.channel_name 'ositcom_visitors', self.channel_name
@ -34,7 +29,7 @@ class OsitcomVisitor(WebsocketConsumer):
if event_type == 'new_visitor': if event_type == 'new_visitor':
event = { event = {
'type': 'new_visitor_handler', 'type': 'new_visitor_handler',
'session_id': self.session_id , 'session_id': text_data_json.get('session_id'),
'client_ip': text_data_json.get('client_ip'), 'client_ip': text_data_json.get('client_ip'),
'client_country': text_data_json.get('client_country'), 'client_country': text_data_json.get('client_country'),
'referrer': text_data_json.get('referrer'), 'referrer': text_data_json.get('referrer'),

@ -19,10 +19,20 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
} }
function fetchSessionID() {
return fetch('https://ositcom.com/get-client-session/')
.then(response => response.json())
.then(data => data.session_id)
.catch(error => {
console.error('Error fetching session ID:', error);
return 'Unknown';
});
}
function initializeWebSocket() { function initializeWebSocket() {
const referrer = document.referrer; const referrer = document.referrer;
fetchClientData().then(({ client_ip, client_country }) => { Promise.all([fetchClientData(), fetchSessionID()]).then(([clientData, session_id]) => {
const visitorsSocket = new WebSocket(visitorsSocketUrl); const visitorsSocket = new WebSocket(visitorsSocketUrl);
visitorsSocket.onopen = () => { visitorsSocket.onopen = () => {
@ -32,8 +42,9 @@ document.addEventListener('DOMContentLoaded', () => {
'event_type': 'new_visitor', 'event_type': 'new_visitor',
'referrer': referrer, 'referrer': referrer,
'url': window.location.href, 'url': window.location.href,
'client_ip': client_ip, 'client_ip': clientData.client_ip,
'client_country': client_country 'client_country': clientData.client_country,
'session_id': session_id
}; };
visitorsSocket.send(JSON.stringify(event_message)); visitorsSocket.send(JSON.stringify(event_message));
}; };

Loading…
Cancel
Save