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

1wf.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

1// Call the wf.ready() function to ensure the script is loaded before setting attributes
2wf.ready(function() {
3 // Set attributes for the current user
4 wf.setAttributes('user', {
5 userSegment: 'enterprise'
6 })
7})

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

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.

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.

Built with