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() and getInsights() return different results #169

Closed
benjamin-schaefer opened this issue Jan 11, 2016 · 13 comments
Closed

Comments

@benjamin-schaefer
Copy link

For a given campaign, I want to return the insights. For this, I used same $fields and $params arrays for getInsights() und getInsightsAsync():

    $fields = array(
      InsightsFields::CAMPAIGN_NAME,
      InsightsFields::CAMPAIGN_ID,
      InsightsFields::DATE_START,
      InsightsFields::DATE_STOP,
      InsightsFields::IMPRESSIONS,
      InsightsFields::SOCIAL_IMPRESSIONS,
      InsightsFields::UNIQUE_CLICKS,
      InsightsFields::REACH,
      InsightsFields::SPEND,
      InsightsFields::TOTAL_ACTIONS,
      InsightsFields::TOTAL_ACTION_VALUE,
      InsightsFields::ACTIONS
    );
    $params = array(
      'time_range' => array(
        'since' => '2013-01-01',
        'until' => '2016-02-06',
      ),
      'level' => InsightsLevels::CAMPAIGN,
    );

Here's the code for getInsights():

  $campaign->getInsights($fields, $params);

This returned NOT EMPTY values for

  • name,
  • reach,
  • amount spent,
  • unique clicks
  • impressions

But it also returned EMPTY values for

  • frequency
  • call to action clicks
  • inline link clicks
  • social clicks
  • unique social clicks
  • ctr
  • cpm

Here my code for the asynchronous call:

  $async_job = $campaign->getInsightsAsync($fields, $params);
    $async_job->read();
    while (!$async_job->isComplete()) {
      sleep(13);
      $async_job->read();
    }
    return $async_job->getResult();

This returns additionaly the following NOT EMPTY fields:

  • frequency
  • call to action clicks
  • inline link clicks
  • social clicks
  • unique social clicks
  • ctr
  • cpm

But, here the following field is empty:

  • campaign name

Am I doing something wrong or is there an issue?
Additionally, how can I get values for Delivery, Results, Cost and cpc? Is this possible by the ads sdk? In business ads manager, I can get these values in a table.

Regards,
Benjamin Schäfer

@duliomatos
Copy link
Contributor

Hello @benjamin-schaefer, thx for reaching out. Can you help with more details by sharing a log using the CurlLogger exemplified here? curl_log.php

@benjamin-schaefer
Copy link
Author

Hello @duliomatos,
the problem is that there are some secret company data in the objects, so I am not allowed to post all result objects. But I'll try it and then reply here with critical data blackened.

@duliomatos
Copy link
Contributor

@benjamin-schaefer Yeah, for the result data, can you try to replace the real values?

At least for the calls you can automatically hide sensitive data using the example logger :-)

// Hide target ids and tokens
$logger->setShowSensitiveData(false);

@benjamin-schaefer
Copy link
Author

@duliomatos unfortunately, using the logger as in the example, causes a notice and an error:

Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in /home/benjamin/lampstack-5.5.30-1/apache2/htdocs/vendor/facebook/php-ads-sdk/src/FacebookAds/Logger/CurlLogger.php on line 72
Fatal error: Call to undefined method FacebookAds\Logger\CurlLogger::setEscapeLevels() in /home/benjamin/lampstack-5.5.30-1/apache2/htdocs/getReportings.php on line 38

Here you can see my debug data for the sync insights object (all real number values were replaced by 0):

