Conversions

163 views
Skip to first unread message

etienne....@admobio.com

unread,
Nov 18, 2015, 12:51:44 PM11/18/15
to AdWords API Forum
Hi,

I want to know how I can find out if there at least 1 conversion within a account in the last 30 days.

I am familiar with "GetService ('CampaignService' ADWORDS_VERSION);" but I don't know what to look for to get that kind of information.

Thank you in advance for your help!

Etienne

Anthony Madrigal

unread,
Nov 18, 2015, 2:32:53 PM11/18/15
to AdWords API Forum
Hi Etienne,

For your use case, I recommend using a report instead of an API service. The particular report type you should use is the Account Performance Report. Make sure to include the field Conversions and use the date range LAST_30_DAYS.

Cheers,
Anthony
AdWords API Team

etienne....@admobio.com

unread,
Nov 19, 2015, 11:50:32 AM11/19/15
to AdWords API Forum
Hi Anthony,

Ok I used the report and I am now able to download them. Now, can I print the results directly on the screen rather than download the report?

Thank you !

Anthony Madrigal

unread,
Nov 19, 2015, 4:34:53 PM11/19/15
to AdWords API Forum
Hi,

Yes, you can get the report returned to you as a string. How to do it depends on which library you use. For example, in this Java example, you can change this line from response.saveToFile(reportFile); to response.getAsString().

Please let me know if you need more assistance. 

etienne....@admobio.com

unread,
Nov 19, 2015, 5:03:02 PM11/19/15
to AdWords API Forum
Hi,

I'm glad to hear that it's possible.

I searched for an equivalent of "response.getAsString ()". I work with PHP, do you have any examples?

Thank you for your help!

Etienne

Anthony Madrigal

unread,
Nov 20, 2015, 9:58:12 AM11/20/15
to AdWords API Forum
Hi Etienne,

I am not 100% certain of the PHP equivalent since I focus primarily on Java, but I will help as best I can. I believe that for Lib\Util\ReportUtils.DownloadReport for the PHP example, the return type is "if path isn't specified the contents of the report, otherwise the size in bytes of the downloaded report". In other words, if you do not provide the file path, it will be returned as a string.

Regards,
Anthony
AdWords API Team

etienne....@admobio.com

unread,
Nov 20, 2015, 12:23:56 PM11/20/15
to AdWords API Forum
Hi !

Ok I tried several things and in different ways but if I don't specify filePath, logs always returns me:

PHP Warning: fopen (): Filename can not be empty in src/Google/Api/Ads/AdWords/User/ReportUtils.php

For now I'm stuck here. If you have a solution let me know and I will meanwhile do research.

Thank you for your help !

PS: Sorry for my English, I speak French from Quebec.

Etienne

Here is my code that works and that allows me to download the report.
function test(AdWordsUser $user) {
       
  // Load the service, so that the required classes are available.
  $user
->LoadService('ReportDefinitionService', ADWORDS_VERSION);

  // Create selector.
  $selector
= new Selector();
  $selector
->fields = array('CampaignId');
       
  //if ($timePeriod == "CUSTOM_DATE") {
  //$selector->dateRange = new DateRange($dateFrom, $dateTo);
  //}

  // Create report definition.
  $reportDefinition
= new ReportDefinition();
  $reportDefinition
->selector = $selector;
  $reportDefinition
->reportName = 'Performance report #' . uniqid();
  $reportDefinition
->dateRangeType = 'LAST_7_DAYS';
  //$reportDefinition->reportType = 'ACCOUNT_PERFORMANCE_REPORT';
  $reportDefinition
->reportType = 'CAMPAIGN_PERFORMANCE_REPORT';
  $reportDefinition
->downloadFormat = 'XML';

  // Set additional options.
  $options
= array('version' => ADWORDS_VERSION);

  $filePath
= "reports/test.xml";
 
  // Download report.
  ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);
 
 
printf("Report with name '%s' was downloaded to '%s'.\n", $reportDefinition->reportName, $filePath);
}




Nadine Sundquist (AdWords API Team)

unread,
Nov 20, 2015, 1:55:07 PM11/20/15
to AdWords API Forum
Hi Etienne,

Your English is definitely easy to understand. No worries there. I looked at the PHP code that you have, and I looked at the Report Utils PHP code in the library. It looks like if you set the file path to null, then it should skip over fopen(). Have you given that a try?

