Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getInsightsAsync fields parameter not working #157

Closed
mtricht opened this issue Nov 30, 2015 · 6 comments
Closed

getInsightsAsync fields parameter not working #157

mtricht opened this issue Nov 30, 2015 · 6 comments
Labels

Comments

@mtricht
Copy link

mtricht commented Nov 30, 2015

The fields ($fields = []) parameter of the method getInsightsAsync does not work. It is not correctly passed to the API endpoint. See the following examples.

cUrl (working)

Requesting an async report:

curl \
-F "time_increment=1" \
-F "time_range={'since': '2015-11-01', 'until': '2015-11-01'}" \
-F "level=adgroup" \
-F "fields=['adgroup_id', 'adgroup_name', 'spend', 'campaign_name']" \
-F "access_token=***" \
-F "appsecret_proof=***" \
https://graph.facebook.com/v2.4/act_XXX/insights

Once the async report is finished, it return the following as expected: (Example report ID 6034279794948)

array(
        'date_start' => '2015-11-01',
        'date_stop' => '2015-11-01',
        'adgroup_id' => 'XXX',
        'adgroup_name' => 'Adgroup name here',
        'campaign_name' => 'Campaign name here',
        'impressions' => '11611',
        'clicks' => (int) 3,
        'spend' => (float) 1.21
    )
}

PHP SDK (not working)

Requesting report:

$facebookAdAccount->getInsightsAsync(
    [
        InsightsFields::ADGROUP_ID,
        InsightsFields::CLICKS,
        InsightsFields::IMPRESSIONS,
        InsightsFields::SPEND,
        InsightsFields::ADGROUP_NAME,
        InsightsFields::CAMPAIGN_NAME
    ],
    array(
        'time_increment' => 1,
        'time_range' => array(
            'since' => $dateStart->format('Y-m-d'),
            'until' => $dateEnd->format('Y-m-d')
        ),
        'level' => InsightsLevels::ADGROUP,
    )
);

Result:
Fields array is ignored. Result contains the following fields:

action_values, actions_results, actions, actions_per_impression, unique_actions, adgroup_bid_type, adgroup_bid_value, adgroup_delivery, attention_score, app_store_clicks, call_to_action_clicks, campaign_budget_value, campaign_budget_type, card_views, clicks, unique_clicks, cost_per_action_type, cost_per_action_result, cost_per_inline_post_engagement, cost_per_inline_link_click, cost_per_result, cost_per_total_action, cost_per_unique_action_type, cost_per_10_sec_video_view, cpc, cost_per_unique_click, cpm, cpp, ctr, unique_ctr, date_start, date_stop, deeplink_clicks, dwell_3_sec, dwell_5_sec, dwell_7_sec, estimated_ad_recallers, estimated_ad_recallers_lower_bound, estimated_ad_recallers_upper_bound, estimated_ad_recall_rate, estimated_ad_recall_rate_lower_bound, estimated_ad_recall_rate_upper_bound, frequency, full_view_impressions, full_view_reach, impressions, unique_impressions, inline_link_clicks, inline_post_engagement, objective, optimization_goal, performance_indicator, reach, result_rate, results, relevance_score, roas, social_clicks, unique_social_clicks, social_impressions, unique_social_impressions, social_reach, spend, today_spend, total_action_value, total_actions, total_unique_actions, unique_link_clicks_ctr, video_avg_pct_watched_actions, video_avg_sec_watched_actions, video_complete_watched_actions, video_p25_watched_actions, video_p50_watched_actions, video_p75_watched_actions, video_p95_watched_actions, video_p100_watched_actions, video_start_actions, video_10_sec_watched_actions, video_15_sec_watched_actions, video_30_sec_watched_actions, website_clicks, website_ctr, adgroup_id, campaign_id, campaign_group_id, account_id

Expected
The fields given to the $fields array, the same as the cUrl example.

Workaround

The workaround for now is adding fields to the $params array, like so:

$facebookAdAccount->getInsightsAsync(
    [],
    array(
        'fields' => [
            InsightsFields::ADGROUP_ID,
            InsightsFields::CLICKS,
            InsightsFields::IMPRESSIONS,
            InsightsFields::SPEND,
            InsightsFields::ADGROUP_NAME,
            InsightsFields::CAMPAIGN_NAME
        ],
        'time_increment' => 1,
        'time_range' => array(
            'since' => $dateStart->format('Y-m-d'),
            'until' => $dateEnd->format('Y-m-d')
        ),
        'level' => InsightsLevels::ADGROUP,
    )
);

I have no proprosed fix. I already have spent too much time figuring things out that are badly documented.

@mtricht mtricht changed the title getInsightsAsync fields parameters not working getInsightsAsync fields parameter not working Nov 30, 2015
@pruno pruno added the bug label Nov 30, 2015
@pruno
Copy link
Contributor

pruno commented Nov 30, 2015

Hi @michaeltricht,

i was able to reproduce, will take a look into it.

Thanks

pruno pushed a commit that referenced this issue Dec 3, 2015
Summary:
This task relates to issue 157 on the GitHub repo 'facebook/facebook-php-ads-sdk':

  #157

On async requests for Insights the fields work differently than when getting
Insights directly: they should be passed on the params.

Test Plan:
- Change your test/config.php so 'no_async_jobs'=>  false (so the tests for async run)
- Run unit tests. Created test/FacebookAdsTest/Object/AsyncJobInsightsTest.php
@duliomatos
Copy link
Contributor

Fixed on master, thanks for reporting!

@Jonatanmdez
Copy link

Please update composer version. 4 hours lost by a solve bug, solved in december and yet not in composer. Maybe there is more people with the same problem. Default composer version (your documentation) 2.5.* . Only works fine with aSync Insights dev-master

@michapixelfarm
Copy link

I agree with @Jonatanmdez . @duliomatos : please update composer.

@duliomatos
Copy link
Contributor

Thx for the feedback, @michapixelfarm and @Jonatanmdez. We will have a minor release to include these changes this week.

@mtricht
Copy link
Author

mtricht commented May 2, 2016

Workaround stopped working since 2.6.0 for those wondering...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants