【问题标题】:How can I specify an AdWords account when using campaignSelector in AdWords scripts?在 AdWords 脚本中使用campaignSelector 时如何指定一个AdWords 帐户?
【发布时间】:2017-04-06 16:48:47
【问题描述】:

我试图编写一个脚本:

  1. 遍历 MCC 中的所有帐户并选择名称中包含“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
    }
  }
}

【问题讨论】:

    标签: javascript google-ads-api awql


    【解决方案1】:

    您可以使用这部分代码在您的代码之前选择一个具有特定条件的帐户。希望对你有帮助

    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();
    

    【讨论】:

      【解决方案2】:

      我会这样做:

      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 函数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-04-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-03
        相关资源
        最近更新 更多