set_custom_code
Set site-wide custom code: head goes before and body before on every page, on every layout. It is saved as a draft and goes live with the next publish_site (on a live-mode site the dashboard publishes only the code). It never runs in the editor. Up to 20,000 characters per box, stored as sent; warnings flags likely mistakes (unclosed , // tags, a canonical or robots tag, GA4 already connected) without rejecting. Send only the boxes you change; "" clears a box. runOn ('live' = live site only, default; 'live-and-preview' = also in the editor's preview) applies at once — agents limited to drafts can't set it. Use for tag managers (GTM), Clarity, ads pixels, chat widgets and verification tags. For plain GA4, Plausible, Fathom or Umami prefer set_analytics_provider.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| body | No | Code for before </body> on every page. "" clears it. | |
| head | No | Code for before </head> on every page. "" clears it. | |
| site | Yes | Site slug, e.g. acme-studio | |
| runOn | No | Where it runs: 'live' (live site only) or 'live-and-preview'. Applies at once. | |
| context | Yes | One sentence: why you are calling this tool and what you are trying to accomplish. Stored on the site's activity log and visible to everyone on the site — never put secrets or personal data here. | |
| guestToken | No | Guest token from start_site. Send it on every call until claim_site. Omit when this chat is already signed in to Dotsy. |