# Group class The `Group` class represents a group. An instance representing the current group is returned calling the [`group`](https://www.krenalis.com/docs/integrations/javascript-sdk/methods.md#group) method of `Krenalis`. For example: ```javascript const groupId = krenalis.group().id(); ``` ## id The `id` method is used to get and set the identifier of the group. It always returns the group's identifier, or `null` if there is no identifier. To set the group's identifier, call the `id` method with an argument: - to remove the identifier, pass a `null` argument. - to change the identifier, pass a non-empty `String` or a `Number` (the number will be converted to a `String`). If the passed identifier is the same of the current identifier, it does nothing. #### Syntax ```javascript id(id) ``` ```typescript id(id?: string | null): string | null ``` #### Parameters | Name | Type | Required | Description | |------|--------------------------------|----------|------------------------------------------------------------------------------| | `id` | `String` or `Number` | | Group identifier to set. If it is `null`, the group's identifier is removed. | #### Examples ```javascript const groupId = krenalis.group().id(); ``` ```javascript krenalis.group().id(null); ``` ```javascript krenalis.group().id('acme'); ``` ## traits The `traits` method is utilized for accessing and modifying the group's traits. It consistently returns the group's traits. To modify the group's traits, utilize the `traits` method with an argument: - To remove all traits, pass a `null` argument. - To update the traits, provide a non-null `object`. Since traits are serialized with `JSON.stringify`, they must consist only of serializable values and should not contain cyclic references. In case of serialization errors, a warning will be logged in the console. #### Syntax ```javascript traits(traits) ``` ```typescript traits(traits?: Record | null): Record ``` #### Parameters | Name | Type | Required | Description | |----------|----------|----------|-----------------------------------------------------| | `traits` | `Object` | | Group's traits to set. `null` to remove all traits. | #### Examples ```javascript const traits = krenalis.group().traits(); ``` ```javascript krenalis.group().traits(null); ``` ```javascript krenalis.group().traits({ name: 'Acme Inc.' }); ```