segment-integrations / analytics-ios-integration-intercom

Segment's Intercom Integration for Analytics-iOS.
MIT License
2 stars 16 forks source link

Register unidentified user on init and reset #7

Closed davidruisinger closed 3 years ago

davidruisinger commented 6 years ago

Trying to open an intercom chat ([Intercom presentMessageComposer];) without being logged in leads to an error since Intercom ALWAYS requires the user to be identified. Luckily intercom offers the registerUnidentifiedUser method.

Looking at the current Intercom integration this method is also included: https://github.com/segment-integrations/analytics-ios-integration-intercom/blob/master/Segment-Intercom/Classes/SEGIntercomIntegration.m#L52

Unfortunately this method never seems to be called since an identify call with the segment SDK ALWAYS requires a user. So the else if (payload.anonymousId) where registerUnidentifiedUser would be called is never reached.

This pull requests changes this behavior and ALWAYS ensures that intercom has either an unregistered user (set within init and reset method) or a registered one (set in identify). This way the intercom chat can still be shown even though the user has not identified before.

NOTE: I applied the same changes to the android integration: https://github.com/segment-integrations/analytics-android-integration-intercom/pull/16