Skip to content

JavaScript API

JavaScript API

In Auto mode you rarely need this page. Use it when running Manual mode, when wiring up your own “Cookie settings” link, or when reacting to consent changes in your own code.

Manual initialization

Set the integration mode to Manual in the backoffice, then add the init script to your layout where you want it:

<script type="module">
import { initFlowcourierConsent } from '/fc-cookie-consent/flowcourier.esm.js';
initFlowcourierConsent({
apiUrl: '/fc-cookie-consent/api',
language: 'en-US',
autoInit: true
});
</script>

language should match the culture of the current page — in a Razor layout, pass Umbraco’s current culture instead of a hard-coded value.

window.FlowcourierConsent

After initialization the public API is available on window.FlowcourierConsent:

MethodDescription
show()Show the consent banner
hide()Hide the consent banner
showPreferences()Open the preferences modal — use this for footer “Cookie settings” links
hidePreferences()Close the preferences modal
getState()Returns the current consent state
isCategoryAccepted(category)true if the visitor accepted the given category, e.g. 'analytics'
acceptAll()Programmatically accept all categories
rejectAll()Programmatically reject all non-necessary categories
configThe loaded configuration object

Examples

A footer link to reopen preferences (required by GDPR — withdrawing consent must be as easy as giving it):

<a href="#" onclick="window.FlowcourierConsent.showPreferences(); return false;">
Cookie settings
</a>

Conditionally run your own code based on consent:

if (window.FlowcourierConsent?.isCategoryAccepted('analytics')) {
// load something analytics-related
}

REST API

For headless setups, the same configuration that drives the banner is available over HTTP:

EndpointMethodDescription
/fc-cookie-consent/api/configGETBanner configuration (categories, UI, texts)
/fc-cookie-consent/api/languagesGETAvailable languages
/fc-cookie-consent/api/statsPOSTRecord a consent decision
/fc-cookie-consent/api/stats/summaryGETAggregated consent statistics
/fc-cookie-consent/api/pingGETHealth check

CORS is enabled by default; restrict allowed origins (and optionally require an API key) under Settings → API.