Liang Zhou
Liang Zhou

Reputation: 2165

How to create events for a visitor that is already an intercom user?

We use both intercom 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:

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?

Upvotes: 0

Views: 842

Answers (1)

Liang Zhou
Liang Zhou

Reputation: 2165

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.

Upvotes: 0

Related Questions