feat: add click event detection and storage to EventView handler
Introduce a new `click_fields` list alongside existing document fields, implement `is_click_record` method to identify click events by checking for 'click' event type, and extend `get_record` to extract click-specific fields. In the `post` method, route click records to a new 'click' collection with associated visit_id, enabling separate storage and analysis of click interactions distinct from document and general event records.
This commit is contained in:
parent
a0077ee13f
commit
786e757458
@ -58,12 +58,15 @@ class BaseView(web.View):
|
|||||||
class EventView(BaseView):
|
class EventView(BaseView):
|
||||||
|
|
||||||
document_fields = ['title','html','domain','href']
|
document_fields = ['title','html','domain','href']
|
||||||
|
click_fields = ["event", "target"]
|
||||||
event_fields = ['target','event','tag','scroll_height','scroll_left','scroll_top','client_width','client_height','page_x','page_y','screen_x','screen_y','client_x','client_y','target_x','target_y']
|
event_fields = ['target','event','tag','scroll_height','scroll_left','scroll_top','client_width','client_height','page_x','page_y','screen_x','screen_y','client_x','client_y','target_x','target_y']
|
||||||
|
|
||||||
def is_document_record(self, data):
|
def is_document_record(self, data):
|
||||||
return data.get('html') and True or False
|
return data.get('html') and True or False
|
||||||
|
|
||||||
|
def is_click_record(self,data):
|
||||||
|
return data.get('event') == 'click'
|
||||||
|
|
||||||
def get_record(self, data):
|
def get_record(self, data):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -86,6 +89,16 @@ class EventView(BaseView):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
record = {}
|
||||||
|
for field in self.click_fields:
|
||||||
|
if field in data:
|
||||||
|
record[field] = data[field]
|
||||||
|
if len(record.keys()) == len(self.click_fields):
|
||||||
|
return record
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def get(self):
|
async def get(self):
|
||||||
@ -123,6 +136,10 @@ class EventView(BaseView):
|
|||||||
)
|
)
|
||||||
self.insert('visit', record)
|
self.insert('visit', record)
|
||||||
self.app.view_count += 1
|
self.app.view_count += 1
|
||||||
|
elif self.is_click_record(data):
|
||||||
|
data['visit_id'] = visit_id
|
||||||
|
record = data
|
||||||
|
self.insert('click', record)
|
||||||
else:
|
else:
|
||||||
data['visit_id'] = visit_id
|
data['visit_id'] = visit_id
|
||||||
record = data
|
record = data
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user