How to create events for a visitor that is already an intercom user?
Closed this issue · 1 comments
We use both web library and intercom-java
sdk to send events as some events can be sent from client side, but some need to be sent from server side. Here is how we send server side events:
- When the visitor triggers some action, say a failed login attempt, we grab
visitorId
from web librarywindow.Intercom("getVisitorId")
and send it to the server - On the server side, we first try to find the visitor
Visitor.findByUserID(visitorId)
, if it returnsNotFoundException
, then we try to find the leadContact.findByUserID(visitorId)
, if it returnsNotFoundException
, then we try to find currently logged in user from server session(I know, old technology), if no logged in user found, we can't create the event because we don't know who the user is. If any of the steps above succeeds, we can create the event with the returned user's userId
The flow above usually works, however it doesn't work when the visitor has already logged in, and remains in the same intercom session while the server session is cleared out - say we restarted the server after the visitor logged in. In this case, the visitorId
doesn't represent any visitor/lead anymore, and the user is no longer logged in to be found in the server session. So we don't know how to identify the user on the server side to send the event.
This is not a problem for client side events. So my question is, is there a way to workaround this on the intercom-java
sdk side?
Version info
- intercom-java version: 2.8.1
- Java version: 1.8
I workaround it by doing the following on intercom web library loaded:
- If
window.intercomSettings.user_id
is not null, don't do nothing else, otherwise proceed to next step - Make a call with
window.Intercom("getVisitorId")
to check if current visitor exists or not - If visitor exists, don't do anything else, otherwise reload intercom by calling:
window.Intercom("shutdown");
window.Intercom("boot", window.intercomSettings)
This will make sure intercom session in sync with server session, and any non logged in user to be treated as visitor.