Custom Scripts
Add custom JavaScript snippets to your documentation site for analytics, widgets, or any custom functionality not covered by built-in integrations.
Inject custom JavaScript into your published documentation site. Use custom scripts for analytics providers not covered by built-in integrations, consent banners, A/B testing tools, or any custom functionality.
Prerequisites
-
A documentation project with publishing access
-
A
.jsor.mjsscript file added to your documentation project
Configure custom scripts from the Editor
You can manage custom scripts directly from the Editor without editing JSON.
Open Site Config
In the Editor, click Site Config in the top toolbar.
Navigate to Custom Scripts
Select Custom Scripts from the left sidebar.
Add a script
Click Add Script and select the script file from your project. Only .js and .mjs files are available for selection.
Publish
Click Publish to deploy the script to your live site. Custom script changes appear in the Changes panel alongside content edits.
Configure custom scripts via documentation.json
If you manage configuration in version control, add scripts directly to documentation.json:
{
"scripts": [
{ "src": "scripts/consent-banner.js" },
{ "src": "scripts/custom-tracking.mjs" }
]
}
Each entry in the scripts array has a single property:
| Property | Type | Required | Description |
|---|---|---|---|
src | string | Yes | Relative file path to a .js or .mjs file in your project |
Script file requirements
- Files must use a
.jsor.mjsextension. - Paths are relative to your project root (for example,
scripts/analytics.js). - Maximum file size is 5 MB.
- The file must exist in your documentation project before you can reference it.
Script paths must be relative — no leading /, ./, or ../. Path traversal patterns are rejected for security.
Security considerations
Custom scripts execute in your readers' browsers with full page access.
-
Only add scripts you trust and have reviewed.
-
Audit script contents periodically, especially if they interact with user data or external services.
Malicious or misconfigured scripts can break your documentation site or compromise reader privacy. Test scripts in a staging environment before publishing to production.
Troubleshooting
Script not loading: Verify the file exists in your project and uses a .js or .mjs extension. Check the browser developer console for syntax errors.
Script conflicts: If multiple scripts interfere with each other, try reordering them in the scripts array. Scripts load in the order they appear in the configuration.
Changes not visible: Custom script changes require publishing. Check that you have published after making edits.
What's next
-
Analytics and chat integrations — zero-code setup for popular analytics and chat tools
-
Site configuration reference — full
documentation.jsonreference
Last updated 1 day ago
Built with Documentation.AI