1) The document provides an overview of the Facebook advertising API and how to get started using it. It discusses the different access levels for the API, how to authorize and get an access token, and examples of creating advertising campaigns, ad sets, ads and targeting audiences using the API.
2) It also covers important concepts like bidding and object specs needed to define ads, and recommends ways to familiarize yourself with targeting specs and estimating reach through the API.
3) The document aims to help developers understand how to leverage the Facebook advertising API to programmatically create and manage ad campaigns at scale.
51. Increasing Reach While Maintaining CPI/ROI
Tiered Lookalike Strategy
Entire
Country
Population
Sorted By
Descending
Likeness To
Seed Audience
Top 1%
Top 3%
Top 5%
52. Manual Steps
1. Create a custom audience
2. Create 1% lookalike
3. Repeat for 3% and 5%
4. Create adset using 1% lookalike
5. Create adset using 3% lookalike, exclude 1% lookalike, bid lower
6. Create adset using 5% lookalike, exclude 3% lookalike, bid lower
7. Don't forget cross-device tracking!
8. Repeat 1- 7 for other seed audiences
9. Repeat 1- 8 for other countries
56. Manual Steps
1.Open saved report in Facebook ads reports
2.Refresh data
3.Export to ?le
4.Open Excel
5.Import ?le
6.Save spreadsheet
7.Repeat daily
8.Everyone does this!
57. Not finish yet
Big team will have hierarchy reporting
Each team member takes care of his own
Someone takes care of summary
This can go up
Different team in different product category takes care of its summary
Someone takes care of teams' summary
Then what if any one got the number wrong? (typo, copy/paste missing)
58. A Better Pipeline
1.Open saved report in Facebook ads reports One command to
retrieve insights to mysql
2.Refresh data
3.Export to ?le
4.Open Excel
5.Import ?le
6.Save spreadsheet Hit refresh button to refresh from mysql
7.Repeat daily
8.Everyone Build a robot to does this!
59. ########################## main ##########################
# get all ad campaign from an ad account
if not db_unix_socket == '':
con = mdb.connect(host='localhost', user=db_username,
db=db_name, unix_socket=db_unix_socket, charset='utf8')
else:
con = mdb.connect(host=db_host, port=db_port,
user=db_username, passwd=db_password,
db=db_name, charset='utf8')
with con:
deleteAdSetsInsight(con, report_date)
for my_ad_account_id in my_ad_account_ids:
ad_account = AdAccount(my_ad_account_id)
fields = [
'campaign_group_name',
'campaign_name',
'campaign_id',
'impressions',
'clicks',
'spend',
'reach',
'actions',
'action_values'
]
params = {
'time_range': {
'since': report_date,
'until': report_date
},
'action_attribution_windows': ['28d_click'],
'breakdowns': ['impression_device', 'placement'],
'level': 'campaign',
'limit': max_records
}
ad_insights = ad_account.get_insights(fields, params)
print('Number of insight records:' + str(len(ad_insights)))
count = 0
for idx in range(0,min(max_records,len(ad_insights))):
ad_insight = ad_insights[idx]
print('Writing record number: ' + str(idx))
writeAdInsight(ad_insight, con, report_date)
59
def writeAdInsight(ad_insight, con, report_date):
impression_device = 0
if 'impression_device' in ad_insight:
impression_device = ad_insight['impression_device']
action_device = 0
if 'action_device' in ad_insight:
action_device = ad_insight['action_device']
key_value = {
'start_date': report_date,
'end_date': report_date,
'campaign': ad_insight['campaign_group_name'],
'adset': ad_insight['campaign_name'],
'adset_id': ad_insight['campaign_id'],
'impressions': ad_insight['impressions'],
'clicks': ad_insight['clicks'],
'spend': ad_insight['spend'],
'reach': ad_insight['reach'],
'impression_device': impression_device,
#'conversion_device': action_device
}
if 'actions' in ad_insight:
actions = ad_insight['actions']
for action in actions:
t = action['action_type']
if t in action_type_columns:
key_value[action_type_columns[t]] = action['28d_click']
if 'action_values' in ad_insight:
action_values = ad_insight['action_values']
for action_value in action_values:
t = action['action_type']
if t in action_value_columns:
key_value[action_value_columns[t]] = action['28d_click']
key_str = ""
value_str = ""
count = 0
for (key, value) in key_value.items():
if count > 0:
key_str += ", "
value_str += ", "
key_str += key
value_str += """ + unicode(value) + """
count += 1
stat = "INSERT INTO ad_set_insight (" + key_str + ") VALUES (" + value_str + ")";
print stat
cur = con.cursor()
cur.execute(stat)