2016-07-12 210 views
0

我已經使用我的mcc帳戶設置了帳戶,併爲我的客戶端客戶id之一執行了廣告系列效果報告的示例報告代碼。google adwords api php庫

這是代碼:

<?php 

// Include the initialization file 
require_once __DIR__ . '/examples/AdWords/Auth/init.php'; 
require_once __DIR__. '/src/Google/Api/Ads/AdWords/Util/v201601/ReportUtils.php'; 


function DownloadCriteriaReportWithAwqlExample(AdWordsUser $user, $filePath, 
    $reportFormat) { 
    // Optional: Set clientCustomerId to get reports of your child accounts 
    $user->SetClientCustomerId('731-721-7585'); 

    // Prepare a date range for the last week. Instead you can use 'LAST_7_DAYS'. 
    // $dateRange = 'ALL_TIME'; 

    // Create report query. 
    $reportQuery = 'SELECT CampaignName, Impressions, Clicks, Ctr, AverageCpc, ' 
     . 'Cost, Date,Conversions,ConversionRate, CostPerConversion,CampaignStatus FROM CAMPAIGN_PERFORMANCE_REPORT ' 
     . 'WHERE CampaignStatus = ENABLED DURING THIS_MONTH'; 

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


    // Download report. 
    $reportUtils = new ReportUtils(); 
    $reportUtils->DownloadReportWithAwql($reportQuery, $filePath, $user, 
     $reportFormat, $options); 

    printf("Report was downloaded to '%s'.\n", $filePath); 
} 




try { 

    // Get AdWordsUser from credentials in "../auth.ini" 
    // relative to the AdWordsUser.php file's directory. 
    $user = new AdWordsUser(); 

    // Log every SOAP XML request and response. 
    $user->LogAll(); 

    // Download the report to a file in the same directory as the example. 
    $filePath = dirname(__FILE__) . '/report.csv'; 
    $reportFormat = 'CSV'; 

    // Run the example. 
    DownloadCriteriaReportWithAwqlExample($user, $filePath, $reportFormat); 
} catch (Exception $e) { 
    printf("An error has occurred: %s\n", $e->getMessage()); 
} 

// Don't run the example if the file is being included. 
if (__FILE__ != realpath($_SERVER['PHP_SELF'])) { 
    return; 
} 

我已經執行該代碼,並得到了CSV報告,在那裏我有兩個字段AverageCpc和成本。

這兩個參數必須四捨五入或以我們在google adwords campaign dashboard中看到的格式返回。

這裏是它的外觀我我的csv文件

Avg.Cpc | Cost 
9788919 | 362190000 

截圖但是當我的AdWords廣告系列驗證,它顯示。

Avg.Cpc | Cost 
9.7 | 36.21 

是否有任何問題的代碼或我需要指定一些額外的參數爲AvgCpc價值和成本來正確格式化?

回答

1

爲此,您必須將成本和平均每次點擊費用除以1000000,所以在進一步處理數據之前,您將獲得格式。