You can connect your BigQuery tables to PostHog by configuring it as a source. You must grant a limited set of permissions so the connector can create, query, and delete temporary tables without exposing your entire BigQuery environment.
Requirements
- A Google Cloud Service Account with the permissions described below
- Google Cloud JSON Key file for that account's Dataset ID
- (Optional) A Dataset ID for temporary tables
Configuring BigQuery
To securely connect your BigQuery account to PostHog, create a dedicated service account with the minimum required permissions:
- Create a service account:
- Go to the Google Cloud Console.
- Navigate to IAM & Admin > Service Accounts.
- Click Create Service Account.
- Provide a descriptive name (e.g.,
bigquery-posthog-service-account
) and a brief description.
- Assign required permissions:
- For simplicity, you can assign the BigQuery Data Editor and BigQuery Job User roles if it meets your security requirements.
- Alternatively, create a custom role that includes only these permissions:bigquery.datasets.getbigquery.jobs.createbigquery.tables.getbigquery.tables.listbigquery.tables.getDatabigquery.tables.createbigquery.tables.updateDatabigquery.tables.delete
- Generate and download the service account key:
- Once the service account is created, click on it and select the Keys tab.
- Click Add Key > Create new key, choose JSON, and download the key file.
- Important: Store the JSON key securely, as it contains sensitive credentials.
Configuring PostHog
- In PostHog, go to the Data pipelines tab, then choose sources
- Click New source and select BigQuery
- Drag and drop the Google Cloud JSON Key file to upload
- Enter the Dataset ID you want to import
- (Optional) If you're limiting permissions to the service account provided, enter a Dataset ID for temporary tables
- (Optional) Add a prefix for the table name
How it works
PostHog creates and deletes temporary tables when querying your data. This is necessary for handling large BigQuery tables. Temporary tables help break down large data processing tasks into manageable chunks. However, they incur storage and query costs in BigQuery while they exist. We delete them as soon as the job is done.
Costs
We minimize BigQuery costs by keeping queries to a minimum and deleting temporary tables immediately after use. Although the connector automates temporary table management, check BigQuery’s pricing for details on storage and query costs.