# User profile changed

Learn how to track changes related to a user's account.

This event tracks any changes related to a user's profile.

> **Automatically tracked**
>
> The SDK automatically tracks this event when you update the user profile.

## Implementation

Here is an example of how to track this event:

**JavaScript**

```javascript
import croct from '@croct/plug';

croct.user.edit()
.set('firstName', 'John Doe')
.set('email', 'john@croct.com')
.set('custom.plan', 'free')
.combine('activities', 'sign-up')
.save();
```

**HTML**

```html
<!DOCTYPE html>
<html>
<head>
  <title>My awesome application</title>
  <script src="https://cdn.croct.io/js/v1/lib/plug.js"></script>
  <script>croct.plug({appId: 'APPLICATION_ID'});</script>
</head>
<body>
  <script>
    function updateProfile() {
      croct.user.edit()
        .set('firstName', 'John Doe')
        .set('email', 'john@croct.com')
        .set('custom.plan', 'free')
        .combine('activities', 'sign-up')
        .save();
    }
  </script>
  <button onclick="updateProfile()">Trigger</button>
</body>
</html>
```

**React — JavaScript**

```jsx
import {useCroct} from '@croct/plug-react';

export function Example() {
const croct = useCroct();

function updateProfile() {
  croct.user.edit()
    .set('firstName', 'John Doe')
    .set('email', 'john@croct.com')
    .set('custom.plan', 'free')
    .combine('activities', 'sign-up')
    .save();
}

return (<button onClick={updateProfile}>Trigger</button>);
}
```

**React — TypeScript**

```typescript
import {useCroct} from '@croct/plug-react';
import type {ReactElement} from 'react';

export function Example(): ReactElement {
const croct = useCroct();

function updateProfile() {
  croct.user.edit()
    .set('firstName', 'John Doe')
    .set('email', 'john@croct.com')
    .set('custom.plan', 'free')
    .combine('activities', 'sign-up')
    .save();
}

return (<button onClick={updateProfile}>Trigger</button>);
}
```

**Next — JavaScript**

```jsx
import {useCroct} from '@croct/plug-next';

export function Example() {
const croct = useCroct();

function updateProfile() {
  croct.user.edit()
    .set('firstName', 'John Doe')
    .set('email', 'john@croct.com')
    .set('custom.plan', 'free')
    .combine('activities', 'sign-up')
    .save();
}

return (<button onClick={updateProfile}>Trigger</button>);
}
```

**Next — TypeScript**

```tsx
import {useCroct} from '@croct/plug-next';
import type {ReactElement} from 'react';

export function Example(): ReactElement {
const croct = useCroct();

function updateProfile() {
  croct.user.edit()
    .set('firstName', 'John Doe')
    .set('email', 'john@croct.com')
    .set('custom.plan', 'free')
    .combine('activities', 'sign-up')
    .save();
}

return (<button onClick={updateProfile}>Trigger</button>);
}
```

**Vue — JavaScript**

```vue
<script setup>
import {useCroct} from '@croct/plug-vue';

const croct = useCroct();

function subscribe(event) {
const form = new FormData(event.target);
const email = String(form.get('email'));

// Your logic to persist the email
api.subscribe(email);

croct.user.edit()
  .set('email', email)
  .save();
}
</script>

<template>
  <form @submit.prevent="subscribe">
      Subscribe to our newsletter!
      <input type="email" name="email" placeholder="Email"/>
      <button type="submit">Subscribe</button>
  </form>
</template>
```

**Vue — TypeScript**

```vue
<script setup lang="ts">
import {useCroct} from '@croct/plug-vue';

const croct = useCroct();

function subscribe(event: Event) {
const form = new FormData(event.target as HTMLFormElement);
const email = String(form.get('email'));

// Your logic to persist the email
api.subscribe(email);

croct.user.edit()
  .set('email', email)
  .save();
}
</script>

<template>
  <form @submit.prevent="subscribe">
      Subscribe to our newsletter!
      <input type="email" name="email" placeholder="Email"/>
      <button type="submit">Subscribe</button>
  </form>
</template>
```

**Nuxt — JavaScript**

```vue
<script setup>
const croct = useCroct()

function subscribe(event) {
const form = new FormData(event.target)
const email = String(form.get('email'))

// Your logic to persist the email
api.subscribe(email)

croct.user.edit()
  .set('email', email)
  .save()
}
</script>

<template>
  <form @submit.prevent="subscribe">
      Subscribe to our newsletter!
      <input type="email" name="email" placeholder="Email"/>
      <button type="submit">Subscribe</button>
  </form>
</template>
```

**Nuxt — TypeScript**

```vue
<script setup lang="ts">
const croct = useCroct()

function subscribe(event: Event) {
const form = new FormData(event.target as HTMLFormElement)
const email = String(form.get('email'))

// Your logic to persist the email
api.subscribe(email)

croct.user.edit()
  .set('email', email)
  .save()
}
</script>

<template>
  <form @submit.prevent="subscribe">
      Subscribe to our newsletter!
      <input type="email" name="email" placeholder="Email"/>
      <button type="submit">Subscribe</button>
  </form>
</template>
```

## Input properties

This event has no input properties.

## Processed properties

These properties are automatically tracked:

- `externalUserId`: `string`

  The user's unique identifier provided by the application, such as a UUID or a username.

  The value must be between 1 and 100 characters long.

- `patch`: `object`

  A set of operations performed on the user profile.

## Payload examples

Below are some payload examples for this event:

**Processed payload**

```json
{
  "type": "userProfileChanged",
  "externalUserId": "0e8d3d6e-4b6d-4b7b-8e0f-2e3b9e7b3e4d",
  "patch": {
    "operations": [
      {
        "type": "set",
        "path": "name",
        "value": "John Doe"
      },
      {
        "type": "set",
        "path": "email",
        "value": "john@croct.com",
      },
      {
        "type": "set",
        "path": "custom.plan",
        "value": "free",
      },
      {
        "type": "combine",
        "path": "activities",
        "value": "sign-up",
      }
    ]
  }
}
```

## Explore

- [Analytics](/reference/analytics): Learn how to analyze your dashboards.
- [CQL](/explanation/audience/examples/user-attributes): Learn how to create audiences based on the user profile.