FacebookAds\Object\Insights Object ( [data:protected] => Array ( [account_id] => [account_name] => [action_values] => [actions] => Array ( [0] => Array ( [action_type] => comment [value] => 0 ) [1] => Array ( [action_type] => like [value] => 0 ) [2] => Array ( [action_type] => link_click [value] => 0 ) [3] => Array ( [action_type] => post [value] => 0 ) [4] => Array ( [action_type] => post_like [value] => 0 ) [5] => Array ( [action_type] => page_engagement [value] => 0 ) [6] => Array ( [action_type] => post_engagement [value] => 0 ) ) [actions_per_impression] => [ad_id] => [ad_name] => [adset_id] => [adset_name] => [call_to_action_clicks] => 0 [campaign_id] => 0 [campaign_name] => Campaign 1 [cost_per_action_type] => Array ( [0] => Array ( [action_type] => comment [value] => 0 ) [1] => Array ( [action_type] => like [value] => 0 ) [2] => Array ( [action_type] => link_click [value] => 0 ) [3] => Array ( [action_type] => post [value] => 0 ) [4] => Array ( [action_type] => post_like [value] => 0 ) [5] => Array ( [action_type] => page_engagement [value] => 0 ) [6] => Array ( [action_type] => post_engagement [value] => 0 ) ) [cost_per_total_action] => [cost_per_unique_click] => [cost_per_inline_link_click] => [cost_per_inline_post_engagement] => [cpm] => 0 [cpp] => 0 [ctr] => 0 [date_start] => 2000-01-01 [date_stop] => 2016-12-24 [frequency] => 0 [impressions] => 0 [inline_link_clicks] => 0 [inline_post_engagement] => [product_id] => [reach] => 0 [relevance_score] => [social_clicks] => 0 [social_impressions] => 0 [social_reach] => [spend] => 0 [total_action_value] => 0 [total_actions] => 0 [total_unique_actions] => [unique_clicks] => 0 [unique_ctr] => [unique_social_clicks] => 0 [video_avg_pct_watched_actions] => [video_avg_sec_watched_actions] => [video_complete_watched_actions] => [video_p100_watched_actions] => [video_p25_watched_actions] => [video_p50_watched_actions] => [video_p75_watched_actions] => [video_p95_watched_actions] => [website_ctr] => ) )

And here the async insights object :

FacebookAds\Object\Insights Object ( [data:protected] => Array ( [account_id] => [account_name] => [action_values] => [actions] => Array ( [0] => Array ( [action_type] => comment [value] => 0 ) [1] => Array ( [action_type] => like [value] => 0 ) [2] => Array ( [action_type] => link_click [value] => 0 ) [3] => Array ( [action_type] => post [value] => 0 ) [4] => Array ( [action_type] => post_like [value] => 0 ) [5] => Array ( [action_type] => page_engagement [value] => 0 ) [6] => Array ( [action_type] => post_engagement [value] => 0 ) ) [actions_per_impression] => [ad_id] => [ad_name] => [adset_id] => [adset_name] => [call_to_action_clicks] => 0 [campaign_id] => 0 [campaign_name] => [cost_per_action_type] => Array ( [0] => Array ( [action_type] => comment [value] => 0 ) [1] => Array ( [action_type] => like [value] => 0 ) [2] => Array ( [action_type] => link_click [value] => 0 ) [3] => Array ( [action_type] => post [value] => 0 ) [4] => Array ( [action_type] => post_like [value] => 0 ) [5] => Array ( [action_type] => page_engagement [value] => 0 ) [6] => Array ( [action_type] => post_engagement [value] => 0 ) ) [cost_per_total_action] => 0 [cost_per_unique_click] => 0 [cost_per_inline_link_click] => 0 [cost_per_inline_post_engagement] => 0 [cpm] => 0 [cpp] => 0 [ctr] => 0 [date_start] => 2000-01-01 [date_stop] => 2016-12-24 [frequency] => 0 [impressions] => 0 [inline_link_clicks] => 0 [inline_post_engagement] => 0 [product_id] => [reach] => 0 [relevance_score] => [social_clicks] => 0 [social_impressions] => 0 [social_reach] => 0 [spend] => 0 [total_action_value] => 0 [total_actions] => 0 [total_unique_actions] => 0 [unique_clicks] => 0 [unique_ctr] => 0 [unique_social_clicks] => 0 [video_avg_pct_watched_actions] => [video_avg_sec_watched_actions] => [video_complete_watched_actions] => [video_p100_watched_actions] => [video_p25_watched_actions] => [video_p50_watched_actions] => [video_p75_watched_actions] => [video_p95_watched_actions] => [website_ctr] => Array ( [0] => Array ( [action_type] => link_click [value] => 0 ) ) [buying_type] => AUCTION [unique_actions] => Array ( [0] => Array ( [action_type] => comment [value] => 0 ) [1] => Array ( [action_type] => like [value] => 0 ) [2] => Array ( [action_type] => link_click [value] => 0 ) [3] => Array ( [action_type] => post [value] => 0 ) [4] => Array ( [action_type] => post_like [value] => 0 ) [5] => Array ( [action_type] => page_engagement [value] => 0 ) [6] => Array ( [action_type] => post_engagement [value] => 0 ) ) [unique_impressions] => 0 [unique_social_impressions] => 0 [deeplink_clicks] => 0 [app_store_clicks] => 0 [website_clicks] => 0 [unique_link_clicks_ctr] => 0 [cost_per_unique_action_type] => Array ( [0] => Array ( [action_type] => comment [value] => 0 ) [1] => Array ( [action_type] => like [value] => 0 ) [2] => Array ( [action_type] => link_click [value] => 0 ) [3] => Array ( [action_type] => post [value] => 0 ) [4] => Array ( [action_type] => post_like [value] => 0 ) [5] => Array ( [action_type] => page_engagement [value] => 0 ) [6] => Array ( [action_type] => post_engagement [value] => 0 ) ) [estimated_ad_recallers] => 0 [estimated_ad_recallers_lower_bound] => 0 [estimated_ad_recallers_upper_bound] => 0 [estimated_ad_recall_rate] => 0 [estimated_ad_recall_rate_lower_bound] => 0 [estimated_ad_recall_rate_upper_bound] => 0 [cost_per_estimated_ad_recallers] => 0 ) ) 

