Skip to main content
Answered

Intercome Widget not toggle correctly


Actually i am facing a issue and tried a lot of things to solve this bug, but could not find out whats the actuall reason behind this bug

Issue:
When I click launcher button, widget appears, then the launcher should become back btn to close that widget, but in my case when i first click the launcher widget appears and instead or becoming back btn, launcher suddenly blinks and return to its launcher state,
second time  i click the btn, nothing happens, thrid time i click the btn , a new widget appear on top of previous one, at it goes so on.

Please help me in solving this issue

Code:

if session[:user_id]
@intercom_hash = OpenSSL::HMAC.hexdigest("sha256", ENV["INTERCOM_SECRET_KEY"].to_s, session[:user_id].to_s)
end
 
 
<% if ENV['SEGMENT_JS_WRITE_KEY'] %>
<% if session[:user_id] && !current_user&.admin? && current_user.present? %>
<% profile = current_user.value&.profile %>
<script>
window.intercomSettings = {
api_base: "https://api-iam.intercom.io",
app_id: window.intercomID,
name: "<%= profile.first_name %> <%= profile.last_name %>",
<% if profile.phone_number %>
phone: '+1<%= profile.phone_number %>',
<% end %>
email: "<%= current_user.email %>",
user_id: "<%=session[:user_id] %>",
user_hash: "<%= @intercom_hash %>"
};
</script>
<script>
(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src="https://widget.intercom.io/widget/<%=ENV['INTERCOM_SECRET_ID'] %>";var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);};if(document.readyState==='complete'){l();}else if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();
</script>
<% elsif !current_user&.admin? %>
<script>
analytics.page();
</script>
<% end %>
<% end %>


 

Best answer by Nathan Sudds

@ans ishfaq  It looks like you’ve been editing the standard Intercom widget to include some other features and that may be impacting how it’s displaying -- do you have the same issue with the default Intercom widget code or only with this customized version?

 

I’d recommend testing the default version and confirming, if it’s working as expected then try to check to see what’s gone wrong with your edits. 

 

I took a minute to run it through Claude.ai and it had some suggestions to potentially fix the issue or what might be causing the issue.  You may want to give that a try as well.  Without being able to access the site you are embedding the code, it may be hard for us to determine what’s going wrong -- in that case, it is probably better to reach out to support via chat where you can share your URL and grant them access to take a look at the configuration if you can. 

Otherwise I hope this feedback is helpful!

View original
Did this topic help you find an answer to your question?

2 replies

Nathan Sudds
Top Expert ✨
Forum|alt.badge.img+5
  • Top Expert
  • 328 replies
  • Answer
  • March 24, 2025

@ans ishfaq  It looks like you’ve been editing the standard Intercom widget to include some other features and that may be impacting how it’s displaying -- do you have the same issue with the default Intercom widget code or only with this customized version?

 

I’d recommend testing the default version and confirming, if it’s working as expected then try to check to see what’s gone wrong with your edits. 

 

I took a minute to run it through Claude.ai and it had some suggestions to potentially fix the issue or what might be causing the issue.  You may want to give that a try as well.  Without being able to access the site you are embedding the code, it may be hard for us to determine what’s going wrong -- in that case, it is probably better to reach out to support via chat where you can share your URL and grant them access to take a look at the configuration if you can. 

Otherwise I hope this feedback is helpful!


  • Author
  • New Participant
  • 1 reply
  • March 25, 2025

I'm facing an issue with the widget while toggling, even when using the default launcher.

The only solution I've found so far is to remove the user ID from the Intercom settings and provide only the email. However, I'm not sure if this is the right approach.

Either not using the user id or set user_id as user email, both are working fine for me.

I'm sharing my code below—please review it and let me know if this solution is technically sound or if there's a better way to handle it.

if current_user
@intercom_hash = OpenSSL::HMAC.hexdigest("sha256", ENV["INTERCOM_SECRET_KEY"].to_s, current_user.id.to_s)
end

 

 

<% if ENV['SEGMENT_JS_WRITE_KEY'] %>
<% if current_user && !current_user.admin? %>
<% profile = current_user.value&.profile %>
<script>
window.intercomSettings = {
api_base: "https://api-iam.intercom.io",
app_id: window.intercomID,
name: "<%= profile.first_name %> <%= profile.last_name %>",
<% if profile.phone_number %>
phone: '+1<%= profile.phone_number %>',
<% end %>
email: "<%= current_user.email %>",
user_hash: "<%= @intercom_hash %>"
};
</script>
 
<script>
(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',w.intercomSettings);}else{var d=document;var i=function(){i.c(arguments);};i.q=[];i.c=function(args){i.q.push(args);};w.Intercom=i;var l=function(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src="https://widget.intercom.io/widget/<%= ENV['INTERCOM_SECRET_ID'] %>";var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);};if(document.readyState==='complete'){l();}else if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();
</script>
<% else %>
<script>
analytics.page();
</script>
<% end %>
<% end %>

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings