Introduction

The Browser API provides JavaScript methods to interact with Webflow features directly in a visitor’s browser. This API is automatically available through the global wf namespace on all Webflow sites.

Current features

Currently, the Browser API only supports Webflow Optimize. The Browser API will continue to expand with new features and capabilities. Stay tuned for updates.

Webflow Optimize

The Browser API provides methods to integrate with Webflow Optimize. You can use Optimize-specific methods to track variations and personalize experiences. See the Webflow Optimize documentation for more information.

Getting started

1

Decide where to add your code

You can add code to interact with the Browser API in one of two ways:

  1. Add code directly to your site

    • Place a script in before the closing </head> tag of your site using Webflow’s custom code feature
    • This is the simplest approach for basic implementations
  2. Use Google Tag Manager or a similar tool

    • Add a script when configuring a custom tag
    • Recommended for more complex implementations or when using other tracking tools
2

Check if the Browser API is ready

The Browser API is available through the global wf namespace. The API includes a definition for wf.ready(), a function that enables you to register callbacks to trigger as soon as the Browser API becomes available to call.

Before using any API methods, you should wrap your code in wf.ready() to ensure the Browser API has fully loaded and initialized. This prevents errors that could occur if you try to call API methods before they’re available.

For example:

1// Call wf.ready() to ensure the Browser API is available
2wf.ready(function() {
3// Your code here
4});
No installation required
The Browser API is automatically included on all Webflow sites and handles loading the necessary code in an optimized way to minimize impact on page performance.
3

Add callbacks to your code

Now you can start adding callbacks inside of wf.ready(). Currently, the Browser API offers methods to interact with Webflow Optimize. See the Webflow Optimize API documentation for more information.

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

Was this page helpful?
Built with