facebook / facebook-php-business-sdk

PHP SDK for Meta Marketing API
https://developers.facebook.com/docs/business-sdk
Other
833 stars 516 forks source link

Retrieve conversion values like Leads, AddToCart, AddPaymentInfo, etc... #418

Closed czmarcos closed 6 years ago

czmarcos commented 6 years ago

Is there any endpoint where I can retrieve conversion values of adsets for custom conversions like Leads, AddToCart, AddPaymentInfo, etc...?

czmarcos commented 6 years ago

Solved

Conversion values can be extracted through actions and actions_values fields:

https://developers.facebook.com/docs/marketing-api/reference/ad-campaign/insights/

freshface commented 6 years ago

Is it possible you could provide an example how to use this in the facebook php ad sdk?

czmarcos commented 6 years ago

Sure, use the getInsights endpoint and add the ACTIONS field.

https://developers.facebook.com/docs/marketing-api/reference/ad-campaign/insights/

Quick example:

$params = array(
                        'time_range' => array(
                                        'since' => $today,
                                        'until' => $today,
                        ),
                        'level' => 'adset',
                        'limit' => '500'
                        );

    $fields = array(
                        AdsInsightsFields::ADSET_NAME,
                        AdsInsightsFields::ADSET_ID,
                        AdsInsightsFields::CAMPAIGN_NAME,
                        AdsInsightsFields::CAMPAIGN_ID,                          
                        AdsInsightsFields::ACTIONS
                        );

    $insights = $account->getInsights($fields, $params);

    foreach ($insights as $insight) { 

      // here you have the list of all actions of your adset (eg: clicks, conversions, add_to_cart, purchases, engagements, lead, etc)

      $insight->{AdsInsightsFields::ACTIONS};

    }
freshface commented 6 years ago

thx!