For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Resources
Get started
ReferenceChangelog
ReferenceChangelog
  • Browser API
    • wf.ready()
  • Consent Management
    • Get consent status
    • Allow user tracking
    • Deny user tracking
  • Optimize
    • Quickstart
    • Variations
    • Custom attributes
      • Get attributes
      • Get all attributes
      • Set attributes
      • Delete attributes
      • Delete all attributes
  • Custom Goals
    • On-site conversions
    • Off-site conversions
  • Data Exports
    • Data destinations
    • Data schema
  • Additional Resources
    • Support Documentation
LogoLogo
Resources
Get started
On this page
  • wf.setAttributes(scope, attributes)
  • Syntax
  • Parameters
  • Example implementation
  • Returns
  • FAQs
OptimizeCustom attributes

Set attributes

Was this page helpful?
Previous

Delete attributes

Next
Built with

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

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.