Weld logo
facebook-ads
Facebook ads

Ad stats by ad_set monthly

Retrieves monthly ad statistics for a specific Facebook ad set, including spend, impressions, clicks, click-through rate (CTR), cost per click (CPC), cost per thousand impressions (CPM), reach, and frequency. It groups the data by month and ad set name.
1select
2    date_trunc(date, month) month
3  , adset_name
4  , sum(spend) spend
5  , sum(impressions) impressions
6  , sum(clicks) clicks
7  , sum(safe_divide(clicks, impressions)) as ctr
8  , sum(safe_divide(clicks, spend)) as cpc
9  , sum(safe_divide(spend, impressions)) * 1000 as cpm
10  , sum(reach) reach
11  , avg(frequency) frequency
12from
13    {{raw.facebook_ads.ad_set_insight}}
14group by
15    1
16  , 2
Example of output from model:
+------------+---------------------+---------+-------------+--------+--------+--------+--------+-------+----------+
|   month    |     adset_name      |  spend  | impressions | clicks |  ctr   |  cpc   |  cpm   | reach | frequency|
+------------+---------------------+---------+-------------+--------+--------+--------+--------+-------+----------+
| 2021-01-01 |    Ad Set #1        |  100.00 |  1,000,000  |  10,000|  1.00% |  0.01  |  100.00| 500,000|   2.00   |
| 2021-01-01 |    Ad Set #2        |  200.00 |  2,000,000  |  20,000|  1.00% |  0.01  |  100.00| 800,000|   2.50   |
| 2021-01-01 |    Ad Set #3        |  300.00 |  3,000,000  |  30,000|  1.00% |  0.01  |  100.00| 1,200,000| 3.00   |
+------------+---------------------+---------+-------------+--------+--------+--------+--------+-------+----------+

By integrating with Facebook Ads, this SQL model allows you to select and aggregate data on a monthly basis, providing insights into ad spend, impressions, clicks, click-through rate (CTR), cost per click (CPC), cost per thousand impressions (CPM), reach, and frequency. This information can be used to optimize ad campaigns, identify top-performing ad sets, and make data-driven decisions to improve overall ad performance. The SQL code is simple to use, requiring only the selection of the desired ad set insight data, and the resulting output is easy to read and interpret. Whether you're a marketer looking to improve your Facebook ad strategy or a business owner seeking to maximize your ad spend, the Ad stats by ad_set monthly SQL template is an essential tool for achieving your goals.

Ready to start modeling your own facebook-ads data?

Get started building your data warehouse with facebook-ads and 100+ more apps and databases available.

facebook-ads
Weld logo
Sign up for free
Weld logo

Tired of scattered data? Build your data warehouse with Weld in minutes with our powerful ELT, SQL Transformations, Reverse-ETL and AI Assistant - connected to 100+ apps, files and databases.

Backed by leading investors
Frontline logoCherry logoInnnovation Fund logo
Twitter LogoLinkedIn Logo
GDPR logoSOC2
© 2023 Weld. All rights reserved.