# Group assignation

Assign your users to groups such as a company, a plan or a cohort, so you can target and analyze them by group.

A group gathers users who share something: the company they work for, their plan, a cohort. A user can belong to several groups. In Screeb, you then target surveys and messages on group membership. Groups are also how segments get users from your code: see [Create user segments](https://help.screeb.app/user-data/user-segments/).

## Assign a user to a group

A group has a type (`company`, `plan`) and a name (`Apple`, `Growth`). The type is optional: without one, the group gets the default type.

```ts
import { Component, OnInit } from "@angular/core";
import { Screeb } from "@screeb/sdk-angular";

@Component({
  selector: "app-root",
  standalone: true,
  template: ``,
})
export class AppComponent implements OnInit {
  constructor(private screeb: Screeb) {}

  ngOnInit() {
    this.screeb.identityGroupAssign("Apple", "company");
    this.screeb.identityGroupAssign("Growth", "plan");
    this.screeb.identityGroupAssign("cohort-42"); // default group type
  }
}
```

The group name comes first and the type second, the reverse of the JavaScript tag and the mobile SDKs.

The group type and the group name are less than 128 characters. They contain letters, digits, spaces and the characters `-`, `_`, `.`, `/` and `:`. The user must be known to Screeb first: assign groups after the SDK has started.

## Add properties to a group

Properties describe the group. Identify the group by an id that never changes rather than by its display name, and send the name as a property:

```ts
await this.screeb.identityGroupAssign("nuR4eecu", "company", {
  name: "Apple",
  city: "Cupertino",
  employees: 160000,
});
```

A group has at most 1000 properties. Property names are 128 characters at most. Values are strings, numbers, booleans or dates.

## Remove a user from a group

```ts
await this.screeb.identityGroupUnassign("nuR4eecu", "company");
```
