intercom / intercom-rails

The easiest way to install Intercom in a Rails app.
https://developers.intercom.io/reference
MIT License
281 stars 107 forks source link

Add callback method in controller when auto include filter decides not to insert javascript #344

Open khoan opened 1 year ago

khoan commented 1 year ago

Why?

We have lots of javascript code that blindly invokes window.Intercom(...) expecting that it's a function. The assumption that window.Intercom is always a function breaks down, when IntercomRails::AutoInclude::Filter is evaluated to exclude javascript, which results in JS runtime error.

How?

This PR adds a configurable callback method on a controller for case when IntercomRails::AutoInclude::Filter excludes javascript. Within the controller callback, a shim can be added to ensure that window.Intercom is indeed a function.