Skip to main content

Overview

The Webflow Browser API is a JavaScript interface exposed via the global wf object on all Webflow sites with Analyze and Optimize enabled. It requires no manual installation and enables you to manage tracking consent, integrate with Consent Management Platforms (CMPs), track experiment variations, and personalize user experiences.
The Browser API is automatically available on sites with Webflow Analyze or Optimize enabled. No installation required.

Download Skill

Add this skill to your AI agent to help with Browser API integration:
https://skills.224ai.au/webflow-browser-api.skill

Key Concepts

Global wf Object

Automatically available on all sites with Analyze or Optimize enabled

wf.ready() Callback

All Browser API calls must be wrapped in this readiness callback

Consent Management

Three methods to manage tracking consent: get, allow, and deny

Custom Attributes

Set visitor attributes for audience targeting (Enterprise only)

API Methods

The Browser API provides the following methods:
MethodDescription
wf.ready(callback)Execute code after the Browser API loads
wf.getUserTrackingChoice()Returns "allow", "deny", or "none"
wf.allowUserTracking(options?)Opt user into tracking
wf.denyUserTracking(options?)Opt user out of tracking
wf.onVariationRecorded(callback)Register a callback for variation events
wf.setAttributes(scope, attributes)Set custom visitor attributes

Basic Usage Example

All Browser API calls must be wrapped in wf.ready():
wf.ready(function() {
  // Check current tracking choice
  const choice = wf.getUserTrackingChoice();
  console.log('Tracking choice:', choice); // "allow", "deny", or "none"
  
  // Allow tracking
  if (choice === "none") {
    wf.allowUserTracking();
  }
});

Tracking Experiment Variations

wf.ready(function() {
  wf.onVariationRecorded(function(data) {
    // Forward to your analytics tool
    console.log('Experiment:', data.experimentId);
    console.log('Variation:', data.variationId);
  });
});
The Browser API integrates seamlessly with popular Consent Management Platforms:
Sync Webflow’s tracking state with OneTrust consent choices:
wf.ready(function() {
  OneTrust.OnConsentChanged(function() {
    const groups = OnetrustActiveGroups;
    if (groups.includes('C0002')) {
      wf.allowUserTracking();
    } else {
      wf.denyUserTracking();
    }
  });
});
Respond to TrustArc consent events:
wf.ready(function() {
  window.addEventListener('trustarc.message', function(e) {
    if (e.detail.consent === 'granted') {
      wf.allowUserTracking();
    } else {
      wf.denyUserTracking();
    }
  });
});

Custom Visitor Attributes

Custom JavaScript attributes via setAttributes() are only available on Enterprise sites.
wf.ready(function() {
  wf.setAttributes('visitor', {
    plan: 'premium',
    industry: 'technology',
    company_size: '50-200'
  });
});

Important Notes

Always wrap all API calls inside wf.ready() to prevent calls before initialization.
  • The Browser API is only available on sites with Webflow Analyze or Optimize enabled
  • Custom JavaScript attributes are Enterprise-only
  • Place scripts in <head> custom code for earliest possible execution
  • Consent choices can be persisted with the persist option

Reference Documentation

The skill includes comprehensive reference documentation:

Getting Started

  • introduction.md — Overview, capabilities, placement options, getting started
  • wf-ready.mdwf.ready() API reference
  • consent-management.md — Consent APIs, CMP integrations (OneTrust, TrustArc), custom consent solutions

Optimize

  • optimize-overview.md — Optimize overview and quickstart
  • variations.md — Variations concept and onVariationRecorded() API reference
  • attributes.md — Custom attributes and setAttributes() API reference

Searching References

The skill includes a Python search script to quickly find relevant documentation:
# List all references with metadata
python scripts/search_references.py --list

# Search by tag (exact match)
python scripts/search_references.py --tag consent

# Search by keyword
python scripts/search_references.py --search tracking

License

MIT License - See the repository for details.

Build docs developers (and LLMs) love