A Google Cloud Function that fetches analytics data from Plausible and streams it into Fivetran. This function handles incremental syncs, respects timezones configured in your Plausible dashboard, and automatically merges data into a timeseries
table within Fivetran.
This repository contains a Node.js function meant to be deployed on Google Cloud Functions. It leverages Fivetran’s function connector to sync Plausible analytics data on a regular schedule. The function:
- Reads the
plausibleApiKey
andsiteId
secrets from the Fivetran request body. - Queries Plausible’s v2 analytics API to retrieve incremental hourly data.
- Returns data in a format Fivetran can ingest (including a state object, table schema, and indicators for additional data).
Use the instructions in the official Fivetran Google Cloud Functions setup guide to deploy this function. Make sure to:
- Provide this repository’s code as your function source.
- Set the entry point to
syncWithPlausible
. - Configure two secrets in Fivetran’s Configuration:
plausibleApiKey
: Your Plausible API keysiteId
: The Plausible site ID you want to fetch analytics for
-
REPORTING_TIMEZONE
Set within the code to match your Plausible dashboard’s timezone. Default isEurope/Berlin
. -
PAGE_SIZE
The number of records fetched per API call. Default is1000
. You can adjust this in the code to optimize for your data volume and performance. -
State Management
Fivetran manages astate
object that the function updates. The function uses:state.lastDateTime
to know the last timestamp syncedstate.lastOffset
for pagination across Plausible’s API
Once deployed and configured:
-
Initial Sync
- Fivetran calls the function with no
state
. The function fetches data starting from the earliest available date (or"all"
) until the latest. - It updates the Fivetran state with the newest timestamp retrieved (
lastDateTime
).
- Fivetran calls the function with no
-
Incremental Sync
- On subsequent calls, Fivetran includes the
lastDateTime
in the requeststate
. - The function queries Plausible from
lastDateTime
to the current time, ensuring only new data is retrieved.
- On subsequent calls, Fivetran includes the
-
Data Destination
- Fivetran creates or updates a
plausible_timeseries
table in your destination. - Columns include
timestamp
,visitors
,pageviews
,bounce_rate
,visit_duration
, andvisits
.
- Fivetran creates or updates a
-
Connection Test
Fivetran’s Test Connection calls the function withsetup_test = true
. In this mode, the function performs a minimal API request to Plausible (requesting one row) to confirm credentials and endpoint availability. -
Local Testing
You can also run the function locally with the Functions Framework:npm install npx functions-framework --target=syncWithPlausible --port=8080
Then POST a request to
http://localhost:8080/
to test the logic.
Need a powerful image editing SDK for your next project? Check out IMG.LY. Our CreativeEditor SDK provides easy-to-integrate photo and video editing capabilities for web, iOS, and Android. Join thousands of developers who use IMG.LY to enhance their apps with filtering, transformations, stickers, and more—helping users unleash their creativity right inside your product.
This project is open source, released under the MIT License. You are free to use, modify, and distribute this code as permitted under the license terms.
Happy Syncing!