如何获得Google广告的总点击次数?

时间:2015-07-10 06:39:43

标签: php adsense google-adwords google-ad-manager

我正在使用php来获取每个关键字在Google adwords中的广告系列总数。我已经设置了所有但问题是我下载的报告确实不包含数据。

我的报告功能:

function DownloadKeywordReport(AdWordsUser $user, $filePath, $keyword_id) 
    {
        // Load the service, so that the required classes are available.
        $user->LoadService('ReportDefinitionService');

        // Create selector.
        $selector = new Selector();
        $selector->fields = array('Clicks', 'Id', 'ConversionValue');

        // Filter out deleted criteria.
        //$selector->predicates[] = new Predicate('Status', 'NOT_IN', array('DELETED'));
        $selector->predicates[] = new Predicate('Id', 'IN', array($keyword_id));


        // Create report definition.
        $reportDefinition = new ReportDefinition();
        $reportDefinition->selector = $selector;
        $reportDefinition->reportName = 'Criteria performance report #' . uniqid();
        //$reportDefinition->dateRangeType = 'CUSTOM_DATE';
        $reportDefinition->dateRangeType = 'LAST_7_DAYS';
        $reportDefinition->reportType = 'KEYWORDS_PERFORMANCE_REPORT';
        $reportDefinition->downloadFormat = 'XML';

        // Exclude criteria that haven't recieved any impressions over the date range.
        $reportDefinition->includeZeroImpressions = FALSE;

        // Set additional options.
        $options = array('returnMoneyInMicros' => FALSE);

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


        $doc = new DOMDocument();
        $doc->loadXML(file_get_contents($filePath));
        $xp = new DOMXPath($doc);
        $q = $xp->query("/report/table/row/@cost");

    }

生成的xml报告是

<report>
      <report-name name="Criteria performance report #559f659c928ac"/><date-range date="Jul 3, 2015-Jul 9, 2015"/>
      <table>
        <columns>
          <column name="clicks" display="Clicks"/>
          <column name="keywordID" display="Keyword ID"/>
          <column name="totalConvValue" display="Total conv. value"/></columns>
</table>
</report>

如果我使用谷歌adsense预览工具,则不会在此处显示我的添加内容。我做错了什么或测试帐户有什么可能性?

1 个答案:

答案 0 :(得分:0)

测试帐户不会累积展示次数(因为广告未显示),因此您需要设置

$reportDefinition->includeZeroImpressions = TRUE;