facebook / facebook-ruby-business-sdk

Ruby SDK for Meta Marketing API
https://developers.facebook.com/docs/business-sdk
Other
208 stars 161 forks source link

Include insights in call to account campaigns #88

Closed kickbk closed 4 years ago

kickbk commented 4 years ago

Is there a way to use nested requests to grab insights for each adset like so?

params = {
    'time_range': {
        'since': '2019-08-01',
        'until': '2019-08-31',
    }
}
ad_account.campaigns(fields: ['adsets{id, insights{spend, impressions}}'], params: params).to_json

Or in other words - Facebook, please get all the adsets in each campaign, and for each adset, please include insights for a specific date range.

How does one request this? It would be wasteful to grab the ID of each adset and then do a call to adset.insights

rubyalanis commented 4 years ago

https://www.facebook.com/help/publisher/372100366658322

kickbk commented 4 years ago

So, surprisingly, Facebook DOES return insights with my call. Sometimes. No explanation why, but I tried with two accounts and got on one account insights and the other not. Maybe it has something to do with the insights returned with this call have a shorter lifespan, so you can't get insights for older ads. Not sure. Not going to read through the million of pages.

My solution, for whoever is interested. I made a call to adaccount insights directly, and specified the level as 'ad' so ir will return insights for all the account ads. I also requested the 'ad_id'. Later I was able to match the results returned with this call to the previous call I mentioned by comparing the ad ID, and merge the results.

ad_account.insights(
    fields: ['ad_id', 'spend', 'impressions', 'clicks', 'ctr', 'cpc'], 
    level: 'ad',
    time_range: {
        since: date_since,
        until: date_until
    }
).to_json
stale[bot] commented 4 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.