# User signed out

Learn how to track when a user logs out.

This event tracks when a user logs out of their account.

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

## Implementation

Here is an example of how to track this event:

**JavaScript**

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

croct.anonymize();
```

**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 anonymizeUser() {
      croct.anonymize();
    }
  </script>
  <button onclick="anonymizeUser()">Trigger</button>
</body>
</html>
```

**React — JavaScript**

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

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

const logout = () => {
  // Your logic to logout the user
  auth.logout();
  croct.anonymize();
};

return (<button onClick={logout}>Logout</button>);
}
```

**React — TypeScript**

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

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

const logout = (): void => {
  // Your logic to logout the user
  auth.logout();
  croct.anonymize();
};

return (<button onClick={logout}>Logout</button>);
}
```

**Next — JavaScript**

**components/LogoutButton.jsx**

```jsx
'use client';

import {logout} from '@/app/services';
import {anonymizeUser} from '@/app/actions';

export function LogoutButton() {
  const onClick = async () => {
    // Your logout logic
    await logout();
    // Anonymize the user
    await anonymizeUser();
  };

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

**app/actions.js**

```jsx
'use server';

import {anonymize} from '@croct/plug-next/server';

export async function anonymizeUser() {
  await anonymize();
}
```

**Next — TypeScript**

**components/LogoutButton.tsx**

```tsx
'use client';

import type {ReactElement} from 'react';
import {logout} from '@/app/services';
import {anonymizeUser} from '@/app/actions';

export function LogoutButton(): ReactElement {
  const onClick = async () => {
     // Your logout logic
     await logout();
     // Anonymize the user
     await anonymizeUser();
  };

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

**app/actions.ts**

```tsx
'use server';

import {anonymize} from '@croct/plug-next/server';

export async function anonymizeUser(): Promise<void> {
  await anonymize();
}
```

**Vue — JavaScript**

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

const croct = useCroct()

function logout() {
// Your logic to logout the user
auth.logout()
croct.anonymize()
}
</script>

<template>
  <button @click="logout">Logout</button>
</template>
```

**Vue — TypeScript**

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

const croct = useCroct()

function logout(): void {
// Your logic to logout the user
auth.logout()
croct.anonymize()
}
</script>

<template>
  <button @click="logout">Logout</button>
</template>
```

**Nuxt — JavaScript**

```vue
<script setup>
import auth from '@/services/auth'

const croct = useCroct()

function logout() {
// Your logic to logout the user
auth.logout()
croct.anonymize()
}
</script>

<template>
  <button @click="logout">Logout</button>
</template>
```

**Nuxt — TypeScript**

```vue
<script setup lang="ts">
import auth from '@/services/auth'

const croct = useCroct()

function logout(): void {
// Your logic to logout the user
auth.logout()
croct.anonymize()
}
</script>

<template>
  <button @click="logout">Logout</button>
</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.

## Payload examples

Below are some payload examples for this event:

**Processed payload**

```json
{
  "type": "userSignedOut",
  "externalUserId": "0e8d3d6e-4b6d-4b7b-8e0f-2e3b9e7b3e4d"
}
```

## 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.
