> ## Documentation Index
> Fetch the complete documentation index at: https://docs.conversion.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Google BigQuery

> Connect Google BigQuery to sync contacts, custom objects, and events into Conversion.

## Set Up

### Before You Begin

Make sure you have the following before starting:

* **Owner or IAM Admin access in your GCP project:** You'll need to create a service account, assign roles, and generate a key. The **Owner**, **IAM Admin**, or an equivalent role is required.
* **The dataset(s) you want to sync identified:** Know which project, and optionally which datasets and tables, Conversion should be able to read from.
* **Your GCP project ID:** Found in the Google Cloud Console next to the project name (e.g. `my-company-prod`). You'll need it when connecting in Step 2.

***

### Step 1: Set Up BigQuery Access

Conversion connects to BigQuery using a service account with a JSON key. In this step you'll create a dedicated service account, grant it read access to your data, and (if needed) configure network access.

#### Create a Service Account

We recommend creating a **dedicated service account** for Conversion so its activity is easy to monitor and audit in isolation.

1. In the Google Cloud Console, go to **IAM & Admin → Service Accounts** and create a new service account (e.g. `conversion-sync`).
2. Grant it the **BigQuery Job User** and **BigQuery User** roles (project level).
3. Open the service account, go to the **Keys** tab, and create a new **JSON** key. Save the downloaded file; you'll upload it to Conversion in Step 2.

#### Grant Read Access to Your Data

The service account also needs **BigQuery Data Viewer** to read your tables.

We recommend granting it at the **dataset** level so Conversion's access is scoped to exactly the data you want it to see. New tables added to those datasets are picked up automatically.

For each dataset you want Conversion to read, open **BigQuery**, find the dataset in the Explorer panel, click the three dots → **Share**, and add your service account email (e.g. `conversion-sync@my-project.iam.gserviceaccount.com`) with the **BigQuery Data Viewer** role.

> [!WARNING]
>
> Conversion only sees datasets you explicitly share. New datasets need to be shared with the service account before Conversion can read from them.

##### Granting Data Viewer at the project level

If your project doesn't contain data Conversion shouldn't see, you can grant **BigQuery Data Viewer** at the project level instead, either during service account creation or later in **IAM & Admin → IAM**. New datasets are then picked up automatically as you add them.

#### Allow IP Addresses

If your BigQuery project uses VPC Service Controls or restricts access by IP, allow connections from Conversion's IP addresses:

| Region | IP Addresses |
| :- | :- |
| US | 35.239.90.161, 35.188.167.166, 34.56.101.43, 34.122.97.230, 34.29.176.66, 35.226.154.44 |

> [!NOTE]
>
> Most BigQuery projects don't restrict by IP. If you don't use VPC Service Controls or perimeter rules, you can skip this step.

***

### Step 2: Connect BigQuery to Conversion

1. In Conversion, go to **Settings → CRM and syncing → Connections**.
2. Click **Add BigQuery connection**.
3. Fill in the connection details using the values from the earlier steps:
   | Field | What to enter | Where it came from |
   | - | - | - |
   | **Name** | A friendly label, e.g. `Production BigQuery` | Free-text, just for your reference in Conversion |
   | **Project ID** | Your GCP project ID, e.g. `my-company-prod` | Found in the Google Cloud Console next to the project name |
   | **Service account credentials** | Upload your JSON key file | Generated in Step 1 |
4. Click **Create connection**.

Conversion will verify the connection. If successful, you're ready to create syncs.

Onboarding with Conversion? Let your Deployment Strategist know when this is done and we'll check it on our end.

***

## Create a Sync

