Learn R Programming

fbRads

This R package includes wrapper functions around the Facebook Marketing API to create, read, update and delete custom audiences, images, campaigns, adsets, ads and related content.

For more details, see the slides presented at useR! 2015, the Los Angeles R Users Group and at a Domino Webinar.

Creating a Facebook App & connect with OAuth token

To be able to use this package, you will have to create a Facebook App and authorize it to manage your Facebook ads. Basic steps to create an app with Development access level letting you manage up to 5 Facebook ad accounts:

  1. Click on "Add a New App" at https://developers.facebook.com/apps

  2. Fill in a unique Display Name (eg "app_testing_foobar_42"), and provide your e-mail address. Click on "Create App ID" & pass the captcha test.

  3. Select the "Implement Marketing API" scenario that will automatically add the "Marketing API" to the "Products" section of the sidebar, or click on the "+" butting in the "Products" section of the sidebar

  4. Optionally associate your app with a Business Manager in the "Settings" screen of the "Marketing API"

  5. In the sidebar, select "Tools" from the "Marketing API" and generate a token

  6. Store your token in a secure place, and you are all set to start using fbRads, eg list all the Ad Account ids you can access:

    accounts <- fbad_get_my_ad_accounts(token)
  7. Pick an Ad Account id from the returned list and initialize fbRads to use that Ad Account by default:

    account <- sample(accounts$account_id, 1)
    fbad_init(accountid = account, token = token)
  8. Then list all your ads along with the ad name and status on that Ad Account:

    fbad_list_ad(fields = c('name', 'effective_status'))
  9. Or eg filter for the active ads:

    fbad_list_ad(statuses = 'ACTIVE', fields = 'name')

Development version

The package is actively maintained, but not frequently pushed to CRAN, so to use the most recent version, install from GitHub. The master branch is supposed to include a relatively stable version at all the time:

devtools::install_github('daroczig/fbRads')

Using the package

This package makes your life more convenient when it comes to interacting with the Facebook Marketing API, but unfortunately, it cannot save you the time to get familiar with the actual API endpoints. To be able to interact with Facebook, you have to learn about how the API works etc -- see the documentation at https://developers.facebook.com/docs/marketing-apis


This package was originally developed at CARD.com, then maintained at System1. If you are interested in taking over the maintenance of this R package, please open a GH ticket.

Copy Link

Version

Install

install.packages('fbRads')

Monthly Downloads

267

Version

17.0.0

License

AGPL-3

Issues

Pull Requests

Stars

Forks

Last Published

August 20th, 2023

Functions in fbRads (17.0.0)

fbad_create_ad

Create ad
fbad_get_adaccount_details

Get details for a Facebook Ads Account
fbad_get_adaccounts

Deprecated in favor of fbad_get_owned_adaccounts
fbad_reachestimate

Query for reach estimate for given targeting spec
fbad_get_search

FB Search API Querying
fbad_init

Initiate Facebook Account with OAuth token
fbad_read_ad

Read ad details
fbad_get_client_pages

Get account details of Pages belonging to the clients of a Business Manager Account
fbad_get_client_ad_accounts

Get account details of Ad Accounts belonging to the clients of a Business Manager Account
fbad_list_ad

List all Ads for current account, list of Ad Sets or Campaigns
fbad_insights_get_async_results

Wait for and get asynchronous report results
fbad_create_adset

Create Ad Set
fbad_create_campaign

Created Ad Campaign
fbad_get_pixels

Get tracking pixels of eg an Ad or Business Manager Account
fbad_list_campaign

List all Ad Campaigns for current account
fbad_get_owned_pages

Get account details of Pages owned by a Business Manager Account
fbad_preview_ad

Preview ad
fbad_share_audience

Share a FB custom audience with other accounts
fbad_request_next_page

Fetch the content of the URL and return JSON
fbad_read_adset

Read Ad Set details
fromJSONish

Validates and fixes some JSON issues, eg removing newlines etc
fbad_get_my_ad_accounts

Get account details of Ad Accounts that are accessible by the given token
fbad_remove_audience

Add people from a custom FB audience
is.FB_Ad_Account

Checks if object is a valid initialized connection to the Facebook Marketing API
fbad_get_owned_ad_accounts

Get account details of Ad Accounts owned by a Business Manager Account
fbad_whoami

Prints user id and name
fbad_update_campaign

Update Ad Campaign
fbad_list_adset

List all Ad Sets for current account or Ad Campaign(s)
fbad_update_adset

Update Ad Set
fbad_request

Get results of a synchronous query from FB graph API
fbad_update_ad

Update ad
fbad_list_audience

List all Custom Audiences for Ad account
print.FB_Ad_Account

Print method for custom fbRads class
url_parse

Parse Facebook URL without bringing in another dependency. Might change this for urltools or httr
fbad_read_campaign

Read Ad Campaign details
fbad_read_creative

Read ad creative
fbad_read_audience

Read metadata on a FB custom audience
this_function_name

Return the name of the parent function
fbad_add_audience

Add people to a custom FB audience
fbad_copy_ad

Create a copy of an ad.
fb_api_version

Returns the currently used version of the Facebook Marketing API
fbad_check_fbacc

Check if provided or previously initialized R object is a valid FB Ad Account
fbad_check_curl_params

Run basic checks on curl get/post parameters
fb_insights

Insights
fbad_copy_adset

Create a copy of an ad set. You can copy a maximum of 3 entities between ad set and ads.
fbad_create_audience

Create a new FB custom audience
fbad_assign_users_to_account

Assign a user to an Ad Account
fbad_create_lookalike_audience

Create a new FB lookalike audience similar to an already existing custom audience
fbad_delete_audience

Delete a FB custom audience
fbad_create_creative

Create an ad creative
fbRads

fbRads package
fb_api_most_recent_version

Returns the most recent version of the supported Facebook Marketing API
fbad_copy_campaign

Create a copy of a campaign. You can copy a maximum of 3 entities between campaign, ad sets and ads.
fbad_create_image

Upload image
fbad_create_account

Create Ad Account