Cheers,
Nadine, AdWords API Team 

etienne....@admobio.com

unread,
Nov 20, 2015, 3:01:47 PM11/20/15
to AdWords API Forum
Hi Nadine !

Thanks for the info. I had previously tested with "NULL" but I had not paid attention then it worked thank you!

Now that it's done, I can't find information to retrieve the values returned by the service. Do you have any info on this on how to do this?

Also, I found the "ConversionTrackerService" that returns many information. I found the "mostRecentConversionDate" field. With this field, I would be able to recover the most recent conversion date and compare it with today's date and then whether a conversion took place in the last 30 days.

The problem is that the field always seems empty! I will do another test but the field still seems empty even if conversion has been made.

What do you think of these two subjects?

Thank you,
Etienne

Josh Radcliff (AdWords API Team)

unread,
Nov 20, 2015, 3:40:08 PM11/20/15
to AdWords API Forum
Hi Etienne,

Have you gone through the Working with Objects guide? That explains how to specify which attributes of an object you want to retrieve from a service. The Selector fields list is also a useful reference.

Regarding the latest conversion date, please make sure that your selector's field list includes MostRecentConversionDate, as the API generally only returns values for fields that you have explicitly requested.

Cheers,
Josh, AdWords API Team
Message has been deleted

etienne....@admobio.com

unread,
Nov 20, 2015, 4:45:49 PM11/20/15
to AdWords API Forum
Hi Josh and thank you for your answer.

I completely forgot to add the field in the selector, so it always sent me an empty field. It was my mistake ... I think I'm exhausted from my work week.

Here's my working code:
function test(AdWordsUser $user) {
 
 $service 
= $user->GetService('ConversionTrackerService', ADWORDS_VERSION);

 $selector 
= new Selector();
 $selector
->fields = array(
  'MostRecentConversionDate', 
  'LastReceivedRequestTime'
 
);
 
 $data 
= $service->get($selector);
 
 
if (isset($data->entries)) {
  print_r
("<pre>");
  print_r 
($data->entries);
  print_r
("</pre>");
 
}else{
  
print "Empty";
 
}

}

I tried to do the same approach with the reports but the method "Get" like "$data = $service->get($selector);" always returns the following error: PHP Warning: The method "get" is not supported. 

So I guess for reports, this is not the right way to proceed.

Is it correct to assume that this isn't the same approach as "ConversionTrackerService" or other services ?

Thank you,

Etienne

Josh Radcliff (AdWords API Team)

unread,
Nov 20, 2015, 5:38:24 PM11/20/15
to AdWords API Forum
Hi Etienne,

Reporting works a bit differently, as it simply streams CSV, TSV, or XML results directly (instead of using SOAP). The Reporting Basics guide gives a good overview of how to run reports, and the examples in the PHP library Reporting folder show how to use the various PHP utilities for reporting.

Cheers,
Josh, AdWords API Team

etienne....@admobio.com

unread,
Nov 24, 2015, 4:18:04 PM11/24/15
to AdWords API Forum
Hi Josh,

I am able to download reports. I wish instead of downloading the reports, retrieve and display the values on the screen. Is it possible ?

Thank you !

Josh Radcliff (AdWords API Team)

unread,
Nov 24, 2015, 4:24:52 PM11/24/15
to AdWords API Forum
Hi Etienne,

You can retrieve the report as a string if you simply do not specify a $filePath when you call ReportUtils::DownloadReport. In that case, the return value from ReportUtils::DownloadReport will be the contents as a string.


Cheers,
Josh, AdWords API Team

etienne....@admobio.com

unread,
Nov 24, 2015, 6:14:04 PM11/24/15
to AdWords API Forum
Hi Josh,

I tried many things but there is something I don't understand.

I added NULL to $filePath but the result is still empty.

With the following code, do you see something that might help me ?

I also googled a lot of request but there's no result for such specific search.

Thank you for your help !


