---
title: Ingest data from Meta Ads
description: Learn how to create a managed ingestion pipeline to ingest data from Meta Ads into Databricks.
canonical_url: https://docs.databricks.com/gcp/en/ingestion/lakeflow-connect/meta-ads-pipeline
---

# Ingest data from Meta Ads

> [!NOTE]
> **Beta**
>
> This feature is in [Beta](https://docs.databricks.com/gcp/en/release-notes/release-types.md). To use it, a workspace admin must turn on **Lakeflow Connect for Meta Ads** from the **Previews** page. See [Manage Databricks previews](https://docs.databricks.com/gcp/en/admin/workspace-settings/manage-previews.md).

Learn how to create a managed ingestion pipeline to ingest data from Meta Ads into Databricks. For a list of supported objects, see [Supported objects](https://docs.databricks.com/gcp/en/ingestion/lakeflow-connect/meta-ads-reference.md#supported-objects).

## <a id="requirements" />Requirements

* To create an ingestion pipeline, you must meet the following requirements:

  * Your workspace must be enabled for Unity Catalog.

  * Serverless compute must be enabled for your workspace. See [Serverless compute requirements](https://docs.databricks.com/gcp/en/compute/serverless/index.md#requirements).

  * To create a new connection, you must have `CREATE CONNECTION` privileges on the metastore. See [Manage privileges in Unity Catalog](https://docs.databricks.com/gcp/en/data-governance/unity-catalog/manage-privileges/index.md).

    If the connector supports UI-based pipeline authoring, an admin can create the connection and the pipeline at the same time by completing the steps on this page. However, if the users who create pipelines use API-based pipeline authoring or are non-admin users, an admin must first create the connection in Catalog Explorer. See [Connect to managed ingestion sources](https://docs.databricks.com/gcp/en/connect/managed-ingestion.md).

  * To use an existing connection, you must have `USE CONNECTION` privileges or `ALL PRIVILEGES` on the connection object.

  * You must have `USE CATALOG` privileges on the target catalog.

  * You must have `USE SCHEMA` and `CREATE TABLE` privileges on an existing schema or `CREATE SCHEMA` privileges on the target catalog.

* To ingest from Meta Ads, you must complete the steps in [Set up Meta Ads as a data source](https://docs.databricks.com/gcp/en/ingestion/lakeflow-connect/meta-ads-source-setup.md).

## Create an ingestion pipeline

### Declarative Automation Bundles

This tab describes how to deploy an ingestion pipeline using Declarative Automation Bundles. Bundles can contain YAML definitions of jobs and tasks, are managed using the Databricks CLI, and can be shared and run in different target workspaces (such as development, staging, and production). For more information, see [What are Declarative Automation Bundles?](https://docs.databricks.com/gcp/en/dev-tools/bundles/index.md).

1. Create a bundle using the Databricks CLI:

   ```bash
   databricks bundle init
   ```

2. Add two new resource files to the bundle:
   * A pipeline definition file (for example, `resources/meta_ads_pipeline.yml`). See [pipeline.ingestion\_definition](https://docs.databricks.com/gcp/en/dev-tools/bundles/resources.md#pipeline-ingestion_definition) and [Examples](https://docs.databricks.com/gcp/en/ingestion/lakeflow-connect/meta-ads-pipeline.md#examples).
   * A job definition file that controls the frequency of data ingestion (for example, `resources/meta_ads_job.yml`). See [Declarative Automation Bundles job definition file](https://docs.databricks.com/gcp/en/ingestion/lakeflow-connect/meta-ads-pipeline.md#bundle-job-definition-file).

3. Deploy the pipeline using the Databricks CLI:

   ```bash
   databricks bundle deploy
   ```

### Databricks notebook

1. Import the following notebook into your Databricks workspace:

   [Get notebook](https://docs.databricks.com/notebooks/source/saas-cdc/meta-ads-pipeline.html)

2. Leave cell one as-is.

3. Modify cell three with your pipeline configuration details. See [pipeline.ingestion\_definition](https://docs.databricks.com/gcp/en/dev-tools/bundles/resources.md#pipeline-ingestion_definition) and [Examples](https://docs.databricks.com/gcp/en/ingestion/lakeflow-connect/meta-ads-pipeline.md#examples).

4. Click **Run all**.

## `ad_insights` configuration

When you ingest from `ad_insights`, you must configure `meta_ads_options` in the `connector_options` for the table or schema:

| Value                             | Description                                                                                                                                                                                                                                                                                                                                                  |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `level`                           | Optional. Granularity level for insights: `account`, `campaign`, `adset`, or `ad`. Default is `ad`.                                                                                                                                                                                                                                                          |
| `start_date`                      | Optional. The start date for the insights data in `YYYY-MM-DD` format. Must be within the last 36 months. If unset, the connector defaults to 36 months before the current date.                                                                                                                                                                             |
| `breakdowns`                      | Optional. List of breakdown dimensions (for example, `["age", "gender", "country"]`).                                                                                                                                                                                                                                                                        |
| `action_breakdowns`               | Optional. List of action breakdown dimensions (for example, `["action_type", "action_destination"]`).                                                                                                                                                                                                                                                        |
| `action_attribution_windows`      | Optional. List of attribution windows used to report action statistics (for example, `["7d_click", "1d_view"]`). If unset, the connector uses your Meta Ads account's default attribution settings. See [Attribution windows](https://docs.databricks.com/gcp/en/ingestion/lakeflow-connect/meta-ads-reference.md#attribution-windows) for supported values. |
| `action_report_time`              | Optional. Determines the timestamp used to report action statistics: `impression`, `conversion`, `mixed`, and `lifetime`. For example, with `impression`, the connector reports a conversion on the date of the impression that drove it. With `conversion`, it reports a conversion on the date it occurred.                                                |
| `time_increment`                  | Optional. Aggregation period for the returned statistics: `all_days`, `monthly`, or an integer number of days (from `1` to `90`) as a string (for example, `"1"` for daily buckets, `"7"` for weekly). If unset, the Insights API default of `all_days` is used.                                                                                             |
| `custom_insights_lookback_window` | Optional. Number of days to reingest on each subsequent sync to capture late-arriving conversions. If unset, the connector reingests the last `7` days. When set explicitly and `action_attribution_windows` isn't set, this value is also used to derive the attribution window sent to Meta as `<N>d_click,1d_view`.                                       |

## <a id="examples" />Examples

Use these examples to configure your pipeline.

### Ingest all current and future tables from an account

#### Declarative Automation Bundles

The following is an example pipeline definition file:

```yaml
resources:
  pipelines:
    pipeline_meta_ads:
      name: <pipeline-name>
      catalog: <destination-catalog>
      target: <destination-schema>
      ingestion_definition:
        connection_name: <connection-name>
        objects:
          - schema:
              source_schema: <meta-ads-account-id>
              destination_catalog: <destination-catalog>
              destination_schema: <destination-schema>
              table_configuration:
                scd_type: SCD_TYPE_1
```

#### Databricks notebook

The following is an example pipeline specification:

```python
pipeline_spec = {
  "name": "<pipeline-name>",
  "catalog": "<destination-catalog>",
  "schema": "<destination-schema>",
  "ingestion_definition": {
    "connection_name": "<connection-name>",
    "objects": [
      {
        "schema": {
          "source_schema": "<meta-ads-account-id>",
          "destination_catalog": "<destination-catalog>",
          "destination_schema": "<destination-schema>",
          "table_configuration": {
            "scd_type": "SCD_TYPE_1"
          }
        }
      }
    ]
  }
}

json_payload = json.dumps(pipeline_spec, indent=2)
create_pipeline(json_payload)
```

### Select specific tables from an account to ingest

#### Declarative Automation Bundles

The following is an example pipeline definition file:

```yaml
resources:
  pipelines:
    pipeline_meta_ads:
      name: <pipeline-name>
      catalog: <destination-catalog>
      target: <destination-schema>
      ingestion_definition:
        connection_name: <connection-name>
        objects:
          - table:
              source_schema: <meta-ads-account-id>
              source_table: campaigns
              destination_catalog: <destination-catalog>
              destination_schema: <destination-schema>
              table_configuration:
                scd_type: SCD_TYPE_1
          - table:
              source_schema: <meta-ads-account-id>
              source_table: ads
              destination_catalog: <destination-catalog>
              destination_schema: <destination-schema>
              table_configuration:
                scd_type: SCD_TYPE_1
```

#### Databricks notebook

The following is an example pipeline specification:

```python
pipeline_spec = {
  "name": "<pipeline-name>",
  "catalog": "<destination-catalog>",
  "schema": "<destination-schema>",
  "ingestion_definition": {
    "connection_name": "<connection-name>",
    "objects": [
      {
        "table": {
          "source_schema": "<meta-ads-account-id>",
          "source_table": "campaigns",
          "destination_catalog": "<destination-catalog>",
          "destination_schema": "<destination-schema>",
          "table_configuration": {
            "scd_type": "SCD_TYPE_1"
          }
        }
      },
      {
        "table": {
          "source_schema": "<meta-ads-account-id>",
          "source_table": "ads",
          "destination_catalog": "<destination-catalog>",
          "destination_schema": "<destination-schema>",
          "table_configuration": {
            "scd_type": "SCD_TYPE_1"
          }
        }
      }
    ]
  }
}

json_payload = json.dumps(pipeline_spec, indent=2)
create_pipeline(json_payload)
```

### Ingest `ad_insights` with `meta_ads_options`

#### Declarative Automation Bundles

The following is an example `resources/meta_ads_pipeline.yml` file:

```yaml
resources:
  pipelines:
    pipeline_meta_ads:
      name: <pipeline-name>
      catalog: <destination-catalog>
      target: <destination-schema>
      ingestion_definition:
        connection_name: <connection-name>
        objects:
          - table:
              source_schema: <meta-ads-account-id>
              source_table: ad_insights
              destination_catalog: <destination-catalog>
              destination_schema: <destination-schema>
              table_configuration:
                scd_type: SCD_TYPE_1
              connector_options:
                meta_ads_options:
                  level: ad
                  start_date: '2024-01-01'
                  breakdowns:
                    - age
                    - gender
                  action_breakdowns:
                    - action_type
```

#### Databricks notebook

```python
pipeline_spec = {
  "name": "<pipeline-name>",
  "catalog": "<destination-catalog>",
  "schema": "<destination-schema>",
  "ingestion_definition": {
    "connection_name": "<connection-name>",
    "objects": [
      {
        "table": {
          "source_schema": "<meta-ads-account-id>",
          "source_table": "ad_insights",
          "destination_catalog": "<destination-catalog>",
          "destination_schema": "<destination-schema>",
          "table_configuration": {
            "scd_type": "SCD_TYPE_1"
          },
          "connector_options": {
            "meta_ads_options": {
              "level": "ad",
              "start_date": "2024-01-01",
              "breakdowns": ["age", "gender"],
              "action_breakdowns": ["action_type"]
            }
          }
        }
      }
    ]
  }
}

json_payload = json.dumps(pipeline_spec, indent=2)
create_pipeline(json_payload)
```

### <a id="bundle-job-definition-file" />Declarative Automation Bundles job definition file

#### Declarative Automation Bundles

The following is an example job definition file to use with Declarative Automation Bundles. The job runs every day, exactly one day from the last run.

```yaml
resources:
  jobs:
    meta_ads_dab_job:
      name: meta_ads_dab_job

      trigger:
        periodic:
          interval: 1
          unit: DAYS

      email_notifications:
        on_failure:
          - <email-address>

      tasks:
        - task_key: refresh_pipeline
          pipeline_task:
            pipeline_id: ${resources.pipelines.pipeline_meta_ads.id}
```

### Ingest a prebuilt report

Set `source_table` to the report name. `connector_options` are optional for prebuilt reports. The following example sets `start_date` to control the date range. Omit `connector_options` to use the defaults.

#### Declarative Automation Bundles

The following is an example pipeline definition file:

```yaml
resources:
  pipelines:
    pipeline_meta_ads:
      name: <pipeline-name>
      catalog: <destination-catalog>
      target: <destination-schema>
      ingestion_definition:
        connection_name: <connection-name>
        objects:
          - table:
              source_schema: <meta-ads-account-id>
              source_table: demographics_age_report
              destination_catalog: <destination-catalog>
              destination_schema: <destination-schema>
              connector_options:
                meta_ads_options:
                  start_date: '2024-01-01'
```

#### Databricks notebook

```python
pipeline_spec = {
  "name": "<pipeline-name>",
  "catalog": "<destination-catalog>",
  "schema": "<destination-schema>",
  "ingestion_definition": {
    "connection_name": "<connection-name>",
    "objects": [
      {
        "table": {
          "source_schema": "<meta-ads-account-id>",
          "source_table": "demographics_age_report",
          "destination_catalog": "<destination-catalog>",
          "destination_schema": "<destination-schema>",
          "connector_options": {
            "meta_ads_options": { "start_date": "2024-01-01" }
          }
        }
      }
    ]
  }
}

json_payload = json.dumps(pipeline_spec, indent=2)
create_pipeline(json_payload)
```

For the full list of available prebuilt reports, see [Prebuilt reports](https://docs.databricks.com/gcp/en/ingestion/lakeflow-connect/meta-ads-reference.md#prebuilt-reports).

### Ingest a custom report

Set `source_table` to `custom_report`, provide a `destination_table` name, and define the configuration under `connector_options.meta_ads_options.custom_report_options`. You must set `destination_table` so multiple custom reports can coexist in one pipeline.

```json
{
  "ingestion_definition": {
    "connection_name": "<connection-name>",
    "objects": [
      {
        "table": {
          "source_schema": "<meta-ads-account-id>",
          "source_table": "custom_report",
          "destination_catalog": "<destination-catalog>",
          "destination_schema": "<destination-schema>",
          "destination_table": "country_breakdown_report",
          "connector_options": {
            "meta_ads_options": {
              "start_date": "2024-01-01",
              "custom_insights_lookback_window": 7,
              "custom_report_options": {
                "level": "ad",
                "breakdowns": ["country"],
                "action_breakdowns": ["action_type"],
                "time_increment": "1",
                "action_report_time": "mixed",
                "action_attribution_windows": ["7d_click", "1d_view"]
              }
            }
          }
        }
      }
    ]
  }
}
```

For configuration options, see [`custom_report` configuration options](https://docs.databricks.com/gcp/en/ingestion/lakeflow-connect/meta-ads-reference.md#custom-report-options).

## Common patterns

For advanced pipeline configurations, see [Common patterns for managed ingestion pipelines](https://docs.databricks.com/gcp/en/ingestion/lakeflow-connect/common-patterns.md).

## <a id="next-steps" />Next steps

Start, schedule, and set alerts on your pipeline. See [Common pipeline maintenance tasks](https://docs.databricks.com/gcp/en/ingestion/lakeflow-connect/pipeline-maintenance.md).

## Additional resources

* [Meta Ads ingestion connector limitations](https://docs.databricks.com/gcp/en/ingestion/lakeflow-connect/meta-ads-limits.md)
* [Troubleshoot Meta Ads ingestion](https://docs.databricks.com/gcp/en/ingestion/lakeflow-connect/meta-ads-troubleshoot.md)
* [Meta Ads ingestion connector reference](https://docs.databricks.com/gcp/en/ingestion/lakeflow-connect/meta-ads-reference.md)
* [Meta Ads ingestion connector FAQs](https://docs.databricks.com/gcp/en/ingestion/lakeflow-connect/meta-ads-faq.md)