@duliomatos
Copy link
Contributor

@benjamin-schaefer sorry, the example file is a little dated, just remove this line from the example, as this function does not exist:

$logger->setEscapeLevels(1);

@duliomatos
Copy link
Contributor

This one also won't work, my bad: $logger->setShowSensitiveData(false);
So can you try the curl logger, and obscure without any sensitive data?

@benjamin-schaefer
Copy link
Author

@duliomatos okay, now I get the same error for "setShowSensitiveData()".... when I also leave out this command, the export says:

FacebookAds\Logger\CurlLogger Object ( [handle:protected] => STDOUT )

So this is not what I want... how can I use it to log my insight request?

@duliomatos
Copy link
Contributor

A better example would be:

// Run this before your request
use FacebookAds\Logger\CurlLogger;
$logger = new CurlLogger();
// OR something like this if you are not running php on the command line
// $logger = new CurlLogger(fopen('curl.log','w'));
Api::instance()->setLogger($logger);
// Your request...

@benjamin-schaefer
Copy link
Author

Okay, thank you - the fopen was missing. Sorry, I'm just new on php.

here are my curl logs, with zeroed IDs:
sync:

curl -G \
  -d 'time_range={"since":"2011-01-01","until":"2016-02-06"}' \
  -d 'level=campaign' \
  -d 'fields=campaign_name,campaign_id,actions,reach,frequency,impressions,social_impressions,unique_clicks,spend,total_actions,total_action_value,cost_per_action_type,cpm,cpp,ctr,call_to_action_clicks,inline_link_clicks,social_clicks,unique_social_clicks' \
  -d 'access_token=TOKEN' \
  -d 'appsecret_proof=PROOF' \
  https://graph.facebook.com/v2.5/0000000000057/insights

async:

curl \
  -F 'time_range={"since":"2011-01-01","until":"2016-02-06"}' \
  -F 'level=campaign' \
  -F 'access_token=TOKEN' \
  -F 'appsecret_proof=PROOF' \
  https://graph.facebook.com/v2.5/0000000000057/insights

I hope that helps!

@duliomatos
Copy link
Contributor

PS: I obscured access_token and appsecret_proof in your comment as well

@benjamin-schaefer
Copy link
Author

Thanks. Can you work with these curl data?

@duliomatos
Copy link
Contributor

@benjamin-schaefer, it surely helps!
I don't see the fields being passed in the async call, and this is because of a recent issue where the fields were not being passed properly in the async call, which I fixed. Can you pull our current API code from master to check if it fixes the problem?

@duliomatos
Copy link
Contributor

I'm closing as duplicate of #157, which was fixed recently. LMK of anything else @benjamin-schaefer.

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

No branches or pull requests

2 participants