fb_insights | R Documentation |
This returns all available FB insights per day including any given breakdown to the specified report level, and place into a data frame. For more information on Ad Insights' API, go to the original documentaion.
fb_insights(
token,
which,
start_date = Sys.Date() - 7,
end_date = Sys.Date(),
time_increment = "1",
report_level = "campaign",
ad_object = "insights",
breakdowns = NA,
fields = NA,
filtering = NULL,
limit = 100,
api_version = NULL,
process = TRUE,
async = FALSE,
...
)
token |
Character. Valid access token with sufficient privileges. Visit the Facebook API Graph Explorer to acquire one. |
which |
Character vector. This is the accounts, campaigns, adsets,
or ads IDs to be queried. Remember: if |
start_date , end_date |
Character. The first and last full day to report, in the
format |
time_increment |
Character. Group by months ("monthly"), everything together ("all_days") or an integer per days [1-90]. Default: each day separately (i.e. "1"). |
report_level |
Character. One of "ad", "adset", "campaign", or "account" |
ad_object |
Character. One of: "insights" (default), "adsets", ... |
breakdowns |
Character Vector. One or more of breakdowns for segmentation results. Set to NA for no breakdowns |
fields |
Character, json format. Leave |
filtering |
List. Each filter will be a list containing "field",
"operator", and "value". Read more about the operators in the official
docs.
Example: |
limit |
Integer. Query limit by pagination. |
api_version |
Character. Facebook API version. |
process |
Boolean. Process GET results to a more friendly format? |
async |
Boolean. Run an async query. When set to |
... |
Additional parameters. |
data.frame with un-nested processed results if process=TRUE
or
raw API results as list when process=FALSE
.
Other API:
bring_api()
,
fb_accounts()
,
fb_ads()
,
fb_creatives()
,
fb_process()
,
fb_report_check()
,
fb_rf()
,
fb_token()
,
gemini_ask()
,
gpt_ask()
,
li_auth()
,
li_profile()
,
queryGA()
,
slackSend()
Other Meta:
fb_accounts()
,
fb_ads()
,
fb_creatives()
,
fb_process()
,
fb_report_check()
,
fb_rf()
,
fb_token()
## Not run:
token <- "YOURTOKEN"
which <- "act_20846447"
# Platforms' Insights: all ad-sets platforms of "which" account,
# aggregated, for the last 30 days
platforms <- fb_insights(
token, which,
start_date = Sys.Date() - 30,
time_increment = "all_days",
report_level = "adset",
fields = c(
"account_name",
"adset_id",
"adset_start",
"adset_end"
),
breakdowns = c(
"publisher_platform",
"platform_position",
"device_platform"
)
)
# Daily results for all campaigns of "which" account,
# with custom performance fields with no breakdowns.
insights_adset <- fb_insights(
token, which,
time_increment = "1",
report_level = "campaign",
fields = c(
"adset_id",
"reach",
"frequency",
"spend",
"cpm",
"objective",
"optimization_goal"
)
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.