# How is it possible to add a custom attribute to the web widget?

**URL:** <https://tiledesk.discourse.group/t/how-is-it-possible-to-add-a-custom-attribute-to-the-web-widget/128>\
**Category:** Technical issue\
**Created:** [May 9, 2022, 1:49pm UTC](https://tiledesk.discourse.group/t/how-is-it-possible-to-add-a-custom-attribute-to-the-web-widget/128 "2022-05-09T13:49:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel\_mozej](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@daniel\_mozej](https://tiledesk.discourse.group/u/daniel_mozej)\
**Post date:** [May 9, 2022, 1:49pm UTC](https://tiledesk.discourse.group/t/how-is-it-possible-to-add-a-custom-attribute-to-the-web-widget/128/1 "2022-05-09T13:49:38Z")

</div>

Hello Tildesk,  
is it possible to add a custom attributes during a conversation or before it starts ?

---

<div class="post-metadata">

**Author:** ![gabrielepan](https://yyz2.discourse-cdn.com/free1/user_avatar/tiledesk.discourse.group/gabrielepan/32/171_2.png) [@gabrielepan](https://tiledesk.discourse.group/u/gabrielepan)\
**Post date:** [May 9, 2022, 2:17pm UTC](https://tiledesk.discourse.group/t/how-is-it-possible-to-add-a-custom-attribute-to-the-web-widget/128/2 "2022-05-09T14:17:21Z")

</div>

Hi Daniel, of course!!  
You can do both.

1. **Set custom attributes as settings property (before conversation starts)**  
Set a custom attributes require only to add a key/value object as value of customAttributes tiledesk property in tiledeskSettings object or tiledesk\_customAttributes url parameter. Use double quotes for each key and value.  
As an example view this code on the docs: [https://developer.tiledesk.com/widget/attributes#example-3.-widget-with-custom-attributes](https://developer.tiledesk.com/widget/attributes#example-3.-widget-with-custom-attributes)

2. **Set customAttributes programmatically (during converstion)**  
in this case, you can subscribe to a tiledesk event named ‘onBeforeMessageSent’ to add programmatically a custom attributes. Then you can add your custom attributes as attributes.payload property value. Code below show you an example

```auto
window.tiledesk.on('onBeforeMessageSend', function (event_data) {
          console.log('event OnBeforeSendMessage', event_data)
          var message = event_data.detail.message
          message.attributes.payload = {
            "user_country": "Italy", 
            "user_code": "E001",
          }
});

```
