---
title: Create a custom attribute
source: https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/create-attribute
---

## Android

### Syntax [#syntax]

#### Java [#java]

```java
NewRelic.setAttribute(string $name, string or float $value)
```

#### Kotlin [#kotlin]

```kotlin
NewRelic.setAttribute(name: String?, value: String?)
NewRelic.setAttribute(name: String?, value: Double)
NewRelic.setAttribute(name: String?, value: Boolean)
```

### Description [#description]

This static method creates a session-level custom [attribute](https://docs.newrelic.com/docs/insights/explore-data/custom-events/insert-custom-attributes-events-new-relic-mobile#attribute-definition) with a specified name and value. This method overwrites its previous value and type each time it is called. The created attribute is shared by multiple [Mobile event types](https://docs.newrelic.com/docs/insights/insights-data-sources/default-data/mobile-events).

You can override any of the [MobileSession default attributes](https://docs.newrelic.com/docs/insights/insights-data-sources/default-attributes/mobile-default-attributes-insights) except:

-   `appId`
-   `appName`
-   `accountId`
-   `carrier`
-   `category`
-   `deviceManufacturer`
-   `deviceModel`
-   `eventType`
-   `install`
-   `lastInteraction`
-   `memUsageMb`
-   `newRelicVersion`
-   `osMajorVersion`
-   `osName`
-   `osVersion`
-   `platform`
-   `platformVersion`
-   `sessionDuration`
-   `sessionId`
-   `timestamp`
-   `type`
-   `upgradeFrom`
-   `uuid`
-   Anything prefixed with `NewRelic`

    ### Parameters [#parameters]

    | Parameter | Type                | Description                                                                              |
    | --------- | ------------------- | ---------------------------------------------------------------------------------------- |
    | `$name`   | `string`            | Required. Name of the attribute.                                                         |
    | `$value`  | `string` or `float` | Required. The second parameter passed can be either a `string` value or a `float` value. |

    ### Return values [#return-values]

    Returns `true` if recorded successfully, and `false` if it doesn't.

    ### Example [#example]

    Here's an example of creating an attribute with the specified text name and text value. `setAttribute` overwrites its previous value and type each time it is called:

    #### Java [#java]

```java
boolean attributeSet = NewRelic.setAttribute("storeId", "SampleStoreId000");
```

#### Kotlin [#kotlin]

```kotlin
val attributeSet = NewRelic.setAttribute("storeId", "SampleStoreId000")
```

Here's an example of creating an attribute with the specified text name and numeric value:

#### Java [#java]

```java
boolean attributeSet = NewRelic.setAttribute("rate", 9999.99);
```

#### Kotlin [#kotlin]

```kotlin
val attributeSet = NewRelic.setAttribute("rate", 9999.99)
```

## iOS

### Syntax [#syntax][#syntax]

#### Objective-c [#objc]

```objectivec
setAttribute:(NSString*)name value:(id) value;
```

#### Swift [#swift]

```swift
NewRelic.setAttribute(string $name, string or float $value)
```

### Description [#description]

This static method creates a session-level custom [attribute](https://docs.newrelic.com/docs/insights/explore-data/custom-events/insert-custom-attributes-events-new-relic-mobile#attribute-definition) with a specified name and value. When called, it overwrites its previous value and type. The created attribute is shared by multiple [Mobile monitoring event types](https://docs.newrelic.com/docs/insights/insights-data-sources/default-data/mobile-events).

You can override any of the [MobileSession default attributes](https://docs.newrelic.com/docs/insights/insights-data-sources/default-attributes/mobile-default-attributes-insights) except:

-   `appId`
-   `appName`
-   `accountId`
-   `carrier`
-   `category`
-   `deviceManufacturer`
-   `deviceModel`
-   `eventType`
-   `install`
-   `lastInteraction`
-   `memUsageMb`
-   `newRelicVersion`
-   `osMajorVersion`
-   `osName`
-   `osVersion`
-   `platform`
-   `platformVersion`
-   `sessionDuration`
-   `sessionId`
-   `timestamp`
-   `type`
-   `upgradeFrom`
-   `uuid`
-   Anything prefixed with `NewRelic`

    ### Parameters [#parameters]

    | Parameter | Type                | Description                                                                              |
    | --------- | ------------------- | ---------------------------------------------------------------------------------------- |
    | `$name`   | `string`            | Required. Name of the session attribute.                                                 |
    | `$value`  | `string` or `float` | Required. The second parameter passed can be either a `string` value or a `float` value. |

    ### Return values [#return-values]

    Returns `true` if recorded successfully, and `false` if it doesn't.

    ### Examples [#examples]

    #### Objective-C [#obj-c]

```objectivec
BOOL attributeSet = [NewRelic setAttribute:@"buildConfiguration" value:@"AppStore-release"];
BOOL attributeSet = [NewRelic setAttribute:@"rate" value:@9999.99];
```

#### Swift [#swift]

```swift
var attributeSet = NewRelic.setAttribute("buildConfiguration", value: "AppStore-release")
attributeSet = NewRelic.setAttribute("rate", value: 9999.99)
```

## Capacitor

### Syntax [#syntax]

```typescript
setAttribute(options: { name: string; value: string; }) => void
```

### Description [#description]

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

### Parameters [#parameters]

| Parameter | Type                | Description                           |
| --------- | ------------------- | ------------------------------------- |
| `name`    | `string`            | Required. The name of the attribute.  |
| `value`   | `string` or `float` | Required. The value of the attribute. |

### Example [#example]

```typescript
NewRelicCapacitorPlugin.setAttribute({ name: "CapacitorAttribute", value: "123" });
```

## Cordova

### Syntax [#syntax]

```typescript
setAttribute(attributeName: string, value: boolean | number | string): void;
```

### Description [#description]

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

### Parameters [#parameters]

| Parameter       | Type     | Description                           |
| --------------- | -------- | ------------------------------------- |
| `attributeName` | `string` | Required. The name of the attribute.  |
| `value`         | `bool`   | Required. The value of the attribute. |

### Example [#example]

```js
NewRelic.setAttribute(Name: "CordovaAttribute", value: "123"): void;
```

## .NET MAUI

### Syntax [#syntax]

```csharp
SetAttribute(string name, string value) : bool;
SetAttribute(string name, double value) : bool;
SetAttribute(string name, bool value) : bool;
```

### Description [#description]

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

### Parameters [#parameters]

| Parameter | Type                          | Description                           |
| --------- | ----------------------------- | ------------------------------------- |
| `name`    | `string`                      | Required. The name of the attribute.  |
| `value`   | `string`, `double`, or `bool` | Required. The value of the attribute. |

### Example [#example]

```C#
CrossNewRelic.Current.SetAttribute("MAUIBoolAttr", false);
CrossNewRelic.Current.SetAttribute("MAUIStrAttr", "Cat");
CrossNewRelic.Current.SetAttribute("MAUINumAttr", 13.5);
```

## Flutter

### Syntax [#syntax]

```dart
setAttribute (String name, dynamic value) : void;
```

### Description [#description]

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

### Parameters [#parameters]

| Parameter       | Type     | Description                           |
| --------------- | -------- | ------------------------------------- |
| `name`          | `string` | Required. The name of the attribute.  |
| `dynamic value` | `string` | Required. The value of the attribute. |

### Example [#example]

```dart
NewrelicMobile.instance.setAttribute('RNCustomAttrNumber', 37);
```

## React Native

### Syntax [#syntax]

```js
setAttribute(name: string, value: boolean | number | string): void;
```

### Description [#description]

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

### Parameters [#parameters]

| Parameter | Type                          | Description                           |
| --------- | ----------------------------- | ------------------------------------- |
| `name`    | `string`                      | Required. The name of the attribute.  |
| `value`   | `bool`, `number`, or `string` | Required. The value of the attribute. |

### Example [#example]

```js
NewRelic.setAttribute('RNCustomAttrNumber', 37);
```

## Unity

### Syntax [#syntax]

```csharp
setAttribute(string name, string value) : bool;
setAttribute(string name, double value) : bool;
setAttribute(string name, bool value) : bool;
```

### Description [#description]

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

### Parameters [#parameters]

| Parameter | Type                          | Description                           |
| --------- | ----------------------------- | ------------------------------------- |
| `name`    | `string`                      | Required. The name of the attribute.  |
| `value`   | `string`, `double`, or `bool` | Required. The value of the attribute. |

### Example [#example]

```csharp
NewRelicAgent.SetAttribute("UnityBoolCustomAttr", false);
NewRelicAgent.SetAttribute("UnityStringCustomAttr", "Cat");
NewRelicAgent.SetAttribute('UnityCustomAttrNumber', 37);
```

## Unreal Engine

### Syntax [#syntax]

```cpp
setStringAttribute(FString name,FString value) : void;
setDoubleAttribute(FString name,double value):void;
setBooleanAttribute(FString name ,bool value):void;
```

### Description [#description]

Creates a session-level attribute shared by multiple mobile event types. Overwrites its previous value and type each time it is called.

### Parameters [#parameters]

| Parameter | Type                          | Description                           |
| --------- | ----------------------------- | ------------------------------------- |
| `name`    | `string`                      | Required. The name of the attribute.  |
| `value`   | `string`, `double`, or `bool` | Required. The value of the attribute. |

### Example [#example]

```cpp
#include "NewRelicBPLibrary.h"
UNewRelicBPLibrary::setBooleanAttribute("From Unreal",true);
UNewRelicBPLibrary::setDoubleAttribute("Unreal Double", 15.0);
UNewRelicBPLibrary::setStringAttribute("Unreal String","From UnReal");
```

![Screenshot of the Unreal Engine Plugin Create Attribute](https://docs.newrelic.com/images/newrelic_unreal_attribute_example.webp "Unreal Engine Plugin Create Attribute")
