feat(Core): add optimize and complete code
This commit is contained in:
@@ -98,6 +98,10 @@ class TrackingService {
|
||||
}
|
||||
|
||||
private function logEvent($type, array $data = []) {
|
||||
if (empty($type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event = [
|
||||
'event_type' => $type,
|
||||
'product_id' => isset($data['product_id']) ? intval($data['product_id']) : null,
|
||||
@@ -111,7 +115,7 @@ class TrackingService {
|
||||
'created_at' => current_time('mysql'),
|
||||
];
|
||||
|
||||
$this->eventRepository->insert($event);
|
||||
return $this->eventRepository->insert($event);
|
||||
}
|
||||
|
||||
private function getSessionId() {
|
||||
@@ -124,7 +128,10 @@ class TrackingService {
|
||||
return $session_id;
|
||||
}
|
||||
|
||||
return 'guest_' . md5($_SERVER['REMOTE_ADDR'] . '|' . $_SERVER['HTTP_USER_AGENT']);
|
||||
$remote_addr = isset($_SERVER['REMOTE_ADDR']) ? sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])) : '';
|
||||
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])) : '';
|
||||
|
||||
return 'guest_' . md5($remote_addr . '|' . $user_agent);
|
||||
}
|
||||
|
||||
private function hasLogged($key) {
|
||||
|
||||
Reference in New Issue
Block a user