Learn R Programming

rfacebookstat (version 2.11.0)

fbGetCostData: Get facebook ads cost data.

Description

Get cost data for loading it into Google Analytics

Usage

fbGetCostData(
    accounts_id = getOption("rfacebookstat.accounts_id"),
    date_start         = Sys.Date() - 30,
    date_stop          = Sys.Date(),
    utm_source         = "facebook",
    utm_medium         = "cpc",
    username           = getOption("rfacebookstat.username"),
    token_path         = fbTokenPath(),
    access_token       = getOption("rfacebookstat.access_token"))

Value

Data frame with statistic.

Arguments

accounts_id

ID of your ad account.

date_start

Start reporting date.

date_stop

End reporting day

utm_source

UTM source name for Google Analytics.

utm_medium

UTM medium name for Google Analytics.

username

your username on Facebook

token_path

path to dir with credentials

access_token

Your facebook API token

Author

Alexey Seleznev

Details

Before loading data create data source at Google Analytics.

Examples

Run this code
if (FALSE) {

# Use googleAnalyticsR for upload data into Google Analytics
library(googleAnalyticsR)

# load cost data
cost_data <- fbGetCostData(accounts_id = "act_11111",
                           date_start  = "2020-05-10", 
                           date_stop   = "2020-05-14",
                           username    = "fb_login")
                              
# upload into GA source
ga_custom_upload_file(accountId          = xxxx, 
                      webPropertyId      = "UA-xxxx-1", 
                      customDataSourceId = 'abcdefg', 
                      cost_data)
}

Run the code above in your browser using DataLab