daroczig / fbRads

Analyze and manage Facebook ads from R using this client library to access their Marketing APIs
GNU Affero General Public License v3.0
153 stars 57 forks source link

fb_insights issue whenever I use breakdowns parameters #120

Closed maxtaind closed 4 years ago

maxtaind commented 4 years ago

Hello!

I'm using this code to retrieve some information using the "fb_insights" function, but when I add the breakdowns parameters (in my case, I used a vector containing "link_url_asset"), I noticed that some information at the ad level cannot be retrieved. For example: I have 3 website_url, so I understand that the answer must be 3 lines containing the 3 url of the sites (or null values). But in this case, my answer is just one line per ad set. Is there another way or am I using the function incorrectly?

Below, there is an example of my request using fb_insights:

fields = c("account_name","campaign_name", "adset_name", 
            "ad_name", "spend","clicks", "impressions", "inline_link_clicks")

fbacc(accountid, token, version = '6.0')

fb_insights(time_range = time_range, time_increment = 1, job_type = 'async', level = 'ad', 
           fields = fields, breakdowns = c('link_url_asset'), simplify = TRUE)

Thanks!

daroczig commented 4 years ago

Hm, I think the fields param should be a JSON array, eg toJSON(c('foo', 'bar'))

But regarding your question -- can you please try the raw API requests at https://developers.facebook.com/tools/explorer and figure out what the breakdown actually do etc and then once you have all the proper parameters there, please share here if you cannot replicate that with the fbRads package and I'll be happy to help.

maxtaind commented 4 years ago

Hm, I think the fields param should be a JSON array, eg toJSON(c('foo', 'bar'))

But regarding your question -- can you please try the raw API requests at https://developers.facebook.com/tools/explorer and figure out what the breakdown actually do etc and then once you have all the proper parameters there, please share here if you cannot replicate that with the fbRads package and I'll be happy to help.

Hi, thanks for your help. The breakdown parameter actually breaks the result of the Google Insights response, bringing additional values like website_url for each ad within a specific ad_set (for example, if an ad_set contains 3 ads, the API response should be a list containing 3 website_url). The raw API request is:

https://graph.facebook.com/v6.0/act_account_id/insights?level=ad&fields=fields_parameters&breakdowns=link_url_asset

There is something mysterious about using this parameter: when I add the breakdowns parameter with fbRads, the package returns only one response for ad set and when I try to replicate the same request using Python/requests, I receive an empty response data.

daroczig commented 4 years ago

Please reopen when you managed to replicate the issue via the API explorer or a curl client (such as Python/requests) and provide more info, meanwhile, I'm closing this as I don't think I can be much help.

dsolito commented 4 years ago

Had a problem with breakdowns= c("age", "gender"). API returned only one of. As @daroczig said, this code work for me.

breakdowns = rjson::toJSON(c("age", "gender"))