Im trying to get an account data by gender breakedown...

38 views
Skip to first unread message

אברהם אברהם

unread,
Dec 28, 2016, 10:23:59 AM12/28/16
to AdWords API Forum
Hi
Im trying to get an account data by gender breakedown using the GENDER_PERFORMANCE_REPORT.
 for example: how many Clicks in a certian account were clicked by 'Males', how many by 'Females', and how many by 'Undetermined'?
I would expect to get 3 rows back that represent the result for each gender (Males,Females,Undetermined)... but in fact I get much more per gender.
the API explains that this could happen when other segment fields are used...but I use only the fields "Criteria" and "Clicks"...

this is my code....

function getData($customerId){

$filePath = sprintf(
        '%s.csv',
        tempnam(sys_get_temp_dir(),  'gender- report -')
    );
$reportSettings = (new ReportSettingsBuilder())
->fromFile()
->includeZeroImpressions(false)
->build();
    $session = (new AdWordsSessionBuilder())
        ->fromFile()
        ->withOAuth2Credential($this->oAuth2Credential)
->withClientCustomerId($customerId)
        ->withReportSettings($reportSettings)
        ->build();
    $selector = new Selector();
    $selector->setFields(['Criteria','Clicks']);
$selector->setDateRange(new DateRange('20161101', '20161130')); 
    // Create report definition.
    $reportDefinition = new ReportDefinition();
    $reportDefinition->setSelector($selector);
    $reportDefinition->setReportName(
       ' gender performance report uniq id: ' . uniqid());
    $reportDefinition->setDateRangeType(
        ReportDefinitionDateRangeType::CUSTOM_DATE); 
    $reportDefinition->setReportType(
         ReportDefinitionReportType::GENDER_PERFORMANCE_REPORT);
    $reportDefinition->setDownloadFormat(DownloadFormat::XML);
    // Download report.
    $reportDownloader = new ReportDownloader($session);
    $reportDownloadResult =
        $reportDownloader->downloadReport($reportDefinition);
    $reportDownloadResult->saveToFile($filePath);
      //  printf("Report with name '%s' was downloaded to '%s'.\n",
        //$reportDefinition->getReportName(), $filePath);
 //parse to array
      $url = $filePath;
  $xml = file_get_contents($url);
  $xml = new SimpleXMLElement( $xml);
  return $xml;


return $filePath;
}

Any help is much apriciated.

Vishal Vinayak (Adwords API Team)

unread,
Dec 28, 2016, 3:26:35 PM12/28/16
to AdWords API Forum
Hi,

Could you please provide me with a sample downloaded report? Please click on Reply privately to author when responding. 

Regards,
Vishal, AdWords API Team
Reply all
Reply to author
Forward
0 new messages