โ๏ธEmbed SDK
Last updated
Last updated
The Embed SDK enables deeper interaction between your application and Toucan embeds, providing a seamless user experience with complete control over what appears in your embedded content.
To get started, simply navigate to Admin Area > Embed Manager > Embed Settings and copy the provided embed SDK script into your application. Youโre all set to begin customizing!
Create a dedicated token for authentication by following the steps in our Embed SDK Authentication documentation.
embedId: This unique identifier is used in each embed script.
DOMId: A combination of embedId
and a random hash, allowing you to integrate the same embed multiple times on a single page.
Example:
The SDK provides access to Filters, enabling targeted data customization within embeds.
When you include the embed script, it automatically attaches the TcTcEmbed
object to window
, ready for instantiation. Use the following code to initialize:
getAll()
Description: Returns an array of all embedded HTML elements on the page.
Parameters: None
Returns: HTMLElement[]
Example:
embedDOMIds()
Description: Returns an array of DOMId
s for all embeds.
Hint: embedId
is not the same as DOMId
and helps avoid integration issues when using the same embed multiple times on the same page.
Parameters: None
Returns: string[]
Example:
setExtraVariablesForAllEmbeds()
Description: Sets external context variables for all embeds.
Parameters:
Parameter | Type | Mandatory | Description |
---|---|---|---|
| object | โ | Variables that can be used in the embed content config |
Returns: void
Example:
setFilterValueForAllEmbeds()
Description: Sets a specific filter value for all embeds.
Parameters:
Parameter | Type | Mandatory | Description |
---|---|---|---|
| string | โ | The ID of the filter whose value you wish to change |
| object | โ | The new filter value |
Returns: void
Example:
insertEmbedById()
Description: Programmatically inserts an embed into the DOM.
Important
Requires an authentication token (see Embed SDK Authentication)
Parameters:
Parameter | Type | Mandatory | Description |
---|---|---|---|
| string | โ | The ID of the embed you want to insert |
| HTMLElement | โ | The container in which you want to insert your embed |
| string | โ | The token used to identify your user |
| Record<string, any> | โ | The initial values of your filters |
| boolean | โ | To display or hide the additional panel |
| boolean | โ | To display or hide the storyโs header |
| boolean | โ | To force display of compact mode if value is |
| string | โ | To get the staging version of the application if the value is |
| Record<string, any> | โ | The extra variables you can use in your Toucan embeds |
Returns:
Success: Promise<Embed>
Error:
when targetEl
isn't an HTMLElement
Example:
get()
Description: Gets an embed instance using either DOMId
or embedId
.
Using DOMId instead of embedId can be useful if you use the same embed several times on the same page.
Parameters:
Parameter | Type | mandatory | Description |
---|---|---|---|
| string | โ | The ID or DOMId of the embed you want to insert |
| number | โ | The maximum waiting time in milliseconds before stopping the search for an embed in the DOM (default: 2000ms) |
Returns: Promise<Embed>
Example:
sendPDFReport()
Description: Sends a PDF report synchronously for a targeted application to a list of users.
Enables synchronous sending of a PDF report for a specific application to a list of recipients. Each recipient is represented as an object containing a token and optional variables. Tokens are used to directly access user context and permissions, including their email (in the username
field), groups, and any other attributes needed to ensure the correct PDF report is sent.
If you don't know what it is, click here for more information.
Important
Requires an authentication token (see Embed SDK Authentication)
Parameters:
Parameter | Type | mandatory | Description |
---|---|---|---|
| string | โ | PDF Report's Small App URL
Example: if your small app is accessible with the URL |
| string | โ | The token used to identify your user |
| Record<string, any> | โ | Override global variables for specific users |
reportId | string | โ | Report ID. Can be find in the URL of a given PDF report |
| Record<string, any> | โ | Filters or extraVariables used into the PDF Report |
Returns:
Success: Promise
Error:
if any email failed to reach its user.
All recipients will receive a PDF report for shop A, except the third user, who will receive a report customized for shop B.
refreshDataQueries()
Description: Refreshes the data in a given embed.
Parameters: None
Returns: void
Example:
filterIds()
Description: Retrieves all filter IDs for a given embed.
Parameters: None
Returns: string[]
Example:
getFilter()
Description: Retrieves a specific filter by ID.
Parameters:
Parameter | Type | Mandatory | Description |
---|---|---|---|
| string | โ | The ID of the filter |
Returns: Filter
Example:
setExtraVariables()
Description: Sets additional variables from external context for a given embed.
Parameters:
Parameter | Type | mandatory | Description |
---|---|---|---|
| object | โ | The extra variables you can use in your Toucan embeds |
Returns: void
Example:
Description: Listens to Toucan events for enhanced interaction within embeds. Supported charts include:
Important
Circularchart
Leaderboard
Linechart
Barchart
Barlinechart
Heatmap
Mapchart
Bulletchart
Stackedbarchart
subscribe
Description: Allows you to listen to Toucan Events. The following events are available:
Events:
chart:selection
: Triggered when a user selects an element.
chart:drill
: Triggered when a user interacts with a drillable element.
Parameters:
Parameter | Type | Mandatory | Description |
---|---|---|---|
| TcEvent | โ | Toucan Event's name |
| function | โ | The token used to identify your user |
Callback function returns: EventData
Parameters:
Parameter | Type | Description |
---|---|---|
| string | The corresponding user interaction with the chart. Possible values are: |
| Record<string, any> | The corresponding data row to the user selection |
| string | The corresponding value in the column used for the label |
| string | Chart type selection (e.g: โzoneโ for a Mapchart, โbarโ for a Leaderboard, โฆ) |
Context:
Parameter | Type | Description |
---|---|---|
| string | Chart's name |
| string | Embed Id |
| string | Story / Tile / Dashboard id |
| number | Chartโs index position inside an embedded story |
| Object | |
| Record<string, any> | Childrenโs data |
| string | Always equals "drill". |
chart:selection
chart:drill
unsubscribe
Description: Destroy listeners to Toucan events.
Parameters:
Parameter | Type | Mandatory | Description |
---|---|---|---|
| TcEvent | โ | Toucan Event's name |
Returns: void
Example:
Description: A Filter
is an interface element used to adjust the data in visualizations, with values based on a specific column in the dataset.
values()
Description: Return all data row values for a given Filter
Parameters: None
Returns: Record<string, any>[]
Example:
currentValue()
Description: Return the current value for a given Filter
Parameters: None
Returns: Record<string, any>[]
Example:
setValue()
Description: Set the current value for a given Filter
Parameters:
Parameter | Type | Mandatory | Description |
---|---|---|---|
| any | โ | A value that is available in the Filter values |
Returns: void
Example:
Only supported on Mapcharts