Metricboard howtos

Articles with examples on specific topics; to help you get started quickly.

Topics

How can I provision and embed separate dashboards for multiple users?

This howto describes a common scenario: you have an application with multiple separate users / customers and you want to offer a generic dashboard to each user which the specific data of that user.

This howto assumes the following:

  • Each user has a separate account in your application but will generate the same set of metrics
  • The dashboard should be embedded into the application itself
  • Users see a dashboard created by you

Note: this howto is not suited if your users should be able to modify and/or create their own dashboard.

Create a data feed for each separate user (optional)

Next we will create a feed for each user. This step is only necessary if your users have access to the application source (i.e they host the application themselfs) or if you want to customize feeds.

The feed can be automatically created from your backend; for example when a user registers an account. Just call the feed API:

Endpoint HTTP Header Method Parameters Result (JSON)
/api/feed apikey: <account apikey> POST
  • name: <name>

Name can be used to identify this feed; i.e 'customer-34-app-metrics'

  • id: <unqiue feed id>
  • api-key: <feed api-key>

You should store the feed id and feed api-key returned from the feed API for each separate user in your backend.

Send metric data for each user

Next you can schedule a (i.e hourly) job in your backend which will start sending application metrics for each user. You can do this by looping over your users and for each user gather the same set of metrics; and then posting them on each feed associated with each user.

Sending data to a feed is very easy, just make a post request:

Endpoint HTTP Header Method Parameters
/api/feed/<feed name> apikey:
<account apikey>
POST
  • <metric 1>: <value>
  • <metric 2>: <value>
  • etc ...

You can also copy-and-paste a working code example by viewing a feed from the metricboard.io interface.

Note: if a feed does not yet exist it will be created automatically.

Build a dashboard

Next we need to create the actual dashboard we like to offer to each user. You can create any dashboard from the 'Dashboards' menu. Use the drag-and-drop functionality to build a dashboard.

Tip: select any of the user feeds created from the backend; so you can select the appropriate metrics.

Embed the dashboard in your application

The last step is to integrate the dashboard into your application. We are going to call the metricboard API to embed the dashboard you have created in the previous step and present it with the correct feed to each individual user.

For this you can use the embed API:

Endpoint HTTP Header Method Parameters Result (JSON)
/api/embed apikey: <account apikey> POST
  • feed: <feed name>
  • dashboard: <dashboard id>
  • expires: <'2014-10-25 14:30:59'> optional
  • description: <optional>
  • url: <embed url>

The feed id is the id you have stores when creating the feed for each user. You can find the dashboard id when editing the dashboard; in the browser URL.

This call will return an JSON document containing a URL. This URL will display the dashboard with the data from the feed for that specific user. The URL can be displayed directly by a redirect or embedded in a iframe within your application.

You can simply call this API each time you want to display a dashboard for a specific user; be sure to specify a expires. After an embed URL expires it will be automatically deleted; thus preventing a user from accessing the dashboard URL indefinitely.

Complete example

Below you will find a python example doing all of the above steps:

Create separate feeds and send data for each user:


import requests
import random

api_key="account api Key"

for user in range(5):

    # Retrieve from your database
    order_count = random.randint(0, 100)
    product_stock = random.randint(0, 100) # Retrieve from your database

    # Retrieve the feed api key associated with this user
    feed_api_key = "api-key"

    requests.post(url="https://metricboard.io/api/feed/feed-user-{}".format(user),
                  data={
                    "order count": order_count,
                    "product stock": product_stock
                  },
                  headers={'apikey': api_key})

Generate an embed URL for a dashboard and feed:


import requests

api_key="account api Key"
feed_name="feed name" # The feed id you stored for this user
dashboard_id=12 # Dashboard id from your account

embed = requests.post(url="https://metricboard.io/api/embed",
                      data={
                        "feed": feed_name,
                        "dashboard": dashboard_id
                      },
                      headers={'apikey': api_key})

# Open the URL in a iframe or redirect:
print "URL: {url}".format(url=embed.json().get('url'))

Conclusion

We hope this article was helpful in getting per user dashboards up and running quickly.

Comments or questions or need help with integrating? Let us know by contacting us!