Integrating GoodData into Vue.js is simpler than it appears, even with out native help. Let’s dive in and go over the 4 step course of:
- Putting in Dependencies
- Organising Atmosphere Variables
- Organising the Code Base
- Managing CORS
Notice: For these all for a deeper dive into these integrations, I like to recommend testing Patrik Braborec’s fast overview.
On the finish of this tutorial, it is possible for you to to combine GoodData Visualizations into your Vue.js software. For the needs of this demo, let’s assume that you’ve got a fruit retailer like this:

That is a part of an ongoing collection about totally different front-end frameworks and their integration into GoodData.
Step 1: Set up Dependencies
First issues first, you would wish so as to add a number of 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 just isn’t within the scope of this text, however if you want 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 @sorts/react@^18.2.0 @sorts/react-dom@^18.2.0
Now that’s out of the way in which, let us take a look at the code!
Step 2: Set atmosphere variables
Be sure to 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 /purchasers/vuejs folder. You must take away “template” from the filename to be able to arrange every thing accurately.
For .env, you will want to outline 4 variables:
# GoodData host
VITE_HOSTNAME=
# GoodData workspace id
VITE_WORKSPACE_ID=
# GoodData perception id
VITE_INSIGHT_ID=
For those who open a GoodData dashboard, you’ll find 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 find INSIGHT_ID like this:
https://<HOSTNAME>/dashboards/#/workspace/<WORKSPACE_ID>/<INSIGHT_ID>/edit
For .env.native, you will want just one variable:
# GoodData API token
VITE_GD_API_TOKEN=
Examine Create an API token documentation for extra data.
In case you want 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 wish to create a backend within the type of tigerFactory() in App.vue:
const backend = tigerFactory()
.onHostname(import.meta.env.VITE_HOSTNAME)
.withAuthentication(
new TigerTokenAuthProvider(import.meta.env.VITE_GD_API_TOKEN)
)
After which simply merely feed it with the onMounted() technique:
onMounted(() => {
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 have a with gooddata-chart id and it will render the Visualization!
Right here is a straightforward template:
<template>
<fundamental>
<h1>Vue.js with GoodData</h1>
<div id="gooddata-chart"></div>
</fundamental>
</template>
Now you possibly can simply add styling and you might be set! Only for simplicity, let’s simply go along with a minimal one:
<fashion scoped>
#gooddata-chart {
width: 100%;
top: 400px;
}
</fashion>
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 might be lacking is to handle CORS. That is fairly easy in GoodData:
- Navigate to your GoodData Occasion,
- Go to the settings
- Add allowed origins to the CORS.

Notice: For detailed details about CORS, confer with the official documentation.
For my native improvement, this was http://localhost:5173:

Now simply merely run npm run dev and you need to see one thing like this:

In case the colours of the visualization don’t suit you, you possibly can at all times change them.
Wish to Be taught extra?
If you wish to strive GoodData, try 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 got in your thoughts, attain out to us on our group Slack.