> This page is for Browser API.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.webflow.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.webflow.com/_mcp/server.

# Set attributes

> Set attributes for the current user or page view

## `wf.setAttributes(scope, attributes)`

Set custom attributes for the current user or page view.

> **Create a custom attribute in Webflow Optimize**
>
> Before setting a custom attribute and sending it to Webflow Optimize, you need to create the attribute in the **Insights > Integrations > Custom JavaScript attributes** section of your site. See [Creating custom attributes in Webflow Optimize](/browser/optimize/attributes#configuring-custom-attributes) for more information.

### Syntax

```typescript
wf.setAttributes(scope: 'user' | 'pageview', attributes: {[attributeName: string]: attributeValue: string})
```

### Parameters

* **scope**: `'user'` | `'pageview'` - The scope of the attributes. You can choose to set attributes for the current user or the current page view.
* **attributes**: `{[attributeName: string]: attributeValue: string}` - An object containing key-value pairs of attributes to set. The attribute name must be less than 40 characters long and may not contain a “=” character

### Example implementation

```javascript
// Call the wf.ready() function to ensure the script is loaded before setting attributes
wf.ready(function() {
  // Set attributes for the current user
  wf.setAttributes('user', {
    userSegment: 'enterprise'
  })
})
```

### Returns

This method doesn't return a value to the client. Instead, it sends the attributes to Webflow Optimize, which records in the user or page view data in the dashboard. See more on [using custom attributes](/browser/optimize/attributes#targeting-visitors-with-custom-attributes) in the Optimize documentation.

### FAQs

#### Can I use boolean and number values for attribute values?

`wf.setAttributes()` attempts to convert values from types like boolean and number into strings for convenience. Don't rely on this conversion and always pass in string values for attributes.

#### Why am I not seeing my attributes in my audience data?

Be sure to create the attribute in the **Insights > Integrations > Custom JavaScript attributes** section of your site before sending custom attributes to Webflow Optimize. See [Creating custom attributes in Webflow Optimize](/browser/optimize/attributes#creating-custom-attributes-in-webflow-optimize) for more information.

> **Enterprise sites only**
>
> This method is only available on enterprise sites.