Weld logo
snapchat-ads logo
Snapchat ads

Ad Report

Generates an ad report by integrating with Snapchat Ads. It retrieves data from various tables such as ad_daily_report, campaign, ad_account, and ad. The report includes information such as date, account ID and name, campaign ID and name, ad ID and name, currency, spend, impressions, clicks, CPC, CTR, CPM, and conversions. The data is filtered based on the date and grouped by different columns.
1with
2    report as (
3        select
4            *
5        from
6            {{raw.snapchat_ads.ad_daily_report}}
7    )
8  , account as (
9        select
10            *
11        from
12            {{raw.snapchat_ads.ad_account}}
13    )
14  , ads as (
15        select
16            *
17        from
18            {{raw.snapchat_ads.ad}}
19    )
20  , creative as (
21        select
22            *
23        from
24            {{raw.snapchat_ads.creative}}
25    )
26select
27    cast(report.date as date) as date_day
28  , account.ad_account_id as account_id
29  , account.name as account_name
30  , report.ad_id
31  , ads.name ad_name
32  , creative.name as creative_name
33  , creative.id as creative_id
34  , account.currency
35  , safe_divide(spend, 1000000) spend
36  , report.impressions as impressions
37  , report.swipes as clicks
38  , conversion_purchases as conversions
39  , conversion_purchases_value as conversion_value
40from
41    report
42    left join ads on report.ad_id = ads.id
43    left join account on ads.ad_account_id = account.id
44    left join creative on creative.id = ads.creative_id
45where
46    cast(report.date as date) <= current_date()
Example of output from model:
+------------+------------+--------------+-------------+----------------+--------+----------------+----------+-------+-------------+-------+---------+---------+--------------+
| date_day   | account_id | account_name | campaign_id | campaign_name  | ad_id  | ad_name        | currency | spend | impressions | clicks| cpc     | ctr     | cpm          |
+------------+------------+--------------+-------------+----------------+--------+----------------+----------+-------+-------------+-------+---------+---------+--------------+
| 2022-01-01 | 123456     | Example Ads   | 987654      | Campaign XYZ   | 789012 | Ad 1           | USD      | 10.50 | 1000        | 50    | 0.21    | 0.05    | 10.50        |
| 2022-01-01 | 123456     | Example Ads   | 987654      | Campaign XYZ   | 789012 | Ad 2           | USD      | 15.75 | 1500        | 75    | 0.21    | 0.05    | 10.50        |
| 2022-01-01 | 123456     | Example Ads   | 987654      | Campaign XYZ   | 789012 | Ad 3           | USD      | 20.00 | 2000        | 100   | 0.20    | 0.05    | 10.00        |
| 2022-01-02 | 123456     | Example Ads   | 987654      | Campaign XYZ   | 789012 | Ad 1           | USD      | 12.00 | 1200        | 60    | 0.20    | 0.05    | 10.00        |
| 2022-01-02 | 123456     | Example Ads   | 987654      | Campaign XYZ   | 789012 | Ad 2           | USD      | 18.00 | 1800        | 90    | 0.20    | 0.05    | 10.00        |
| 2022-01-02 | 123456     | Example Ads   | 987654      | Campaign XYZ   | 789012 | Ad 3           | USD      | 24.00 | 2400        | 120   | 0.20    | 0.05    | 10.00        |
+------------+------------+--------------+-------------+----------------+--------+----------------+----------+-------+-------------+-------+---------+---------+--------------+

Combines data from multiple tables, including ad_daily_report, campaign, ad_account, and ad, to generate a comprehensive report. The template begins by creating temporary tables using the "with" clause. These tables include "report," which contains data from the ad_daily_report table, "creatives," which contains data from the campaign table, "account," which contains data from the ad_account table, and "ads," which contains data from the ad table. The main query then selects various fields from these temporary tables, such as the date, account ID and name, campaign ID and name, ad ID, ad name, currency, spend, impressions, clicks, CPC (cost per click), CTR (click-through rate), CPM (cost per thousand impressions), and conversions. To generate the report, the main query performs left joins between the temporary tables based on their respective relationships. The "where" clause filters the data to include only records with a date less than or equal to the current date. Finally, the results are grouped by the selected fields, providing a summarized view of the advertising performance. This SQL template can be useful for analyzing ad campaign effectiveness, monitoring spending, tracking conversions, and optimizing advertising strategies on Snapchat Ads.

Ready to start modeling your own snapchat-ads data?

Get started building your data warehouse with snapchat-ads and connect all your apps and databases.

snapchat-ads logo
Weld logo
Sign up for free
Weld logo

Tired of scattered data? Sync your data in minutes with our AI-powered ETL platform. Seamlessly connect all your apps, files, and databases.

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