2017-04-06 70 views
0

我試圖寫一個腳本,將:通過在MCC所有帳戶在AdWords腳本中使用campaignSelector時,如何指定AdWords帳戶?

  1. 迭代,並選擇那些在名稱中有「SEM」。
  2. 遍歷帳戶中的廣告系列並選擇符合特定條件的廣告系列。
  3. 向我自己發送這些活動的列表。

我得到的問題是將帳戶循環鏈接到活動循環。

所以我的問題是,在AdWords腳本中使用campaignSelector時,如何指定AdWords帳戶?

如果我可以爲廣告系列迭代指定帳戶(而不是默認腳本所在帳戶的腳本),那麼我可以在其中包含一個包含我所選帳戶的數組。

謝謝。

劇本至今:

//This code is to be placed in an MCC, sift through accounts in that MCC that fit a certain criteria 
//then in those selected accounts, sift through the campaigns that fit a certain criteria and add 
//these to a report (report code yet to be added) 
//The problem we have is getting the campaignSelector() function to ‘look’ at the account that has been passed through from the accountIterator() function 

function main() { 

var mccAccount = AdWordsApp.currentAccount(); 
var childAccounts = MccApp.accounts(); 


function accountIterator() 
    { 
    var accountSelector = MccApp.accounts() 
    .withCondition("AccountDescriptiveName CONTAINS 'SEM'") 
    .withCondition("Status = ENABLED"); 

    var accountIterator = accountSelector.get(); 

    while (accountIterator.hasNext()) 
    { 
    var account = accountIterator.next(); 
    var accountName = account.getName(); 
    Logger.log(accountName); 
    campaignSelector(accountName); //This might be really wrong.... 
            //Need to pass the account name through to the campaignSelector function 
            //so that the campaignSelector functions looks at the campaigns in the highlighted account 
    } 
    } 


function campaignSelector() 
    { 
    //SELECT campaigns we're interested in 
    var account = AdWordsApp.currentAccount(); //Guessing that we might need to use this? 
    var campaignSelector = AdWordsApp.campaigns() 
    .withCondition("CampaignName CONTAINS 'Shoop'") 
    .withCondition("SearchExactMatchImpressionShare < 95") 
    .forDateRange("LAST_7_DAYS") 
    .withCondition("Status = ENABLED"); 

    //GET an iterator to list the selected campaigns 
    var campaignIterator = campaignSelector.get(); 

    //ITERATE through all selected campaigns 
    while (campaignIterator.hasNext()) 
    { 
     var campaign = campaignIterator.next(); 
     //Add campaign and account info to a report – to be coded seperately 
    } 
    } 
} 

回答

0

您可以使用這部分代碼到你的代碼之前選擇一個帳戶與某些contidion。我希望它能幫助

var mccAccount = AdWordsApp.currentAccount(); 


while (accountIterator.hasNext()) { 
    var account = accountIterator.next(); 
    if("condition to get certain account"){ 
    // Select the client account. 
    MccApp.select(account); 
    } 
} 

// Select campaigns under the client account 
var campaignIterator = AdWordsApp.campaigns().get(); 
0

我會做這樣的事情:

function main() { 

    var mccAccount = AdWordsApp.currentAccount(); 
    var childAccounts = MccApp.accounts(); 

    var accountIterator = MccApp.accounts().get(); 
    while (accountIterator.hasNext()) 
    { 
    var account = accountIterator.next(); 
    campaignSelector(account); 
    } 
} 

function campaignSelector(account) { 
    MccApp.select(account); // open the account that we've acquired in the previous function 

    var accountName = account.getName(); 

    var campaignSelector = AdWordsApp.campaigns() 
    .withCondition("CampaignName CONTAINS 'Shoop'") 
    .withCondition("SearchExactMatchImpressionShare < 95") 
    .forDateRange("LAST_7_DAYS") 
    .withCondition("Status = ENABLED"); 

    var campaignIterator = campaignSelector.get(); 

    while (campaignIterator.hasNext()) { 
    var campaign = campaignIterator.next(); 
    // Reporting 
    } 
} 

我想在您給我們的代碼的主要問題是缺少MccApp.select功能。

相關問題