> For the complete documentation index, see [llms.txt](https://help.daasity.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.daasity.com/core-concepts/data-integrations/setup-guides/digital-integrations/facebook-ads/integration-specifications.md).

# Integration Specifications

## **Integration Overview**

Facebook is the largest social media platform globally, meaning it is the destination allowing advertisers to reach the largest majority of potential consumers.

The Daasity Facebook Ads integration extracts key advertising information from the Facebook Ads platform, which includes Instagram advertising as well. Data such as spend, clicks and impressions are extracted on a daily basis and populate your data warehouse.

{% hint style="warning" %}
**Only 37 months of history available**

Facebook exposes only the last 37 months of history in their API. We will not be able to extract data for any activity outside of that window. [(source)](https://developers.facebook.com/docs/marketing-api/reference/ad-account/insights/)
{% endhint %}

## **Integration Availability**

This integration is available for:

* Enterprise
* Growth

## **API Endpoints**

The Daasity Facebook Ads extractor is built based on this [Facebook Ads Marketing Insights API Documentation](https://developers.facebook.com/docs/marketing-apis). The following endpoints are used by Daasity to replicate data from Facebook Ads.

* [Ads](https://developers.facebook.com/docs/marketing-api/campaign-structure#ads)
* [Ad Sets](https://developers.facebook.com/docs/marketing-api/campaign-structure#sets)
* [Campaigns](https://developers.facebook.com/docs/marketing-api/campaign-structure#campaigns)
* [Insights](https://developers.facebook.com/docs/marketing-api/insights/best-practices)

## **Entity Relationship Diagram (ERD)**

[Click here to view the ERD for the Daasity Facebook Ads](https://lucid.app/documents/embedded/f86e8f54-6bfa-441b-a516-66b231771f51) integration illustrating the different tables and keys to join across tables.

## Facebook Ads Schema

The Daasity Facebook Ads extractor creates these tables using the endpoints and replication methods listed. The data is mapped from the source API endpoint to the table based on the mapping logic outlined in each table.

* [Ads](#a-ds)
* [Ad Sets](#a-d-sets)
* [Ad Spends](#a-d-spends)
* [Campaigns](#campaigns)
* [Ads Extended Columns](#ads-extended-columns)
* [Product Performance](#product-performance)
* [Custom Reports](#custom-reports)

### **Ads**

* Endpoint: [Ads](https://developers.facebook.com/docs/marketing-api/campaign-structure#ads)
* Update Method: UPSERT
* Table Name: \[`facebook_marketing.ads`]

| JSON Element                                    | Database Column          |
| ----------------------------------------------- | ------------------------ |
| id                                              | id                       |
| name                                            | ad\_name                 |
| status                                          | ad\_status               |
| effective\_status                               | effective\_status        |
| configured\_status                              | configured\_status       |
| adset\_id                                       | adset\_id                |
| campaign\_id                                    | campaign\_id             |
| adset::name                                     | adset\_name              |
| campaign::name                                  | campaign\_name           |
| preview\_shareable\_link                        | preview\_shareable\_link |
| Facebook Account ID                             | ad\_account\_id          |
| ID of Merchant in Daasity App                   | \_account\_id            |
| timestamp when data was extracted from Facebook | \_\_synced\_at           |

{% hint style="info" %}
The `creative_*`, `asset_feed_spec` and `destination_url` columns on this table are not populated. Ad creative data is loaded into [Ads Extended Columns](#ads-extended-columns) instead.
{% endhint %}

### **Ad Sets**

* Endpoint: [Ad Sets](https://developers.facebook.com/docs/marketing-api/campaign-structure#sets)
* Update Method: UPSERT
* Table Name: \[`facebook_marketing.adsets`]

| JSON Element                                    | Database Column   |
| ----------------------------------------------- | ----------------- |
| id                                              | id                |
| — (no longer populated)                         | date              |
| name                                            | adset\_name       |
| status                                          | adset\_status     |
| effective\_status                               | effective\_status |
| targeting::geo\_locations::countries            | target\_country   |
| targeting::publisher\_platforms                 | target\_platform  |
| Facebook Account ID                             | ad\_account\_id   |
| ID of Merchant in Daasity App                   | \_account\_id     |
| timestamp when data was extracted from Facebook | \_\_synced\_at    |

### **Ad Spends**

* Endpoint: [Insights](https://developers.facebook.com/docs/marketing-api/insights/best-practices)
* Update Method: UPSERT
* Table Name: \[`facebook_marketing.ad_spends`]

| JSON Element                                                                                   | Database Column                             |
| ---------------------------------------------------------------------------------------------- | ------------------------------------------- |
| MD5(campaign\_id + adset\_id + ad\_id + date\_start + attribution window)                      | id                                          |
| campaign\_id                                                                                   | campaign\_id                                |
| adset\_id                                                                                      | adset\_id                                   |
| ad\_id                                                                                         | ad\_id                                      |
| account\_id                                                                                    | account\_id                                 |
| account\_name                                                                                  | account\_name                               |
| spend                                                                                          | spend                                       |
| cpc                                                                                            | cpc                                         |
| cpm                                                                                            | cpm                                         |
| cpp                                                                                            | cpp                                         |
| ctr                                                                                            | ctr                                         |
| account\_currency                                                                              | account\_currency                           |
| date\_start                                                                                    | date                                        |
| buying\_type                                                                                   | buying\_type                                |
| conversion\_rate\_ranking                                                                      | conversion\_rate\_ranking                   |
| engagement\_rate\_ranking                                                                      | engagement\_rate\_ranking                   |
| objective                                                                                      | objective                                   |
| optimization\_goal                                                                             | optimization\_goal                          |
| quality\_ranking                                                                               | quality\_ranking                            |
| canvas\_avg\_view\_percent                                                                     | canvas\_avg\_view\_percent                  |
| canvas\_avg\_view\_time                                                                        | canvas\_avg\_view\_time                     |
| cost\_per\_estimated\_ad\_recallers                                                            | cost\_per\_estimated\_ad\_recallers         |
| cost\_per\_inline\_link\_click                                                                 | cost\_per\_inline\_link\_click              |
| cost\_per\_inline\_post\_engagement                                                            | cost\_per\_inline\_post\_engagement         |
| cost\_per\_unique\_click                                                                       | cost\_per\_unique\_click                    |
| cost\_per\_unique\_inline\_link\_click                                                         | cost\_per\_unique\_inline\_link\_click      |
| reach                                                                                          | reach                                       |
| social\_spend                                                                                  | social\_spend                               |
| qualifying\_question\_qualify\_answer\_rate                                                    | qualifying\_question\_qualify\_answer\_rate |
| estimated\_ad\_recall\_rate                                                                    | estimated\_ad\_recall\_rate                 |
| estimated\_ad\_recallers                                                                       | estimated\_ad\_recallers                    |
| frequency                                                                                      | frequency                                   |
| full\_view\_impressions                                                                        | full\_view\_impressions                     |
| full\_view\_reach                                                                              | full\_view\_reach                           |
| impressions                                                                                    | impressions                                 |
| clicks                                                                                         | clicks                                      |
| inline\_link\_click\_ctr                                                                       | inline\_link\_click\_ctr                    |
| inline\_link\_clicks                                                                           | inline\_link\_clicks                        |
| inline\_post\_engagement                                                                       | inline\_post\_engagement                    |
| instant\_experience\_clicks\_to\_open                                                          | instant\_experience\_clicks\_to\_open       |
| instant\_experience\_clicks\_to\_start                                                         | instant\_experience\_clicks\_to\_start      |
| actions::app\_custom\_event.fb\_mobile\_purchase                                               | mobile\_purchase\_count                     |
| actions::onsite\_conversion.purchase                                                           | onsite\_purchase\_count                     |
| actions::offline\_conversion.purchase                                                          | offline\_purchase\_count                    |
| action\_values::app\_custom\_event.fb\_mobile\_purchase                                        | mobile\_purchase\_value                     |
| action\_values::onsite\_conversion.purchase                                                    | onsite\_purchase\_value                     |
| action\_values::offline\_conversion.purchase                                                   | offline\_purchase\_value                    |
| action\_values::offsite\_conversion.fb\_pixel\_purchase (sum of the attribution window values) | purchase\_value                             |
| actions::offsite\_conversion.fb\_pixel\_purchase (sum of the attribution window values)        | purchase\_count                             |
| Attribution window set on the integration, joined with `:` (e.g. 7d\_click:1d\_view)           | attribution\_window                         |
| Facebook Account ID                                                                            | ad\_account\_id                             |
| ID of Merchant in Daasity App                                                                  | \_account\_id                               |
| timestamp when data was extracted from Facebook                                                | \_\_synced\_at                              |

{% hint style="info" %}
The insights level is set on the integration (campaign by default). `adset_id` and `ad_id` are only filled at the ad level. The columns from `account_id` to `instant_experience_clicks_to_start`, other than `account_currency`, are only requested in async mode.
{% endhint %}

### **Campaigns**

* Endpoint: [Campaigns](https://developers.facebook.com/docs/marketing-api/campaign-structure#campaigns)
* Update Method: UPSERT
* Table Name: \[`facebook_marketing.campaigns`]

| JSON Element                                    | Database Column   |
| ----------------------------------------------- | ----------------- |
| id                                              | id                |
| — (no longer populated)                         | date              |
| id                                              | campaign\_id      |
| name                                            | campaign\_name    |
| status                                          | campaign\_status  |
| effective\_status                               | effective\_status |
| Facebook Account ID                             | ad\_account\_id   |
| ID of Merchant in Daasity App                   | \_account\_id     |
| timestamp when data was extracted from Facebook | \_\_synced\_at    |

### **Ads Extended Columns**

* Endpoint: [Ads](https://developers.facebook.com/docs/marketing-api/campaign-structure#ads)
* Update Method: UPSERT
* Table Name: \[`facebook_marketing.ads_extended_columns`]

{% hint style="info" %}
Optional: loaded only when "Ads extended columns" is enabled on the integration (off by default).
{% endhint %}

| JSON Element                                                      | Database Column                  |
| ----------------------------------------------------------------- | -------------------------------- |
| id                                                                | ad\_id                           |
| creative::id                                                      | creative\_id                     |
| creative::name                                                    | creative\_name                   |
| creative::thumbnail\_url                                          | creative\_thumbnail\_url         |
| creative::body                                                    | creative\_body                   |
| creative::asset\_feed\_spec (JSON)                                | asset\_feed\_spec                |
| creative::object\_story\_spec::link\_data::link                   | destination\_url                 |
| creative::object\_story\_spec::link\_data::name                   | creative\_title                  |
| creative::object\_story\_spec::link\_data::picture                | creative\_image\_url             |
| creative::object\_story\_spec::video\_data::video\_id             | creative\_video\_id              |
| creative::object\_story\_spec::link\_data::call\_to\_action::type | creative\_call\_to\_action\_type |
| ID of Merchant in Daasity App                                     | \_account\_id                    |
| timestamp when data was extracted from Facebook                   | \_\_synced\_at                   |

### **Product Performance**

* Endpoint: [Insights](https://developers.facebook.com/docs/marketing-api/insights/best-practices) (campaign level, broken down by `product_id`)
* Update Method: UPSERT
* Table Name: \[`facebook_marketing.product_performance`]

{% hint style="info" %}
Loaded when "Product performance report" is enabled on the integration (on by default).
{% endhint %}

| JSON Element                                                               | Database Column                |
| -------------------------------------------------------------------------- | ------------------------------ |
| MD5(campaign\_id + product\_id + date\_start + attribution window + spend) | id                             |
| date\_start                                                                | date                           |
| product\_id                                                                | product\_id                    |
| campaign\_id                                                               | campaign\_id                   |
| campaign\_name                                                             | campaign\_name                 |
| spend                                                                      | spend                          |
| cpc                                                                        | cpc                            |
| cpm                                                                        | cpm                            |
| ctr                                                                        | ctr                            |
| cost\_per\_inline\_link\_click                                             | cost\_per\_inline\_link\_click |
| impressions                                                                | impressions                    |
| actions::link\_click                                                       | link\_clicks                   |
| Attribution window set on the integration, joined with `:`                 | attribution\_window            |
| Facebook Account ID                                                        | ad\_account\_id                |
| ID of Merchant in Daasity App                                              | \_account\_id                  |
| timestamp when data was extracted from Facebook                            | \_\_synced\_at                 |

### **Custom Reports**

* Endpoint: [Insights](https://developers.facebook.com/docs/marketing-api/insights/best-practices)
* Update Method: UPSERT on `__sync_key`
* Table Name: \[`facebook_marketing.<table name set on the custom report>`]

Custom reports are set up on the integration. Each report has its own table, with one column per selected field and breakdown, plus these columns:

| JSON Element                                                                | Database Column              |
| --------------------------------------------------------------------------- | ---------------------------- |
| MD5(date\_start + level ID + breakdown values + attribution window + level) | id                           |
| date\_start                                                                 | date                         |
| Insights level of the report                                                | level                        |
| Attribution window set on the integration, joined with `:`                  | attribution\_window          |
| `<level>_id` (e.g. campaign\_id, ad\_id)                                    | `<level>_id`                 |
| Each selected breakdown                                                     | `<breakdown>`                |
| Each selected field                                                         | `<column set on the report>` |
| ID of Merchant in Daasity App                                               | \_account\_id                |
| Facebook Account ID                                                         | \_\_source\_id               |
| Same as id                                                                  | \_\_sync\_key                |
| timestamp when data was extracted from Facebook                             | \_\_synced\_at               |
