⚙️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:
variables
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:
filterId
string
✅
The ID of the filter whose value you wish to change
value
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:
embedId
string
✅
The ID of the embed you want to insert
targetEl
HTMLElement
✅
The container in which you want to insert your embed
parameters.token
string
❌
The token used to identify your user
parameters.filters
Record<string, any>
❌
The initial values of your filters
parameters.panel
boolean
❌
To display or hide the additional panel
parameters.header
boolean
❌
To display or hide the story’s header
parameters.compact
boolean
❌
To force display of compact mode if value is true
parameters.stage
string
❌
To get the staging version of the application if the value is staging
parameters.variables.extra
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:
embedId
or DOMId
string
✅
The ID or DOMId of the embed you want to insert
maxWait
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:
smallAppUrlPart
string
✅
PDF Report's Small App URL
Example: if your small app is accessible with the URL https://acme.toucantoco.com/my-app
, then use my-app
users[].token
string
✅
The token used to identify your user
users[].variables
Record<string, any>
❌
Override global variables for specific users
reportId
string
✅
Report ID. Can be find in the URL of a given PDF report
variables
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:
filterId
string
✅
The ID of the filter
Returns: Filter
Example:
setExtraVariables()
Description: Sets additional variables from external context for a given embed.
Parameters:
variables
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:
eventName
TcEvent
✅
Toucan Event's name
callback
function
✅
The token used to identify your user
Callback function returns: EventData
Parameters:
clickType
string
The corresponding user interaction with the chart. Possible values are: click
and dblclick
⚠️ Only supported on Mapcharts
dataRow
Record<string, any>
The corresponding data row to the user selection
dataLabel
string
The corresponding value in the column used for the label
type
string
Chart type selection (e.g: ‘zone’ for a Mapchart, ‘bar’ for a Leaderboard, …)
Context:
chartType
string
Chart's name
embedId
string
Embed Id
storyId
string
Story / Tile / Dashboard id
chartIndex
number
Chart’s index position inside an embedded story
drillInfo
Object
children
Record<string, any>
Children’s data
type
string
Always equals "drill".
chart:selection
chart:drill
unsubscribe
Description: Destroy listeners to Toucan events.
Parameters:
eventName
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:
value
any
✅
A value that is available in the Filter values
Returns: void
Example: