Embed in your product
Content Security Policy
What your page's security policy must allow.
If your page sends a Content Security Policy, it must allow GOAT's embed script, your install's address, and your token endpoint. This page lists what to add, and how to use a nonce.
The embed needs no 'unsafe-inline', no fonts, and no frames.
What to allow
| Directive | Add |
|---|---|
script-src | Your install's address, such as https://analytics.example.com, for the embed script. And a way for the snippet's inline script to run: your page's nonce on it, its hash, or the script moved into a file on your site. |
connect-src | Your install's address, and your token endpoint ('self' if it is on your own site). |
img-src | data:, and the addresses of any pictures the dashboard's authors placed in Image elements. Nothing if the dashboard has none. |
For example, with the token endpoint on your own site and a nonce on both script tags:
Content-Security-Policy: script-src 'self' https://analytics.example.com 'nonce-r4nd0m'; connect-src 'self' https://analytics.example.com; img-src 'self' data:
Use a fresh nonce for each page load.
A connect-src directive replaces the fallback from default-src, so list your own site in it too if your page calls it.
Using a nonce
If your policy allows scripts by nonce, put your page's nonce on both script tags in the snippet, in place of YOUR_NONCE:
<script src="https://analytics.example.com/embed/qc-embed.js" nonce="r4nd0m"></script>
<qc-embed-view base-url="https://analytics.example.com" dashboard-id="dash_abc"></qc-embed-view>
<script nonce="r4nd0m">
/* the rest of the snippet */
</script>
The embed takes its nonce from the script tag that loaded it. Older browsers that cannot build stylesheets in code fall back to <style> elements, which a strict style-src allows only with that nonce. If you mount from code, you can also pass it as the nonce option.
If your page sends no script-src policy at all, remove both nonce attributes. Any script-src policy blocks the snippet's inline script unless it carries the nonce, the policy lists its hash, or the script is moved into a file, as below.
A policy that allows only your own site
A policy of script-src 'self' blocks the snippet's inline script and the embed script from your install. Add your install's address to script-src, and move the snippet's script block into a file on your site:
<script src="https://analytics.example.com/embed/qc-embed.js"></script>
<qc-embed-view base-url="https://analytics.example.com" dashboard-id="dash_abc"></qc-embed-view>
<script src="/my-embed-hook.js"></script>
The file holds the snippet's script block unchanged. It still finds the element directly before it.
Policy reports
On a page that collects policy reports, styled text in a dashboard may file one or two style-src-attr reports for each styled passage. They change nothing on screen.
Common problems
| What you see | What to check |
|---|---|
| The dashboard never loads, and the console shows a blocked script | script-src allows your install's address, and the inline script carries the nonce or is moved into a file. |
| The view says it has no token provider | The inline script was blocked. Check the nonce. |
| The dashboard stays on its loading state, and the console shows a blocked connection | connect-src allows your install's address and your token endpoint. |
| Images in the dashboard are missing | img-src allows their addresses. |
GOAT answers 403 ORIGIN_DENIED | That is not your policy: your install limits which sites may embed. See Settings. |