getAny: Get data on any object

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/getAny.R

Description

Get insights on advertising performances of an ad, an adset, a campaign or even an account. This function may relace any other GET function in this package.

Usage

1
2
3
4
getAny(id, token, fields = "default", n = 100, action.attribution.windows,
  action.breakdowns, action.report.time, breakdowns, date.preset, level,
  time.increment, time.range, summary = FALSE, verbose = FALSE,
  limit = 100)

Arguments

id

The id of the object you want to retrieve (Required), see how to find yours.

token

A valid token as returned by fbAuthenticate or a short-term token from facebook Graph API Explorer.

fields

There are in total 73 valid fields defaults to (default) which returns the most popular ones. Run findFields to see all valid fields.

n

Number of results to retrieve, defaults to 100. When you make an API request, you will usually not receive all of the results of that request in a single response. This is because some responses could contain thousands of objects so most responses are paginated by default.

action.attribution.windows

Determines what is the attribution window for the actions. For example, c("28d_click") means the API returns all actions that happened 28 days after someone clicked on the ad (Optional). See details below for valid values.

action.breakdowns

How to break down action results. Supports more than one breakdowns (Optional). Run findParams to see all valid action breakdowns.

action.report.time

Determines the report time of action stats. For example, if a person saw the ad on Jan 1st but converted on Jan 2nd, when you query the API with action.report.time="impression", you will see a conversion on Jan 1st. When you query the API with action.report.time="conversion", you will see a conversion on Jan 2nd (Optional).

breakdowns

How to break down the result. Does not support more than one breakdown, except c("age", "gender") and "impression_device", "placement". The option impression_device cannot be used by itself (Optional). Run findParams to see all valid breakdowns.

date.preset

Represents a relative time range (Optional). This field is ignored if time.range is specified. Run findParams to see all valid presets.

level

Represents the level of result (Optional). Must be one of ad, adset, campaign, account.

time.increment

If it is an integer, it is the number of days from 1 to 90. After you pick a reporting period by using time.range or date.preset, you may choose to have the results for the whole period, or have results for smaller time slices. If "all_days" is used, it means one result set for the whole period. If "monthly" is used, you will get one result set for each calendar month in the given period. Or you can have one result set for each N-day period specified by this param.

time.range

time range must be c(since = 'YYYY-MM-DD', until='YYYY-MM-DD')

summary

Default value: FALSE Determine whether to return a summary section with the same fields as specified by fields will be included in the summary section. If TRUE the data structure returned will be of type list (see @return below)

verbose

Defaults to FALSE if TRUE will print information on the queries in the console.

limit

Number of results requested at each API call, defaults to 100. Sometimes useful to bring it down if many results (n) are required as the API might otherwise return error_code: 1 or in other words an "Unknown error".

Details

This function refers to the following API call https://developers.facebook.com/docs/marketing-api/reference/ad-account/insights/, it is strongly encouraged to have a look a the latter link. only the following parameters are not available default_summary, filtering, summary, sort and time_ranges.

getAny may replace any other GET function. Indeed all functions share the same parameters and fields, the data that is returned solely depend on the object id the functions is fed. See examples.

Value

Note that if summary is TRUE the function returns a list

Author(s)

John Coene jcoenep@gmail.com

See Also

fbAuthenticate, findParams, grabAds, grabAdsets, grabCampaigns

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
## Not run: 
# run authentication with your app details
fbOAuth <- fbAuthenticate(app.id = "1234567890123456", 
                          app.secret = "76xx79121xx0130x2x10a08x3e2x80xx", 
                          scope = "ads_management")
                          
# get ads on account
ads <- grabAds(id = "act_1014262775316748", token = TK)

# get adsets on account
adsets <- grabAdsets(id = "act_1014262775316748", token = TK)

# get ads on account
camp <- grabCampaigns(id = "act_1014262775316748", token = TK)

# get date.preset (this quarter)
date <- findParams("date.preset")[grep("quarter", findParams("date.preset"))]

# fetch Ad data
dat <- getAny(id = sample(ads$id, 1), token = TK, date.preset = date)

# fetch Adset data
dat <- getAny(id = sample(adsets$id, 1), token = TK, date.preset = date)

# fetch Campaign data
dat <- getAny(id = sample(campaigns$id, 1), token = TK, date.preset = date)

# fetch Account data
dat <- getAny(id = "act_1014262775316748", token = TK, date.preset = date)

## End(Not run)

JohnCoene/fbadsinsightsr documentation built on May 28, 2019, 12:55 p.m.