2017-04-06 122 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功能。