Example Javascript code for importing data from

You can use Import Scripts to import data from your account directly into an Equals workbook.

Create a Plausible personal access token

You can obtain a Plausible API Key from your account by going to your user settings page

Add the key to a secret group

Copy the access token from the prior step. Then create a new secret group and paste the key into a new secret named plausible_io_api_key.

Example code

Once you've completed the prior steps, create a new workbook, add a new import script to a sheet and copy + paste the script below. Once pasted select your secret group in the toolbar (make sure the key in the secret group is called plausible_io_api_key).

const equals = require('equals');const axios = require('axios');const luxon = require('luxon');

const baseUrl = '';const siteId = '';const apiKey = equals.getSecret('plausible_io_api_key');

function formatJSDate(jsDate) {return luxon.DateTime.fromJSDate(jsDate).toFormat('yyyy-LL-dd');}

const response = await axios.get(baseUrl + 'timeseries', {params: {site_id: siteId,period: 'custom',date: '2022-06-01,' + formatJSDate(new Date()),interval: 'date',metrics: 'visitors,bounce_rate',},headers: {Authorization: `Bearer ${apiKey}`,}});