Scripts
The Scripts tool (formerly Custom Code) allows you to register, apply, and manage custom scripts for your Webflow sites. Add inline JavaScript, tracking codes, analytics, or other custom scripts to site headers or footers.
When to use
Use the Scripts tool to:
- Add tracking codes: Implement Google Analytics, Facebook Pixel, or other tracking
- Custom functionality: Add JavaScript for custom behaviors or integrations
- Third-party integrations: Include scripts from external services
Currently, only site-level, inline custom code is supported, and only JavaScript scripts can be applied. To apply page-level scripts, use the Custom DOM element and update the tag to script.
Tool details
Tool name: data_scripts_tool
Available actions
List registered scripts
View all scripts registered for a site that are available to be applied.
Action: list_registered_scripts
Parameters:
Returns: Array of registered scripts with IDs, names, and metadata
Example usage:
List applied scripts
Retrieve scripts currently applied to a site.
Action: list_applied_scripts
Parameters:
Returns: Array of applied scripts with their configuration
Example usage:
Use this to audit which scripts are running on your site before adding new ones.
Add inline site script
Register and apply a new inline script to a site.
Action: add_inline_site_script
Parameters:
Example usage:
Scripts are limited to 2000 characters. For longer scripts, host them externally and use a script tag to include them.
Delete all site scripts
Remove all custom scripts applied to a site by the MCP server.
Action: delete_all_site_scripts
Parameters:
Returns: Confirmation of deletion
Example usage:
This action removes ALL scripts applied through the MCP server. This operation cannot be undone.
Best practices
Place scripts appropriately
Header scripts (location: "header"):
- Critical JavaScript that must load before page content
- Fonts or CSS dependencies
- Scripts that modify the DOM before rendering
Footer scripts (location: "footer", default):
- Analytics and tracking codes
- Non-critical JavaScript
- Third-party widgets
- Social media scripts
Footer placement is generally preferred for better page load performance.
Minify large scripts
Minify your JavaScript to reduce character count and fit within the 2000 character limit. For larger scripts:
- Host externally and include via script tag
- Split into multiple smaller scripts
- Load from a CDN
Version your scripts
Use meaningful version identifiers to track script changes:
v1.0.0- Initial versionv1.1.0- Added featuresv2.0.0- Major changes
This helps with troubleshooting and rollbacks.
Test before publishing
After adding scripts, test your site thoroughly before publishing:
- Check browser console for errors
- Verify tracking codes are firing
- Test on multiple browsers and devices
- Ensure scripts don’t interfere with site functionality
Document script purposes
Use descriptive displayName values that clearly indicate what each script does:
- “Google Analytics 4 Tracking”
- “Facebook Pixel - Purchase Events”
- “Custom Form Validation”
- “Hotjar Heatmap Tracking”
Limitations
- Character limit: Scripts are limited to 2000 characters
- Inline only: Can only add inline scripts, not external file references. To add external scripts, use script tags in the Designer.
- MCP-managed only:
delete_all_site_scriptsonly removes scripts added through the MCP server - Publishing required: Scripts must be published to appear on the live site
- No execution in MCP: Scripts are registered but not executed by the MCP server itself
Security considerations
Important security notes:
- Only add scripts from trusted sources
- Never include sensitive data (API keys, passwords) in scripts
- Validate and sanitize any user input used in scripts
- Be cautious with third-party scripts that can access site data
- Regularly audit and update scripts to patch security vulnerabilities