โš™๏ธEmbed SDK

Introduction

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!

Embed SDK - scripts

SDK Key

Create a dedicated token for authentication by following the steps in our Embed SDK Authentication documentation.

Glossary

IDs

  • 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:

Filters

The SDK provides access to Filters, enabling targeted data customization within embeds.

TcTcEmbed

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 DOMIds 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

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:

Parameter
Type
Mandatory
Description

filterId

string

โœ…

The ID of the filter whose value you wish to change

value

object

โœ…

The new filter value

Returns: void

  • When using a filter with multiple selectable values (ex. a checkbox filter), to select all values in this filter, you need to send:

The name of the key (here anyKey) can be anything, only the value __VOID__ matters.

  • When using a filter with one selectable value (ex: dropdown filter), to set all values in this filter, you need to send:

Where columnName is the name of the filtered column in your data.

Example 1: Main Case

Example 2: Select all values of a multiple selector filter

Example 3: Select all values of a single selector filter

insertEmbedById()

Description: Programmatically inserts an embed into the DOM.

Parameters:

Parameter
Type
Mandatory
Description

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:

    • If targetEl isn't an HTMLElement.

Example:

Example with a checkbox filter with multiple values set:

destroy()

Description: Destroy the embed and clean up event subscriptions.

Use case: You must call destroy() before reinserting a new embed into the same container, or when the container is removed from the DOM.

This method ensures that:

  • Event listeners registered via subscribe() or subscribeToAllEvents() are removed

  • The embed instance is destroyed cleanly

Returns: void

Example:

When to use:

Call destroy():

  • Before inserting a new embed into the same container

  • When navigating away from the page or view containing the embed

  • When the embed's container is being removed from the DOM

Note: destroy() automatically unsubscribes from all SDK-level event listeners registered via subscribe() or subscribeToAllEvents().

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

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.

Parameters:

Parameter
Type
mandatory
Description

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 found 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.

Embed

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[]

Use filterIds for scenarios like binding it to a button click or user interaction.

Example:

getFilterIdsAsync()

Description: Retrieves the filter IDs asynchronously. This method guarantees that the filters' configuration is fully loaded before resolving. Parameters: None Returns: Promise<string[]>

Use this method when you need to ensure that the filters' configuration is fully loaded, such as during the initialization phase.

This method is particularly useful for embedding scenarios where the timing of the filters' configuration load is uncertain.

Example:

getFilter()

Description: Retrieves a specific filter by ID.

Parameters:

Parameter
Type
Mandatory
Description

filterId

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

variables

object

โœ…

The extra variables you can use in your Toucan embeds

Returns: void

Example:

downloadPdf()

Description: Renders the document to a PDF and triggers a browser download as soon as it is ready.

Parameters:

Parameter
Type
mandatory
Description

options.locale

'en' | 'fr' | 'jp' | 'es' | 'it'

โŒ

Locale to use for generating the document.

Returns:

  • ๐ŸŸข Success: Promise<void> resolving when the PDF has been downloaded.

  • ๐Ÿ”ด Error:

    • If any call to the rendering service fails.

    • If the document fails to be downloaded.

exportAsPdfBlob()

Description: Renders the document to a PDF and returns a Blob containing the PDF data. This is useful if you want to control where the document is going (ex. send it to your own API, display it in a modal, etc.).

Parameters:

Parameter
Type
mandatory
Description

options.locale

'en' | 'fr' | 'jp' | 'es' | 'it'

โŒ

Locale to use for generating the document.

Returns:

  • ๐ŸŸข Success: Promise<Blob> resolving with the PDF data.

  • ๐Ÿ”ด Error:

    • If any call to the rendering service fails.

    • If the document fails to be downloaded to a Blob.

exportAsPdfPollingUrl()

Description: Renders the document to a PDF and returns a polling API URL that is then used to retrieve the PDF file. An example of a use case might involve sending the URL to your own API and let your server process the document asynchronously while the user can leave the page.

Prefer using exportAsPdfBlob() if possible, use this method only for backend-to-backend communication that require asynchronous processing.

You MUST GET the returned URL with proper Authorization headers; you may reuse the same token you used to initialize the SDK:

You MUST poll the returned URL until the document is ready:

  1. The URL will return a 404 while the document is being generated; then, continue polling the URL.

  2. The URL will return a 200 with the PDF as the body response.

  3. Note: The URL will return a 404 after the document has been retrieved a first time in step 2, as the document is being deleted from the rendering service.

Parameters:

Parameter
Type
mandatory
Description

options.locale

'en' | 'fr' | 'jp' | 'es' | 'it'

โŒ

Locale to use for generating the document.

Returns:

  • ๐ŸŸข Success: Promise<string> resolving with the URL to poll.

  • ๐Ÿ”ด Error:

    • If any call to the rendering service fails.

Event Emitter System

Description: Listens to Toucan events for enhanced interaction within embeds.

Supported charts include:

  • 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

eventName

TcEvent

โœ…

Toucan Event's name

callback

function

โœ…

The token used to identify your user

Callback function returns: EventData

Parameters:

Parameter
Type
Description

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:

Parameter
Type
Description

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:

Parameter
Type
Mandatory
Description

eventName

TcEvent

โœ…

Toucan Event's name

Returns: void

Example:

Filter

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

value

any

โœ…

A value that is available in the Filter values

Returns: void

Example:

Last updated

Was this helpful?