Set attributes
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 for more information.
Syntax
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
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 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 for more information.
Enterprise sites only
This method is only available on enterprise sites.