---
updatedAt: 2026-11-11T08:25:13.000Z
agentTools:
  projectIndex: https://docs.esputnik.com/llms.txt
---

# Importing Data from the BigQuery Tables

<HTMLBlock>{`
<p align="right" style="color: gray;">
  <a href="https://docs-ua.esputnik.com/docs/import-danih-iz-tablic-bigquery" style="color: gray; text-decoration: none;"><em>
    Read this article in Ukrainian ⮕
  </em></a>
</p>
`}</HTMLBlock>

Let’s consider how to create a BigQuery data source and use it for segmentation and personalization in eSputnik.

The account's pricing plan has to include this feature — if it stops covering BigQuery import, the import stops automatically. The integration also works with regular (scheduled) workflows only; event-driven workflows aren't supported.

> ❗️ Important
>
> Create the dataset you import from in the `US` or `EU` multi-region. eSputnik queries it without naming a location, which BigQuery accepts for those two multi-regions only — a dataset placed in a single region, such as `us-central1` or `europe-west3`, returns an error, and the data source shows no data. If you already have such a dataset, recreate the table in a supported location.

Internal identifiers — `contactId`, event ID, and the internal order ID — are unique to the account that produced them. If you import a table exported from another account, those values match nothing here, so pass them into additional fields at most, and match records on identifiers of your own, such as `externalCustomerId` or the external order ID.

## Configuring a Data Source for Importing Data to eSputnik

1. Go to your profile → **Settings → Data sources**, click **New data source**, and select **External data source**.

<Image src="https://files.readme.io/b924aeeaa7456214eb04ff55d4ceff1fa29ff5644ac5aadd40d444210a78fb91-image.png" alt="External data source" align="center" width="80% " />

2. Select [the created connector](https://docs.esputnik.com/docs/integrating-with-google-bigquery#connecting-bigquery).

<Image src="https://files.readme.io/0b9770ec28ea4306f52319861c4cc749c5b65812c60f407a32bb3171c0068ffc-image.png" alt="Connector" align="center" width="80% " />

3. Specify the dataset and table, and enter a source name (also you can specify filters for forming the message content here). Click **Save**.

<Image src="https://files.readme.io/96f8c6d646e09352c23ec3f2af97b565c2080af94cc3c2201924c5667be66562-image.png" alt="Save" align="center" width="80% " />

## Using BigQuery Data for Personalized E-commerce Campaigns

BigQuery data can drive highly targeted campaigns by dynamically referencing customer-specific details such as purchase history, engagement levels, and preferred product categories. Here’s how to incorporate this data into your e-commerce campaigns.

Preview doesn't substitute data from an external source — the values appear only in a real send. Check the message with a campaign to the segment built on that source: a send addressed to a single contact instead of that segment doesn't go through.

### 1. Broadcast Campaign with BigQuery Data

Suppose you want to run a campaign targeting customers who recently purchased specific product categories, offering a personalized discount code. Here’s an example data setup for a contact, `jdoe@example.com` using the `discount_codes` data source:

```json
{  
  "data": {  
    "discount_codes": [  
      {  
        "id": "3",  
        "email": "jdoe@example.com",  
        "name": "John Doe",  
        "recent_purchase_category": "Home Appliances",  
        "discount_code": "SAVE20-HOME",  
        "expiry_date": "2023-12-31T23:59:59Z"  
      }  
    ]  
  }  
}
```

You can reference each field in the message using a [Velocity syntax](https://docs.esputnik.com/docs/introduction-to-velocity) as follows:

* **Directly with parameters** (if you know the array has a fixed length):

```text Apache Velocity
$!data.get('discount_codes').get(0).get('name')  
$!data.get('discount_codes').get(0).get('discount_code')
```

* **Using a loop** (ideal for flexible-length arrays):

```text Apache Velocity
# foreach($code in $!data.get('discount_codes'))

  $!code.get('name')  
  $!code.get('discount_code')  
#end
```

### 2. Triggered Campaign Based on Purchase Milestones

To send personalized messages when customers reach purchase milestones, such as their 50th order:

1. [Create a dynamic segment](https://docs.esputnik.com/docs/creating-dynamic-segment) that includes customers meeting specific purchase conditions (for example, the 50th purchase was made).
2. [Set up a regular workflow](https://docs.esputnik.com/docs/launching-a-regular-workflow-for-a-segment) for this segment.

When the workflow triggers for contacts matching specified conditions, the system creates an event. The event name is generated by combining the static prefix `regularEventType` with the segment ID, resulting in a name like `regularEventType-170531841`.

This event includes contact information, such as the contact ID in eSputnik (`contactId`), email address (`emailAddress`), and data pulled from an external table. Each field from the table is converted into a key and placed within an array, labeled with a numeric name that matches the data source ID.

<Image src="https://files.readme.io/1fc5d427783b5344b0cf39bfc7d181c6d24d8f44f52a268038c1bb06b2c3ba38-image.png" alt="ID" align="center" width="80% " />

Data from the external table is passed in the system event as a native JSON object. Escaped JSON strings are not used, so no additional parsing is required to work with the data. Example event body:

```json
{
  "params": [
    {
      "name": "contactId",
      "value": "123456789"
    },
    {
      "name": "1043",
      "value": [
        {
          "id": 2,
          "email": "[email protected]",
          "name": "Jordan Lee",
          "lastPurchaseDate": "2023-10-15T10:00:00Z",
          "purchaseFrequency": 50,
          "averageBasketValue": 120
        }
      ]
    },
    {
      "name": "emailAddress",
      "value": "[email protected]"
    }
  ]
}
```

When inserting data into a message, the eSputnik data source ID is used as the array name in the `data` object:

```json
{
  "data": {
    "1043": [
      {
        "id": "2",
        "email": "shopper@example.com",
        "name": "Jordan Lee",
        "lastPurchaseDate": "2023-10-15T10:00:00Z",
        "purchaseFrequency": 50,
        "averageBasketValue": 120
      }
    ]
  }
}
```

If you know that there’s a single entry in the 1043 array, you can access fields directly:

```text Apache Velocity
$!data.get('1043').get(0).get('name')  
$!data.get('1043').get(0).get('lastPurchaseDate')  
$!data.get('1043').get(0).get('purchaseFrequency')  
$!data.get('1043').get(0).get('averageBasketValue')
```

If the 1043 array could contain multiple entries, use a loop to extract all values dynamically:

```text Apache Velocity
# foreach($entry in $!data.get('1043'))
  $!entry.get('name')  
  $!entry.get('lastPurchaseDate')  
  $!entry.get('purchaseFrequency')  
  $!entry.get('averageBasketValue')  
#end
```

## Creating a Dynamic Segment Using BigQuery Parameters

1. In **Contacts → Segments**, create a new dynamic segment.

2. Select the conditions for inclusion in the segment. In the condition options, click the source name, then the option name, and set the condition. For example,  purchaseFrequency → equals → 50.

<Image src="https://files.readme.io/1f603d0214b94a3e9c535b3f8ecf8bef626e6f1b002fe8a757805dc7011bcbf0-image.png" alt="Dynamic Segment" align="center" width="80%" />

> 📘 Note
>
> Connection to the external database doesn’t presuppose contact import. Segmentation is only available for contacts that exist both in your eSputnik account and in the external database. Synchronize and update contacts before creating campaigns.

<br />