After connecting, open your new BigQuery connection and go to the **Syncs** tab to create a sync. Read more about [Setting Up a Sync](https://docs.conversion.ai/product-docs/sync/data-warehouse/overview.md#setting-up-a-sync).

***

## Writing Queries for BigQuery

A few things to keep in mind before writing your first query:

* **Name your columns to match Conversion fields.** Conversion maps results to fields **by column name**, so each column in your `SELECT` clause must match the field key in Conversion exactly (e.g. `email`, `first_name`, `userId`, `event_id`). Use `AS` to alias when the source name doesn't match.
* **Always filter by `last_sync_time`** so each run only processes changed rows. In BigQuery, wrap it with `TIMESTAMP_SECONDS()`; see [Using last\_sync\_time](#using-last-sync-time) for details.
* **Select only the columns you'll actually use**, as every column scanned costs money in BigQuery.
* **Schedule large syncs carefully.** See [Set the Schedule](https://docs.conversion.ai/product-docs/sync/data-warehouse/overview.md#3-set-the-schedule) for how often to run queries that return millions of rows.

### Contact Sync

Provide `userId` (preferred), `email`, or both; at least one is required so Conversion can match the contact.

```sql theme={null}
SELECT
  id AS userId,
  email,
  first_name,
  last_name,
  title AS job_title,
  phone,
  city
FROM `project.dataset.users`
WHERE updated_at >= TIMESTAMP_SECONDS({{last_sync_time}})
```

### Custom Objects (Without Relationships)

Alias your record's unique identifier as `object_id`, and select the object's own fields:

```sql theme={null}
SELECT 
  id AS object_id,
  name,
  status,
  plan_tier,
  monthly_price
FROM `project.dataset.subscriptions`
WHERE updated_at >= TIMESTAMP_SECONDS({{last_sync_time}})
```

### Custom Objects with Relationships

To link each record to a related record, alias a column to the key of a relationship field on the object. See [Custom Objects with Relationships](https://docs.conversion.ai/product-docs/sync/data-warehouse/overview.md#custom-objects-with-relationships) for the values each related object accepts.

```sql theme={null}
SELECT 
  p.id AS object_id,
  p.name,
  p.sku,
  p.category,
  p.price,
  u.email AS owner  -- relationship field to Contacts
FROM `project.dataset.products` p
JOIN `project.dataset.users` u ON p.owner_id = u.id
WHERE p.updated_at >= TIMESTAMP_SECONDS({{last_sync_time}})
```

In this example:

* `object_id` identifies the Product record, and `name`, `sku`, `category`, and `price` are stored on it
* `owner` is a relationship field on the Product object that points at Contacts, so each product links to the contact with that email address

### Events

Events require a contact identifier (`userId` or `email`), `event_name`, and `timestamp`. `event_id` is optional but recommended. Conversion uses it to deduplicate events across runs, so it must be unique across all your event syncs; prefix it with the table name as shown.

```sql theme={null}
SELECT
  CAST(u.id AS STRING) AS userId,
  u.email,
  'purchase_completed' AS event_name,
  UNIX_SECONDS(o.created_at) AS timestamp,
  CONCAT('order:', CAST(o.id AS STRING)) AS event_id,
  o.total_amount,
  o.product_name,
  o.currency
FROM `project.dataset.orders` o
JOIN `project.dataset.users` u ON o.user_id = u.id
WHERE o.created_at >= TIMESTAMP_SECONDS({{last_sync_time}})
```

***

## BigQuery SQL Reference

### Converting Timestamps

Conversion expects Unix timestamps for date/time fields. Use `UNIX_SECONDS()` to convert BigQuery `TIMESTAMP` or `DATETIME` values:

```sql theme={null}
SELECT 
  email,
  UNIX_SECONDS(created_at) AS created_at,
  UNIX_SECONDS(last_login) AS last_login
FROM `project.dataset.users`
WHERE updated_at >= TIMESTAMP_SECONDS({{last_sync_time}})
```

### Using last\_sync\_time

See [Incremental Syncing](https://docs.conversion.ai/product-docs/sync/data-warehouse/overview.md#incremental-syncing) for how `last_sync_time` works. In BigQuery, convert it with `TIMESTAMP_SECONDS()` to compare against a `TIMESTAMP` column:

```sql theme={null}
WHERE updated_at >= TIMESTAMP_SECONDS({{last_sync_time}})
```

Or convert your column to Unix seconds and compare integers directly:

```sql theme={null}
WHERE UNIX_SECONDS(updated_at) >= {{last_sync_time}}
```

With a [time buffer](https://docs.conversion.ai/product-docs/sync/data-warehouse/overview.md#time-buffered-queries):

```sql theme={null}
WHERE updated_at >= TIMESTAMP_SECONDS({{last_sync_time}} - 300)  -- 5 minute buffer
```

### Handling NULLs

Use `COALESCE` or `IFNULL` to provide default values:

```sql theme={null}
SELECT 
  email,
  COALESCE(first_name, '') AS first_name,
  IFNULL(phone, '') AS phone
FROM `project.dataset.users`
```

### Casting Types

Use `CAST` to convert between types:

```sql theme={null}
SELECT 
  CAST(user_id AS STRING) AS userId,
  CAST(score AS INT64) AS lead_score
FROM `project.dataset.users`
```

### Querying Across Datasets

Use fully-qualified table names to join across datasets:

```sql theme={null}
SELECT 
  u.email,
  o.order_id
FROM `project.users_dataset.users` u
JOIN `project.orders_dataset.orders` o ON u.id = o.user_id
```

***

## Troubleshooting

### "Permission denied" errors

Ensure your service account has the required roles:

* **BigQuery Job User** (project level)
* **BigQuery User** (project level)
* **BigQuery Data Viewer** (on each dataset you want to query)

### "Could not connect" errors

Verify that:

* You uploaded the service account's JSON key file, unedited
* Your project ID matches the project the service account belongs to
* Conversion's IP addresses are allowed if you use VPC Service Controls

### Sync taking too long

* Use partitioned tables and filter on the partition column for time-based data

For general tips, see [Sync Taking Too Long](https://docs.conversion.ai/product-docs/sync/data-warehouse/overview.md#sync-taking-too-long).

### Duplicate data appearing

If you're using time-buffered queries (subtracting from `last_sync_time` to catch edge cases), Conversion handles duplicates automatically based on the unique key (`userId` or `email` for contacts, `object_id` for custom objects, `event_id` for events).

***

## Frequently Asked Questions

> [accordion] What BigQuery permissions does Conversion need?
>
> The service account needs **BigQuery Job User** and **BigQuery User** at the project level, plus **BigQuery Data Viewer** on the datasets you want to sync. Conversion only reads data; it never writes to your BigQuery project.

> [accordion] How much does this cost in BigQuery?
>
> BigQuery charges for the amount of data scanned by your queries. To minimize costs: select only the columns you need, filter with `last_sync_time`, and use partitioned tables where possible.

> [accordion] How do I sync from multiple datasets?
>
> Use fully-qualified table names in your query:
>
> ```sql theme={null}
> SELECT u.email, o.order_id
> FROM `my-project.users_dataset.users` u
> JOIN `my-project.orders_dataset.orders` o ON u.id = o.user_id
> ```
>
> Make sure **BigQuery Data Viewer** is granted on each dataset you reference.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.