__tcfapi
__tcfapi is a standard JavaScript function defined by the IAB Europe Transparency and Consent Framework (TCF) that lets a website's scripts communicate with the consent management platform (CMP) on a page. Through this function, developers can retrieve a user's consent choices or be notified when those choices change. It is a technical building block that supports TCF-based consent workflows but does not by itself determine whether any given use of cookies or data is lawful.
__tcfapi is the client-side JavaScript function specified by the IAB Europe Transparency and Consent Framework (TCF) v2.x CMP API for interacting with a CMP in the browser. It follows the general form __tcfapi(command, version, callback, parameter), where the command (for example, retrieving TC data or registering an event listener) invokes CMP behavior and the callback receives the result. Scripts may call __tcfapi before the full CMP script has loaded because early invocations are queued (via a stub) and executed once the CMP is initialized. The function surfaces TCF signals such as the consent string and event states, enabling vendors and third-party scripts to read consent status or listen for consent changes. Note that __tcfapi is a technical interface within the TCF's opt-in-oriented, EU/ePrivacy- and GDPR-facing model; its availability and correct behavior depend on CMP implementation, and its presence does not guarantee that consent collected is valid or that any downstream data processing is compliant. Requirements and applicable frameworks differ outside the EU (for example, US state privacy regimes that rely on opt-out mechanisms), which are out of scope for this function.
Why it matters
The __tcfapi function is the practical bridge between a website's tracking scripts and the consent choices a user has made through a TCF-based consent management platform (CMP). Without a reliable interface of this kind, third-party scripts and vendors would have no standardized way to check whether a user has consented before firing cookies, pixels, or other data-collection technologies. For teams that have adopted the IAB Europe Transparency and Consent Framework, __tcfapi is therefore central to how consent signals actually flow across a page.
Because __tcfapi surfaces the TCF consent string and event states, it becomes the technical point at which a compliance intention is either honored or missed. If a script reads consent incorrectly, ignores it, or fires before consent is available, the result can be data processing that the user did not agree to, a gap that carries risk in EU jurisdictions governed by the ePrivacy Directive's national implementations and the GDPR. It is important to stress, however, that the presence and correct operation of __tcfapi does not by itself make any use of cookies lawful. The function communicates consent status; it does not decide whether the consent collected was freely given, specific, informed, and unambiguous, nor whether any downstream processing meets its legal basis.
Teams should also be careful not to treat the TCF and its API as a universal solution. The framework and __tcfapi are oriented toward an opt-in model aligned with EU requirements, and their behavior depends heavily on how the underlying CMP is implemented. Different jurisdictions, for example, US state privacy regimes that generally rely on opt-out mechanisms, operate under different rules and are outside the scope of this function.
Who it's relevant to
Inside __tcfapi
Common questions
Answers to the questions practitioners most commonly ask about __tcfapi.

