Browser API

Introduction to the Webflow Browser API

The Browser API lets you control Webflow Analyze and Optimize features directly from your site’s JavaScript. Use it to manage consent, track experiments, and personalize user experiences.

What you can do with the Browser API

Getting started

1

Choose where to add your code

You can use the Browser API by adding JavaScript in one of two ways:

  • Directly in your site
    Add a script before the closing </head> tag using Webflow’s custom code settings.
    Best for simple use cases.

  • With Google Tag Manager (or similar)
    Add a script as a custom tag.
    Recommended for advanced tracking or integrations.

2

Wait for the API to be ready

Wrap your code in wf.ready() to ensure the API has loaded before you call any methods:

1wf.ready(function() {
2 // Your code here
3});
3

Start building

Once inside wf.ready(), you can call any Browser API methods to manage consent, track variations, or set custom attributes.

1// Call wf.ready() to ensure the Browser API is available
2wf.ready(function() {
3 // Retrieve variations
4 wf.onVariationRecorded(function(result){
5 // Do something with the result
6 console.log(result);
7 });
8 // Set custom attributes
9 wf.setAttributes("user",{
10 userSegment: 'enterprise',
11 userRole: 'technicalBuyer'
12 });
13});

FAQs

The Browser API is a JavaScript API that allows you to interact with Webflow features directly in the browser. It provides methods to retrieve Optimize variations, set custom attributes, and handle other Webflow features.

The Browser API is automatically included on all Webflow sites with Analyze and Optimize enabled, and handles loading the necessary code in an optimized way to minimize impact on page performance.

The Browser API is available through the global wf object in your browser. You can access the API by adding a script using custom code on your sites and pages or through external services that load scripts on your site like Google Tag Manager.

The API can be called from any JavaScript code running on your site.