function getAccountPerformanceReport(AdWordsUser $user) {
       
 
// Load the service.

 $user
->LoadService('ReportDefinitionService', ADWORDS_VERSION);

 // Create selector.
 $selector
= new Selector();
 $selector
->fields = array(

 
'CampaignId',
 
'Impressions');

       
 // Create report definition.
 $reportDefinition
= new ReportDefinition();
 $reportDefinition->selector = $selector;
 $reportDefinition->reportName = 'Criteria performance report #' . uniqid();

 $reportDefinition
->dateRangeType = 'LAST_7_DAYS';
 //$reportDefinition->reportType = 'ACCOUNT_PERFORMANCE_REPORT';
 $reportDefinition
->reportType = 'CAMPAIGN_PERFORMANCE_REPORT';
 $reportDefinition
->downloadFormat = 'XML';

 // Set additional options.
 $options
= array('version' => ADWORDS_VERSION);

       
 $filePath
= NULL;
 
 print ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);
 //printf("Report with name '%s' was downloaded to '%s'.\n", $reportDefinition->reportName, $filePath);
}

Josh Radcliff (AdWords API Team)

unread,
Nov 25, 2015, 9:47:52 AM11/25/15
to AdWords API Forum
Hi Etienne,

When you say the result is empty, do you mean it's literally the empty string ("")/null, or that it simply does not contain any rows of data, like this?

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<report>
  <report-name name="Criteria performance report #5655c94a2d066"/>
  <date-range date="Nov 18, 2015-Nov 24, 2015"/>
  <table>
    <columns>
      <column name="campaignID" display="Campaign ID"/>
      <column name="impressions" display="Impressions"/>
    </columns>
  </table>
</report>

If the latter, then this is most likely due to your campaigns not having any impressions. You can include campaigns with zero impressions as follows:

$reportDefinition->includeZeroImpressions = true;

If that doesn't resolve it for you, could you let me know if you've tried the example without setting filePath to null, and if so, if the resulting file contained any data (even if it's just the empty response above)?

Thanks,
Josh, AdWords API Team

etienne....@admobio.com

unread,
Nov 26, 2015, 8:33:58 AM11/26/15
to AdWords API Forum
Hi Josh !

Ok here is the result of my test:

If I put the path to NULL and print the result directly on the screen there are no results so the string is empty.

Like this:
$filePath = NULL;
print ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);


If I specify a directory path and print the result on the screen I get a strange result "252" as a string.

Like this:
$filePath = "reports/test.xml";

print ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);


If I send the result in the XML file I get this:

Like this:
$filePath = "reports/test.xml";

ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);

Result in the XML file:
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<report>

 
<report-name name='Criteria performance report #5657055530886'/>
 
<date-range date='Nov 19, 2015-Nov 25, 2015'/>

 
<table>
 
<columns>
 
<column name='campaignID' display='Campaign ID'/>

 
</columns>
 
<row campaignID='xxxxx'/>
 
<row campaignID='xxxxx'/>
 
<row campaignID='xxxxx'/>
 
<row campaignID='xxxxx'/>
 
<row campaignID='xxxxx'/>
 
</table>
</report>


There are results, but it's impossible to get them out on the screen.

It's really all I have for now!

Any ideas ?

Josh Radcliff (AdWords API Team)

unread,
Nov 30, 2015, 9:11:34 AM11/30/15
to AdWords API Forum
Hi Etienne,

Are you setting any of the options, such as:
  $options['skipReportHeader'] = true;
  $options['skipColumnHeader'] = true;
  $options['skipReportSummary'] = true;

If you set all of those options to true and the report does not contain any rows, then you'll get an empty string back.

In case it helps, attached is a modified version of DownloadCriteriaReport.php that's printing the report results for me if I run php DownloadCriteriaReport.php.

Also, please make sure you are running the example from the command line, and not loading it up as a webpage in your browser. All code examples are meant to be run from the command line, since they print to stdout/stderr.

Cheers,
Josh, AdWords API Team

...
DownloadCriteriaReport.php

etienne....@admobio.com

unread,
Dec 1, 2015, 12:00:16 PM12/1/15
to AdWords API Forum
Hi,

Ok finally works!

FYI I use the reports on the web, not from the command line.

The reason it does not show on the screen is that I had to parse the string with simplexml_load_string before. Looking at the source code of the page I noticed that everything was there but it was not displayed on the screen.

Thanks for all !

Final working code:

$report = ReportUtils::DownloadReport($reportDefinition, NULL, $user, $options);

$xml
= simplexml_load_string($report);
print "<pre>";
print_r
($xml);
print "</pre>";

Reply all
Reply to author
Forward
0 new messages