> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://knowledge.clym.io/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Clym Widget API

The **Clym Widget API** is accessible through the global `window.Clym` object within the **top window context**. This allows developers to programmatically interact with the Clym Widget embedded on a website.

### Available Functions
* **Clym.showWidget():** This triggers the widget to open up regardless of Geographical settings.
* **Clym.hideWidget():** This closes the widget.
* **Clym.forgetUser():** The function triggers the "Forget Me" functionality, clears all Clym related preferences, consent from the browser and reloads the page.
* **await Clym.getWidgetData():** Returns with all the static widget data, some of the relevant fields:
```
- processing_categories: Array of the active processing categories (eg: Analytics, Advertising...)
- embedded_tags: Array of the Clym Widget services (eg: Google Analytics, Hotjar...)
- embedded_content: Array of the embedded content services (eg: Youtube iframe)
- policies: Array of available policies
```

* **await Clym.isTagAllowed(serviceName):** Returns a boolean value if the service is accepted or not. Case sensitive.
* **await Clym.getConsent():** Returns with all the consent related fields
```
- receipt_id: The receipt Id we generated for the user / if null no consent choice was made
- gpp_string: IAB GPP string
- has_decision: If the user explicitly made a choice about cookie consent preferences
- current
	- embedded_tags: An object where the key is the embedded tag id (service id) and the value if it's accepted or not
	- embedded_content: An object where the key is the embedded content id (embedded content id) and the value if it's accepted or not
- pending: Holds the changes that are not saved yet
- created_at: Timestamp of when the consent was created
```

* **Clym.acceptAll():** Triggers the "Accept all" functionality, accepting all services
* **Clym.rejectAll():** Triggers the "Reject all" functionality, rejecting everything and possibly refreshing the page
* **Clym.on(EVENT, callback):** Creates an event subscriber
```
// Example usage:
Clym.on(Clym.EVENT.CONSENT_CHANGE, async function() {
	const MyServiceAllowed = await Clym.isTagAllowed('Your Service Name');
	if (MyServiceAllowed) {
		// We have consent for this service
	} else {
		// We don't have consent for this service
	}
});
```

### Clym callback
If you want to set a listener before the Clym object is accessible you can use a callback function that will fire once the Clym widget is ready:
```
window._clymInit = window._clymInit || []; 
window._clymInit.push(['ready', (Clym) => {
        Clym.on(Clym.EVENT.CONSENT_CHANGE, async function(data) {
        const consentObject = await Clym.getConsent();
});
}]);
```

If you encounter any challenges, please reach out to us at [support@clym.io](mailto:support@clym.io).