Thursday, August 7, 2025
HomeBusiness IntelligenceFrontend Integration Sequence: SvelteKit | GoodData

Frontend Integration Sequence: SvelteKit | GoodData


Integrating GoodData into SvelteKit is less complicated than it appears, even with out native assist. Let’s dive in and go over the 4 step course of:

  • Putting in Dependencies
  • Establishing Atmosphere Variables
  • Establishing the Code Base
  • Managing CORS

Word: For these enthusiastic about a deeper dive into these integrations, I like to recommend trying out Patrik Braborec’s fast overview.

On the finish of this tutorial, it is possible for you to to combine GoodData Visualizations into your SvelteKit utility. For the needs of this demo, let’s assume that you’ve a fruit retailer like this:

Fruit Store placeholder with the embedded GoodData visualization
Fruit Retailer placeholder with the embedded GoodData visualization

That is a part of an ongoing sequence about completely different front-end frameworks and their integration into GoodData, final one was about Angular.

Step 1: Set up Dependencies

First issues first, you would want so as to add just a few issues to your dependencies.

npm set up --save react@^18.2.0 react-dom@^18.2.0 @gooddata/sdk-ui-all @gooddata/sdk-backend-tiger

Particulars concerning the GoodData.UI SDK isn’t within the scope of this text, however if you need to be taught extra about it, right here is the GoodData.UI structure overview.

And only for completeness listed here are TypeScript dependencies:

npm set up --save-dev @varieties/react@^18.2.0 @varieties/react-dom@^18.2.0

Now that’s out of the best way, let us take a look at the code!

Step 2: Set surroundings variables

Ensure you have your .env and .env.native information with appropriate values. After you clone the repository, you will notice a .env.native.template file within the /shoppers/sveltekit folder. You must take away “template” from the filename with a view to arrange every part appropriately.

For .env, you will have to outline three variables:

# GoodData host
VITE_HOSTNAME=

# GoodData workspace id
VITE_WORKSPACE_ID=

# GoodData perception id
VITE_INSIGHT_ID=

When you open a GoodData dashboard, you will discover the HOSTNAME and WORKSPACE_ID within the URL:

https://<HOSTNAME>/dashboards/#/workspace/<WORKSPACE_ID>/dashboard/<DASHBOARD_ID>

For INSIGHT_ID you’ll have to navigate to the Analyze tab after which navigate to one of many visualizations. There you’ll discover INSIGHT_ID like this:

https://<HOSTNAME>/dashboards/#/workspace/<WORKSPACE_ID>/<INSIGHT_ID>/edit

For .env.native, you will have just one variable:

# GoodData API token
VITE_GD_API_TOKEN=

Examine Create an API token documentation for extra data.

In case you wish to use this in your manufacturing, we extremely advocate to make use of OAuth, as you would probably leak your API_TOKEN.

Step 3: Arrange the Code

To rapidly embed GoodData Visualizations, you would want to create a backend within the type of tigerFactory() in your chart element:

const backend = tigerFactory()
    .onHostname(import.meta.env.VITE_HOSTNAME)
    .withAuthentication(
        new TigerTokenAuthProvider(import.meta.env.VITE_GD_API_TOKEN)
);

Then simply merely feed it with the onMounted() technique:

onMount(async () => {
    const { InsightView } = await import('@gooddata/sdk-ui-ext');
    const node = doc.getElementById('gooddata-chart');
    const props = {
        workspace: import.meta.env.VITE_WORKSPACE_ID,
        perception: import.meta.env.VITE_INSIGHT_ID,
        backend
};

    if (node) {
        ReactDOM.render(React.createElement(InsightView, props), node);

    }
});

Now, you possibly can merely create <GoodDataChart> and it’ll render the Visualization.

Here’s a quite simple template:

<h1>SvelteKit with GoodData</h1>
<GoodDataChart/>

Now you possibly can simply add styling and you’re set! Only for simplicity, let’s simply go along with a minimal one:

#gooddata-chart {
 width: 100%;
 peak: 400px;
}

Here’s a GitHub repo you possibly can simply begin with!

Step 4: Handle CORS

And that’s all for code! Fairly easy, is not it? 😉

Now the one factor that may be lacking is to maintain CORS. That is fairly easy in GoodData:

  1. Navigate to your GoodData Occasion,
  2. Go to the settings
  3. Add allowed origins to the CORS.
CORS example setting in the GoodData web UI.
CORS instance setting within the GoodData internet UI.

Word: For detailed details about CORS, discuss with the official documentation.

For my native growth, this was http://localhost:5173:

CORS settings. Note, that there is http://localhost:4200 from the Vue.js article.
CORS settings. Word, that there’s http://localhost:4200 from the Vue.js article.

Now simply merely run npm run dev and it’s best to see one thing like this:

Fruit Store placeholder with the embedded GoodData visualization
Fruit Retailer placeholder with the embedded GoodData visualization

In case the colours of the visualization don’t suit you, you possibly can all the time change them.

Wish to Be taught extra?

If you wish to strive GoodData, take a look at our free trial – it really works nicely with the GitHub repo! If you need to debate embedding, AI, dashboard plugins or no matter you’ve in your thoughts, attain out to us on our neighborhood Slack.

RELATED ARTICLES

Most Popular

Recent Comments