The block_analytics plugin is a custom block that allows users to embed Metabase dashboards within Custom Pages. It is designed to enable the integration of analyses while ensuring data security and appropriate user permissions.
- Embeds a Metabase dashboard within a Moodle Custom Page.
- Requires specific permissions to add and view the block.
- Ensures security through Moodle-side and Metabase-side authorization.
- Allows configuration of dashboard settings via the block interface.
- Supports URL parameters for customizing the embedded dashboard.
This plugin requires the local_custompage plugin to function correctly. The Custom Page functionality is not available in standard Moodle. Ensure that local_custompage is installed and configured before using block_analytics.
- Download the plugin package.
- Place the block_analytics folder in your Moodle installation under blocks/.
- Navigate to Site Administration > Plugins > Install plugins to complete the installation.
- Ensure that the local_custompage plugin is installed and enabled.
- Configure the site-wide Metabase settings in Site Administration > Plugins > Blocks > Analytics Block Settings.
After installation, the plugin requires some configuration:
- Metabase Site URL: The base URL of your Metabase instance.
- Metabase Secret Key: The secret key used to generate JWT tokens for embedding dashboards.
This block includes two main permissions that control access:
- block/analytics:addinstance - Allows adding the block to a Custom Page (default: Manager role).
- block/analytics:view - Allows viewing the block's embedded content (default: Manager role).
- The block can only be added to Custom Pages, not courses or dashboards.
- Users must have the appropriate permissions to add or view the block.
- The embedded dashboard requires at least one Audience restriction on the Custom Page.
- The plugin uses JWT authentication to securely embed dashboards.
- The embedded URL is valid for 5 to 10 minutes before expiration.
- The Metabase instance should be configured to expose only the /embed/dashboard/* URLs.
To embed a Metabase dashboard with ID 50, use the following settings:
- Dashboard ID: 50
- Extra URL Parameters: bordered=true&titled=true
A sample JWT generation code snippet:
var jwt = require("jsonwebtoken");
var METABASE_SITE_URL = "https://metabase.example.com";
var METABASE_SECRET_KEY = "your_secret_key";
var payload = {
resource: { dashboard: 50 },
params: {},
exp: Math.round(Date.now() / 1000) + (10 * 60) // 10-minute expiration
};
var token = jwt.sign(payload, METABASE_SECRET_KEY);
var iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token + "#bordered=true&titled=true";