Function: initializeAnalyticsSdk()

initializeAnalyticsSdk(config): Promise<BootstrapResponse>

Use this method to initialize the Analytics Embedding SDK with the provided configuration. Calling this method clears all event data before initialization. Successful initialization triggers a successEvent, while any failures due to configuration or authorization issues trigger an errorEvent.

Parameters 

config: AnalyticsSdkConfig

The configuration to use for SDK initialization

Returns 

Promise<BootstrapResponse>

A promise that resolves to the result of the initialization.

Usage 

1//JavaScript
2// Importing required modules and libraries from the Tableau Next Embedding SDK
3import {initializeAnalyticsSdk, AnalyticsDashboard, analyticsEventTarget} from '@salesforce/analytics-embedding-sdk';
4
5//Listening to global ERROR event, such as SDK or component initialization failures.
6analyticsEventTarget.addEventListener(EventName.ERROR, (errorEvent) => {		
7	//Error details (such as error code and message) are available in the event object
8    console.log("Received a global error event", errorEvent)				
9});
10
11//Configuration object for initializing the Tableau Next Embedding SDK
12await initializeAnalyticsSdk({                 
13    //The frontdoor URL required for authentication 
14    authCredential: "<%- authCredential %>",	   
15    //The Salesforce org URL that hosts the Analytics component to be embedded.
16    orgUrl: '<%- org-url %>'                    
17});
18
19const analyticsDashboard = new AnalyticsDashboard({
20    //The parent ID or element to render the component in
21    parentIdOrElement: '<%- parent-element %>',
22    //The ID or API name of the component to embed   
23    idOrApiName: '<%- dashboard-id-or-api-name %>'
24});    
25
26//Listening to component specific ERROR event
27analyticsDashboard.addEventListener(EventName.ERROR, (event) => {			
28    // Error details (such as error code and message) are available in the event object
29    console.log("Received error", event);		
30});
31
32//Listening to COMPONENT_LOADED event triggered when the component gets loaded
33analyticsDashboard.addEventListener(EventName.COMPONENT_LOADED, () => {			
34     console.log("Component Loaded");
35});
36
37//Renders the dashboard in the parent HTML element
38analyticsDashboard.render();
1//TypeScript
2// Importing required modules and libraries from the Tableau Next Embedding SDK
3import {
4    AnalyticsDashboard,
5    initializeAnalyticsSdk,
6	analyticsEventTarget,
7    type DashboardProps,
8    type AnalyticsSdkConfig
9} from '@salesforce/analytics-embedding-sdk';
10
11//Listening to global ERROR event, such as SDK or component initialization failures.
12analyticsEventTarget.addEventListener(EventName.ERROR, (errorEvent) => {		
13	//Error details (such as error code and message) are available in the event object
14    console.log("Received a global error event", errorEvent)				
15});
16
17//Configuration object for initializing the Tableau Next Embedding SDK
18const config: AnalyticsSdkConfig = {		
19    //The frontdoor url required for authentication			
20    authCredential: "<%- authCredential %>",	
21    //The Salesforce org URL that hosts the Analytics component to be embedded.		
22    orgUrl: "<%- org-url %>"							
23};
24await initializeAnalyticsSdk(config);
25
26//Defines the properties required for configuring a dashboard component.
27const dashboardProps: DashboardProps = {			
28    //The parent ID or element to render the component i	
29    parentIdOrElement: '<%- parent-element %>',   	
30    //The ID or API name of the component to embed
31    idOrApiName: '<%- dashboard-id-or-api-name %>'  
32};
33
34//A web component for embedding an analytics dashboard
35const analyticsDashboard: AnalyticsDashboard = new AnalyticsDashboard(dashboardProps);    
36
37//Listening to component specific ERROR event
38analyticsDashboard.addEventListener(EventName.ERROR, (event) => {			
39    //Error details (such as error code and message) are available in the event object
40    console.log("Received error", event);		
41});
42
43//Listening to COMPONENT_LOADED event triggered when the component gets loaded
44analyticsDashboard.addEventListener(EventName.COMPONENT_LOADED, () => {			
45     console.log("Component Loaded");
46});
47
48//Renders the dashboard in the parent HTML element
49analyticsDashboard.render();

Multi-org Support 

The SDK supports initializing and embedding components from multiple Salesforce orgs. Use the orgConfigs array to configure multiple orgs:

1// Multi-org initialization
2await initializeAnalyticsSdk({
3    orgConfigs: [
4        {
5            authCredential: "https://org1.salesforce.com/secur/frontdoor.jsp?sid=123...",
6            // Must be Lightning URL
7            orgUrl: "https://org1.lightning.force.com"  
8        },
9        {
10            authCredential: "https://org2.salesforce.com/secur/frontdoor.jsp?sid=123...",
11            // Must be Lightning URL
12            orgUrl: "https://org2.lightning.force.com"  
13        }
14    ]
15});
16
17// When creating components in multi-org scenarios, always specify orgUrl
18const dashboard1 = new AnalyticsDashboard({
19    parentIdOrElement: 'container1',
20    idOrApiName: 'Dashboard1',
21    // Required in multi-org
22    orgUrl: 'https://org1.lightning.force.com'  
23});
24
25const dashboard2 = new AnalyticsDashboard({
26    parentIdOrElement: 'container2',
27    idOrApiName: 'Dashboard2',
28    // Required in multi-org
29    orgUrl: 'https://org2.lightning.force.com'  
30});

Note: The orgUrl parameter must be a Lightning URL (e.g., https://yourorg.lightning.force.com), not the my.salesforce.com domain URL.