emile 9 months ago
parent fe19c6429a
commit 48537a95ea

Binary file not shown.

@ -38,6 +38,7 @@ class OsitcomVisitor(WebsocketConsumer):
session_id = session_id,
ip_address = text_data_json.get('client_ip'),
country = text_data_json.get('client_country'),
region = text_data_json.get('client_region'),
browser_name = text_data_json.get('browser_name'),
os_name = text_data_json.get('os_name'),
)
@ -128,6 +129,7 @@ class Osichat(WebsocketConsumer):
'session_id': visitor.session_id,
'ip': visitor.ip_address,
'country': visitor.country,
'region' : visitor.region,
'country_flag': visitor.flag_image_url,
'name': visitor.name,
'mobile_number': visitor.mobile_number,

@ -0,0 +1,18 @@
# Generated by Django 4.2.5 on 2024-08-14 08:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('osichat', '0025_rename_chatotification_chatnotification'),
]
operations = [
migrations.AddField(
model_name='visitor',
name='region',
field=models.CharField(max_length=25, null=True),
),
]

@ -48,6 +48,7 @@ class Visitor(models.Model):
session_id = models.CharField(max_length=300)
ip_address = models.CharField(max_length=300)
country = models.CharField(max_length=15, null=True)
region = models.CharField(max_length=25, null=True)
name = models.CharField(max_length=200, blank=True, null=True)
mobile_number = models.CharField(max_length=10, null=True, blank=True)
email = models.CharField(max_length=100, null=True, blank=True)

@ -15,10 +15,11 @@ def get_client_ip(request):
response = requests.get(f'http://ipinfo.io/{client_ip}/json')
data = response.json()
country = data.get('country', 'Unknown')
region = data.get('region', 'Unknown')
except Exception as e:
country = "Unknown"
return JsonResponse({'ip': client_ip, 'country': country})
return JsonResponse({'ip': client_ip, 'country': country, 'region': region})
@csrf_exempt

@ -13,7 +13,8 @@ async function fetchClientData() {
if (data.ip) {
clientData = {
client_ip: data.ip,
client_country: data.country || 'Unknown'
client_country: data.country || 'Unknown',
client_region: data.region || 'Unknown'
};
}
} catch (error) {
@ -92,7 +93,6 @@ async function initializeVisitorsWebSocket() {
visitorsSocket.onopen = () => {
console.log('WebSocket connection to visitors established');
console.log('alooo'+window.document.title)
const event_message = {
'event_type': 'visitor_ping',
@ -101,6 +101,7 @@ async function initializeVisitorsWebSocket() {
'title': window.document.title,
'client_ip': clientData.client_ip,
'client_country': clientData.client_country,
'client_region': clientData.client_region,
'browser_name': browserInfo.browserName,
'os_name': browserInfo.osName,
'session_id': session_id

Loading…
Cancel
Save