---
title: newrelic_set_user_id (PHP agent API)
source: https://docs.newrelic.com/docs/apm/agents/php-agent/php-agent-api/newrelic_set_user_id
---

## Syntax

```php
newrelic_set_user_id(string $user_id)
```

Associate a unique user ID with the current transaction.

## Requirements

Agent version 10.12 or higher.

## Description

This API allows an application to assign a unique User ID to the current transaction.

This will allow a user to gain insight about individual end users, such as the impact of an error event.

## Parameters

| Parameter             | Description                                                                                           |
| --------------------- | ----------------------------------------------------------------------------------------------------- |
| `$user_id` (_string_) | Required. Should be a unique value (such as a UUID) that will be assigned to the current transaction. |

## Return values

This function will return `true` if the user ID was added successfully, otherwise `false`.

## Examples

```php
function example() {
    if (extension_loaded('newrelic')) { // Ensure PHP agent is available
        $user_id = "YOUR UNIQUE USER ID";
        newrelic_set_user_id($user_id);
    }
}
```
