To compose an embeddable URL, generate the signed payload on the server side so your API key is never exposed to the browser. Below is a Node.js example that creates the data and signature for an embeddable URL. For more examples, see the Tractorscope snippets GitHub repo.
const { createHmac } = require("crypto");
const key = 'Your Tractorscope API Key';
// the dashboard you want to embed
const dashboard = 'dsh_01GRS8C4BVZ8X9N7E86Z82DQG9'
const expiresAtUtcUnix = moment().utc().add(10, "second").unix();
// compose the data object with filters and dashboard
const data = encodeURIComponent(
JSON.stringify({
dashboard,
filters: {
"Date Range": "last_month",
"Aggregation": "day",
"ClientId": "YourClientId",
// more filters here
},
expiresAtUtcUnix, // this is optional, makes the url expire, that way someone can't just get the iframe src and share it
})
);
// create the encrypted signature
const signature = createHmac("sha256", key).update(data).digest("hex");
// compose the embed url
const embedUrl = `https://app.tractorscope.com/embed/dashboard/${dashboard}?data=${data}&signature=${signature}`const { createHmac } = require("crypto");
const key = 'Your Tractorscope API Key';
// the dashboard you want to embed
const dashboard = 'dsh_01GRS8C4BVZ8X9N7E86Z82DQG9'
const expiresAtUtcUnix = moment().utc().add(10, "second").unix();
// compose the data object with filters and dashboard
const data = encodeURIComponent(
JSON.stringify({
dashboard,
filters: {
"Date Range": "last_month",
"Aggregation": "day",
"ClientId": "YourClientId",
// more filters here
},
expiresAtUtcUnix, // this is optional, makes the url expire, that way someone can't just get the iframe src and share it
})
);
// create the encrypted signature
const signature = createHmac("sha256", key).update(data).digest("hex");
// compose the embed url
const embedUrl = `https://app.tractorscope.com/embed/dashboard/${dashboard}?data=${data}&signature=${signature}`FAQ
Should I generate the embed URL on the client or the server?
Generate the signed payload on the server. Your Tractorscope API key should never be exposed in browser code, mobile apps, or other public clients.
Can I embed a chart instead of a full dashboard?
Yes. The signed payload can target either a dashboard or a chart depending on the embed flow you are using.
Can I pass filters in the signed payload?
Yes. Filters are the standard way to scope an embedded dashboard or chart to a tenant, customer, date range, aggregation level, or other viewer-specific values.
Can an embed expire?
Yes. Add
expiresAtUtcUnix
to the signed payload to make the embed URL expire after a specific time.