All Collections
Import Scripts
Examples
Import data from Plausible.io
Import data from Plausible.io

Example Javascript code for importing data from Plausible.io

Abbey Lauren Minondo avatar
Written by Abbey Lauren Minondo
Updated over a week ago

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

1. Create a Plausible personal access token

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

2. 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.

3. The 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 = 'https://plausible.io/api/v1/stats/';const siteId = 'interval.com';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}`,}});

equals.addRows(response.data['results']);


โ€‹

Did this answer your question?