fbGetMarketingStat is main function of rfacebookstat package, intended for load statiscit data by your ad, adset, campaign or account
fbGetMarketingStat(
accounts_id = getOption("rfacebookstat.accounts_id"),
sorting = NULL, level = "account", breakdowns = NULL,
action_breakdowns = NULL,
fields = "account_id,campaign_name,impressions,clicks,reach,spend",
filtering = NULL, date_start = NULL,
date_stop = NULL, date_preset = "last_30d",
attribution_window = NULL,
api_version = getOption("rfacebookstat.api_version"),
action_report_time = NULL, interval = "day",
use_unified_attribution_setting = FALSE,
use_account_attribution_setting = FALSE,
console_type = "progressbar", request_speed = "normal",
fetch_by = NULL,
username = getOption("rfacebookstat.username"),
token_path = fbTokenPath(),
access_token = getOption("rfacebookstat.access_token"))
Data frame with statistic.
ID of your ad account.
Field to sort the result, and direction of sorting. You can specify sorting direction by appending "_ascending" or "_descending" to the sort field. For example, "reach_descending". This array supports no more than one element. By default, the sorting direction is ascending.
Represents the level of result. Avable ad, adset, campaign, account.
group results in the actions field. You can use the following breakdowns for action_breakdowns, for details go, or see details
Permutations marked with an asterisk (*) can be joined with action_type and action_target_id. Avable age, country, gender, frequency_value, hourly_stats_aggregated_by_advertiser_time_zone, hourly_stats_aggregated_by_audience_time_zone, impression_device, place_page_id, placement, device_platform, product_id, region. See details.
List of fields which you want get in R.
Vector of filtring or JSON string with array of filtring parameters, on example "ad.effective_status IN ARCHIVED"
[{/'field/':/'ad.effective_status/',/'operator/':/'IN/',/'value/':[/'ARCHIVED/']}
, see filtring block for more examples
Start reporting date.
End reporting day
Represents a relative time range. This field is ignored if time_range or time_ranges is specified. One of: today, yesterday, this_month, last_month, this_quarter, lifetime, last_3d, last_7d, last_14d, last_28d, last_30d, last_90d, last_week_mon_sun, last_week_sun_sat, last_quarter, last_year, this_week_mon_today, this_week_sun_today, this_year
The conversion attribution window provides timeframes that define when we attribute an event to an ad on Facebook. See Attribution Window sections.
Speed beetwen API request, "normal", "fast" or "slow", depend of you API access level.
Character, split your requst by time interval, one of: day, week, month, quarter, year.
Current Facebook API version.
Determines the report time of action stats.
Character value for split by time interval, one of "day", "week", "month", "quarter", "year". By default = "day"
When this parameter is set to true, your ads results will be shown using unified attribution settings defined at ad set level and parameter use_account_attribution_setting will be ignored.
When this parameter is set to true, your ads results will be shown using the attribution settings defined for the ad account.
Character value for manage console output message, one of "progressbar", "message". By default = "progressbar". See more at Detail
your username on Facebook
path to dir with credentials
Your facebook API token
Allowed values for breakdowns.
ad_format_asset
age
body_asset
call_to_action_asset
country
description_asset
gender
image_asset
impression_device
link_url_asset
product_id
region
title_asset
video_asset
dma
frequency_value
hourly_stats_aggregated_by_advertiser_time_zone
hourly_stats_aggregated_by_audience_time_zone
place_page_id
publisher_platform
platform_position
device_platform
Group results in the actions field. You can use the following breakdowns for action_breakdowns. Now you can use next action breakdowns:
The device on which the conversion event you're tracking occurred. For example, "Desktop" if someone converted on a desktop computer.
The destination where people go after clicking on your ad. This could be your Facebook Page, an external URL for your conversion pixel or an app configured with the software development kit (SDK).
The number of reactions on your ads or boosted posts. The reactions button on an ad allows people to share different reactions on its content: Like, Love, Haha, Wow, Sad or Angry.
The id of destination where people go after clicking on your ad. This could be your Facebook Page, an external URL for your conversion pixel or an app configured with the software development kit (SDK).
The kind of actions taken on your ad, Page, app or event after your ad was served to someone, even if they didn't click on it. Action types include Page likes, app installs, conversions, event responses and more.
Together of action types and reactions brekdown.
Grouping types marked with an asterisk (*) can be combined with action_type, action_target_id, and action_destination (action_target_id).
action_type *
action_target_id *
action_device *
action_device, impression_device *
action_device, publisher_platform *
action_device, publisher_platform, impression_device *
action_device, publisher_platform, platform_position *
action_device, publisher_platform, platform_position, impression_device *
action_reaction
action_type, action_reaction
age *
gender *
age, gender *
country *
region *
publisher_platform *
publisher_platform, impression_device *
publisher_platform, platform_position *
publisher_platform, platform_position, impression_device *
product_id *
The conversion attribution window provides time intervals that determine the attribution period of an event for advertising on Facebook.
For background information, see Facebook Ads Help Center, How Attribution Reporting Works. We measure the actions that occur when a conversion event occurs and look back in time 1-day, 7-days, and 28 days.
To view actions attributed to different attribution windows, use attribution_window
.
Use the account level attribution window setting
The FB default attribution window is 1 day views, 28 day clicks
Inline attribution only (0 day views, 0 day clicks)
1 day views, 0 day clicks
7 day views, 0 day clicks
28 day views, 0 day clicks
0 day views, 1 day clicks
0 day views, 7 day clicks
0 day views, 28 day clicks
1 day views, 1 day clicks
7 day views, 1 day clicks
28 day views, 1 day clicks
1 day views, 7 day clicks
1 day views, 28 day clicks
28 day views, 28 day clicks
Also you can get more than one attribution window in one request, for example attribution_window = c('default', '1d_view', '28d_view', '28d_click')
Filters on the report data. This parameter is an array of filter objects. You can set string vector or JSON string with field, operator and value.
Field for filtering.
One of EQUAL, NOT_EQUAL, GREATER_THAN, GREATER_THAN_OR_EQUAL, LESS_THAN, LESS_THAN_OR_EQUAL, IN_RANGE, NOT_IN_RANGE, CONTAIN, NOT_CONTAIN, IN, NOT_IN, STARTS_WITH, ANY, ALL, AFTER, BEFORE, NONE.
Field value for filtering.
Simple filtring:
filtering = "publisher_platform IN instagram"
filtering = "[{'field':'publisher_platform','operator':'IN','value':['instagram']}]"
Example of using two or more conditions: filtering = "[{'field':'clicks','operator':'LESS_THAN','value':500},{'field':'impressions','operator':'GREATER_THAN','value':20000}]"
Filtring by two or more conditions:
filtering = c("clicks LESS_THAN 500", "impressions GREATER_THAN 20000")
filtering = '[{"field":"clicks","operator":"LESS_THAN","value":"500"},{"field":"impressions","operator":"GREATER_THAN","value":"20000"}]'
Filtring with operators IN_RANGE, NOT_IN_RANGE, IN, NOT_IN
filtering = 'publisher_platform IN instagram,facebook'
filtering = '[{"field":"publisher_platform","operator":"IN","value":["instagram","facebook"]}]'
Alexey Seleznev
Console_type parameters, if chose "progressbar" you can see load progress in percent, and if chose "message" you get message about loading process.
All avable field, and discription of all parameters you can see oh this link. More information about breakdowns and action brekdowns on this link. More information about action field in this documentation.
if (FALSE) {
fbStat <- fbGetMarketingStat(accounts_id = "act_xxxxxxxxxxxxxxx",
level = "campaign",
fields = "account_name,campaign_name,impressions",
breakdowns = "device_platform",
date_start = "2016-08-01",
date_stop = "2016-08-10",
interval = "day",
access_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
}
Run the code above in your browser using DataLab