Every Click to Call widget has a Custom code section where you can paste HTML and JavaScript snippets. The code runs inside a secure sandbox, so it can react to widget events and call its own APIs without putting your visitors or your account at risk.Documentation Index
Fetch the complete documentation index at: https://docs.apifycloud.io/llms.txt
Use this file to discover all available pages before exploring further.
Where to configure it
In the console under Call Studio → Settings → Custom code, two text areas:- Head HTML — injected at the top of the sandbox document. Use for
<script>tags that set up SDKs,<link>tags for CSS, meta tags. - Body end HTML — injected at the bottom. Use for scripts that need the DOM ready or that fire on visibility.
<script> tags execute. Inline
scripts, external scripts (via src), and <link> stylesheets all
work.
The sandbox model
The code you paste runs inside an isolated iframe with a strict sandbox. What the sandbox can do:- Run any JavaScript
- Load external scripts and stylesheets
- Call third-party APIs (analytics, pixels, SDKs) over the network
- Subscribe to widget events
- Emit custom events back to the widget
- Read cookies or
localStorageon the integrator’s domain - Read cookies or
localStorageofapifycloud.io - Access the widget’s DOM or React state
- Call the integrator’s APIs with the user’s credentials
- Navigate the top-level window
- Read or modify the embedding page in any way
The window.c2c API
Inside the sandbox, window.c2c is pre-populated with a small event
bridge to the widget. Same surface as if it were an uninstrumented
page — you just read events and emit events.
Subscribe to events
data object including
context.
Unsubscribe
on returns an unsubscribe function. Call it to stop receiving
events:
window.c2c.off(name, handler) explicitly.
Emit custom events
custom:custom_action.
Read URL context
context object is frozen — you can read but not modify it.
Await ready
The shim dispatches ac2c:ready event on its own window as soon as
the bridge is ready:
window.c2c is defined synchronously before your scripts
execute, so you rarely need to wait.
Common examples
GA4 — track calls as events
Meta Pixel — fire Lead on call start
Google Tag Manager — push events to the dataLayer
Custom events — emit your own signals
Usewindow.c2c.emit to surface custom signals from the sandbox. They
reach the parent page as postMessage and integrations as
custom:<name>.
Conditional tracking based on URL context
Thecontext object is available on every event and on
window.c2c.context. Use it to only fire a tag for specific visitor
cohorts.
Limitations to keep in mind
No access to cookies on your domain
No access to cookies on your domain
No direct access to parent page
No direct access to parent page
You can’t read URL parameters from the embedding page, inspect its
DOM, or modify it. Pass anything you need via
URL context when
loading the widget.
Synchronous postMessage only
Synchronous postMessage only
Communication with the widget is event-based and one-way per direction
(sandbox → widget and widget → sandbox). There’s no request/response
RPC pattern built in.
No access to call audio
No access to call audio
WebRTC audio streams live in the widget, not in the sandbox. Custom
code cannot tap into mic input or call audio.
Debugging custom code
The sandbox is a normal iframe — open your browser devtools and select it in the iframe dropdown to inspect its console, network, and sources. Errors in your custom code appear there, not in the main page console. If a script fails silently:- Check the Network tab for blocked requests (CSP on your side, ad blockers, mixed-content warnings).
- Check the Console for thrown exceptions inside handlers.
- Verify the iframe’s sandbox attributes are what you expect — by
design they should be
allow-scriptsonly.
What’s next
Events
The full catalogue of events you can subscribe to.
Security
Why the sandbox is shaped this way and what it protects against.