diff --git a/src/messenger/webim/client.php b/src/messenger/webim/client.php index 8ec20acf..6ec8e397 100644 --- a/src/messenger/webim/client.php +++ b/src/messenger/webim/client.php @@ -22,6 +22,7 @@ require_once('libs/groups.php'); require_once('libs/expand.php'); require_once('libs/captcha.php'); require_once('libs/invitation.php'); +require_once('libs/track.php'); require_once('libs/classes/thread.php'); if(Settings::get('enablessl') == "1" && Settings::get('forcessl') == "1") { diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php index 095df339..9895a3b8 100644 --- a/src/messenger/webim/libs/chat.php +++ b/src/messenger/webim/libs/chat.php @@ -689,6 +689,11 @@ function chat_start_for_user($group_id, $requested_operator, $visitor_id, $visit $_SESSION['threadid'] = $thread->id; + // Bind thread to the visitor + if (Settings::get('enabletracking')) { + track_visitor_bind_thread($visitor_id, $thread); + } + // Send several messages if ($is_invited) { $operator = operator_by_id($thread->agentId); diff --git a/src/messenger/webim/libs/track.php b/src/messenger/webim/libs/track.php index ef25cdde..27065add 100644 --- a/src/messenger/webim/libs/track.php +++ b/src/messenger/webim/libs/track.php @@ -221,4 +221,24 @@ function track_get_user_id($visitorid) { return $visitor['userid']; } +/** + * Bind chat thread with visitor + * + * @param string $user_id User ID ({chatsitevisitor}.userid field) of the + * visitor. + * @param Thread $thread Chat thread object + */ +function track_visitor_bind_thread($user_id, $thread) { + $db = Database::getInstance(); + $db->query( + 'UPDATE {chatsitevisitor} ' . + 'SET threadid = :thread_id ' . + 'WHERE userid = :user_id', + array( + ':thread_id' => $thread->id, + ':user_id' => $user_id + ) + ); +} + ?> \ No newline at end of file