Skip to main content

I am using the @intercom/messenger-js-sdk SDK.

It successfully records new users.

The problem is that I cannot find how to set custom attributes for that user. I have the custom attribute `is_admin`.

 

Here are the approaches I’ve tried:

  1. Basic object
Intercom({
app_id: APP_ID,
api_base: process.env.NEXT_PUBLIC_INTERCOM_API_BASE_URL,
user_id: user.id,
email: user.email,
user_hash: hash,
is_admin: user.role.includes('admin'),
});
  1. Object with custom_attributes
Intercom({
app_id: APP_ID,
api_base: process.env.NEXT_PUBLIC_INTERCOM_API_BASE_URL,
user_id: user.id,
email: user.email,
user_hash: hash,
custom_attributes: {
is_admin: user.role.includes('admin'),
}
});
  1. Post instance update method
Intercom({
app_id: APP_ID,
api_base: process.env.NEXT_PUBLIC_INTERCOM_API_BASE_URL,
user_id: user.id,
email: user.email,
user_hash: hash,
});

update({
user_id: user.id,
email: user.email,
is_admin: user.role.includes('admin'),
});

None of these approaches work. `is_admin` is always unknown.

Please let me know the correct approach for uploading custom attributes via the SDK or point me towards the correct documentation (I’ve found all 3 of the above approaches in various parts of the documentation - none of which are working).

Thanks

Hey there ​@Fergus Farrell, Emily here from Support Engineering at Intercom 👋🏼
 

To set custom attributes for a user using the @intercom/messenger-js-sdk, you should use the updateUser method. Here's how you can set the is_admin attribute for a user:

Intercom.updateUser({
  customAttributes: {
    is_admin: true
  }
});


This will update the user's information with the is_admin custom attribute set to true. If the is_admin attribute is not recognized by Intercom, it should be created automatically upon updating the user with this attribute. It's important to note that you can send only the data you want to update; you do not need to send every attribute each time. Once updated, you can view these attributes in the Intercom dashboard under the "USER DATA" section in the Inbox's right-hand sidebar. If you continue to experience issues, ensure that you are using the correct syntax as per the SDK documentation and that the SDK is properly initialized and configured in your application. For more details on using the updateUser method with the Intercom SDK, you can refer to the Intercom documentation for React Native or the relevant SDK documentation for your platform.

Hopefully this helps! 💪🏼


Thanks ​@Emilygav,

Apologies for the delay in response.

I’ve tried the syntax you recommend here but the custom attributes still are not making it into Intercom.

A couple of small points:

  1. There does not seem to be an `updateUser` method available in the SDK as per your recommendation. Instead I’ve used the `update` method which accepts user values as an argument. I assume this does the same thing?
  2. We are not using React Native, we are just using regular React, so I’m not sure whether the react native documentation will help us.
  3. I think a big part of the problem we’re facing is that I am reading the documentation, but I can’t find a clear way to upload these custom attributes using the `@intercom/messenger-js-sdk`

Any help or guidance is greatly appreciated! 


Reply