# Event occurred

Learn how to track a custom event.

This event tracks a domain-specific event.

> **When should I track this event?**
>
> Track this event whenever you want to record that something happened for later analysis or personalization.

## Implementation

Here is an example of how to track this event:

**JavaScript**

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

croct.track('eventOccurred', {
  name: 'userRatedProduct'
});
```

**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>
    const track = () => croct.track('eventOccurred', {
        name: 'userRatedProduct'
      });
  </script>
  <button onclick="track()">Trigger</button>
</body>
</html>
```

**React — JavaScript**

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

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

const track = () => croct.track('eventOccurred', {
    name: 'userRatedProduct'
  });

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

**React — TypeScript**

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

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

const track = () => croct.track('eventOccurred', {
    name: 'userRatedProduct'
  });

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

**Next — JavaScript**

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

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

const track = () => croct.track('eventOccurred', {
    name: 'userRatedProduct'
  });

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

**Next — TypeScript**

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

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

const track = () => croct.track('eventOccurred', {
    name: 'userRatedProduct'
  });

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

**Vue — JavaScript**

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

const croct = useCroct()

const track = () => croct.track('eventOccurred', {
    name: 'userRatedProduct'
  })
</script>

<template>
  <button @click="track">Trigger</button>
</template>
```

**Vue — TypeScript**

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

const croct = useCroct()

const track = (): void => croct.track('eventOccurred', {
    name: 'userRatedProduct'
  })
</script>

<template>
  <button @click="track">Trigger</button>
</template>
```

**Nuxt — JavaScript**

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

const track = () => croct.track('eventOccurred', {
    name: 'userRatedProduct'
  })
</script>

<template>
<button @click="track">Trigger</button>
</template>
```

**Nuxt — TypeScript**

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

const track = (): void => croct.track('eventOccurred', {
    name: 'userRatedProduct'
  })
</script>

<template>
<button @click="track">Trigger</button>
</template>
```

## Input properties

These are the supported properties:

- `name`: `string`

  The name of the event.

  The value must be between 1 and 50 characters long.

- `details`: `object` (optional)

  The details of the event.

  The following restrictions apply to the properties:

  - It allows up to 10 properties
  - Keys must be strings up to 300 characters long, starting with a letter or underscore, followed by letters, digits, or underscores
  - Values can be strings up to 300 characters long, numbers, booleans, and null.

## Processed properties

This event has no processed properties.

## Payload examples

Below are some payload examples for this event:

**Basic payload**

```json
{
  "name": "userRatedProduct"
}
```

**Full payload**

```json
{
  "name": "userRatedProduct",
  "details": {
    "productId": "12345",
    "rating": 5
  }
}
```

**Processed payload**

```json
{
  "type": "eventOccurred",
  "name": "userRatedProduct",
  "details": {
    "productId": "12345",
    "rating": 5
  }
}
```

## Explore

- [Analytics](/reference/analytics): Learn how to analyze your dashboards.
- [Event-based audiences](/reference/cql/expressions/events/event-types/event-experienced): Learn how to create audiences based on this event.
