rfacebookstat (version 2.1.7)

fbGetMarketingStat: Get statistic by ad accounts.

Description

fbGetMarketingStat is main function of rfacebookstat package, intended for load statiscit data by your ad, adset, campaign or account

Usage

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 = Sys.Date() - 30,
    date_stop = Sys.Date(), attribution_window = NULL,
	api_version = getOption("rfacebookstat.api_version"), 
	action_report_time = NULL, interval = "day", 
	console_type = "progressbar", request_speed = "normal",
    username = getOption("rfacebookstat.username"),
    token_path = fbTokenPath(),	
	access_token = getOption("rfacebookstat.access_token"))

Arguments

accounts_id

ID of your ad account.

sorting

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.

level

Represents the level of result. Avable ad, adset, campaign, account.

action_breakdowns

group results in the actions field. You can use the following breakdowns for action_breakdowns, for details go, or see details

breakdowns

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.

fields

List of fields which you want get in R. You can find list of available fields at Facebook API documentation by this link.

filtering

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

date_start

Start reporting date.

date_stop

End reporting day

attribution_window

The conversion attribution window provides timeframes that define when we attribute an event to an ad on Facebook. See Attribution Window sections.

request_speed

Speed beetwen API request, "normal", "fast" or "slow", depend of you API access level.

api_version

Current Facebook API version.

action_report_time

Determines the report time of action stats.

interval

Character value for split by time interval, one of "day", "week", "month", "quarter", "year". By default = "day"

console_type

Character value for manage console output message, one of "progressbar", "message". By default = "progressbar". See more at Detail

username

your username on Facebook

token_path

path to dir with credentials

access_token

Your facebook API token

Value

Data frame with statistic.

Breakdowns

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

Action Breakdowns

Group results in the actions field. You can use the following breakdowns for action_breakdowns. Now you can use next action breakdowns:

action_device

The device on which the conversion event you're tracking occurred. For example, "Desktop" if someone converted on a desktop computer.

action_destination

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).

action_reaction

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.

action_target_id

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).

action_type

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.

action_type,action_reaction

Together of action types and reactions brekdown.

Available Combinations Of Breakdowns

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 *

Attribution Window

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.

account_default

Use the account level attribution window setting

default

The FB default attribution window is 1 day views, 28 day clicks

inline

Inline attribution only (0 day views, 0 day clicks)

1d_view

1 day views, 0 day clicks

7d_view

7 day views, 0 day clicks

28d_view

28 day views, 0 day clicks

1d_click

0 day views, 1 day clicks

7d_click

0 day views, 7 day clicks

28d_click

0 day views, 28 day clicks

1d_view_1d_click

1 day views, 1 day clicks

7d_view_1d_click

7 day views, 1 day clicks

28d_view_1d_click

28 day views, 1 day clicks

1d_view_7d_click

1 day views, 7 day clicks

1d_view_28d_click

1 day views, 28 day clicks

28d_view_28d_click

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')

Filtering

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

Field for filtering.

operator

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.

value

Field value for filtering.

Simple filtring:

Example vector

filtering = "publisher_platform IN instagram"

Example JSON

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:

Example vector

filtering = c("clicks LESS_THAN 500", "impressions GREATER_THAN 20000")

Example JSON

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

Example vector

filtering = 'publisher_platform IN instagram,facebook'

Example JSON

filtering = '[{"field":"publisher_platform","operator":"IN","value":["instagram","facebook"]}]'

Details

Console_type parameters, if chose "progressbar" you can see load progress in percent, and if chose "message" you get message about loading process.

See Also

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.

Examples

Run this code
# NOT RUN {
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 DataCamp Workspace