ember-intercom-io
ember-intercom-io copied to clipboard
Problem figuring out when to call `update()`
I have the following usage pattern:
- When the user is on my login page, I do not have
{{intercom-io}}
loaded in my template - When the user logs in, session data is set into the
intercom.user
object - A page is loaded that does have the
{{intercom-io}}
helper loaded
The problem is that intercom.isBooted
is not true when I go and set the user data as the template hasn't loaded {{intercom-io}}
yet.
If I refresh the page, everything looks right, my current user is displayed when I click on the messenger and get the "Hi <username>
👋 " message instead of "Hi there
👋"
Can anyone suggest where the best place, in my Ember app, I could place an intercom.update()
call so that my messenger is loaded with the current user data?
@ctataryn The best way to handle this is in your currentUser
or session
service (or whatever you call that concept).
I usually create some sort of set of computed properties on that service that's called intercomData
that watches wherever that user session data is stored.
Then at some point after wherever you authenticated/loaded up your data i call a method like 'didLoadUser' on my session/current user service where I set things like intercom data, analytics data tracking , etc.
The documentation surrounding this needs an update. If you take a look at the intercom.js
service, the environment.js
variables for name
, email
, userId
, createdAt
, etc that you declare are computed properties and they monitor the user
object NOT user.name
or whatever properties you end up using.
Therefore, when you make a call to this.get('intercom').update()
the addon doesn't register the changes you made to the user
object if you used this.get('intercom').set('user.name', user.get('name')
since that change is being made on a property and not the object.
Thus, you need to do the following:
this.get('intercom').set('user', {
name: user.get('name'),
email: user.get('email'),
user_id: user.get('id'),
created_at: user.get('createdAt')
});
Then, when you call update()
you also need to tell the intercom service which properties to update: this.get('intercom').update(this.get('intercom.user'))
.
When I followed the documentation, everything worked fine if I was already logged in and opened a new window because the intercom.js
service handled things gracefully during the boot()
call. It didn't work though when I opened a new window and then logged in because the intercom.js
service wasn't seeing the new values on my user
object and I wasn't passing those into the update()
call.