AdWords
4.4K members online now
4.4K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me
star_border
Reply

What's wrong with this script?

Follower ✭ ✭ ✭
# 1
Follower ✭ ✭ ✭

I'm trying to write a script that gets data from a JSON feed and replace it in the ad ( {param1Smiley Very Happyefault Value} )... but when I click on "preview", the only thing i see is this:

 

http://s2.postimg.org/e3gj1lmk9/pic.jpg

 

 

Here's the script. What's wrong with this?

 

 

function main() 
{
 
  var campaignIterator = AdWordsApp.campaigns().withCondition("Name CONTAINS 'Search'").get();
  var rate = rates("USD", "IND");
  
  while (campaignIterator.hasNext()) 
  {
    var campaign = campaignIterator.next();
    if(!campaign.isEnabled()) continue;
      
    var adGroupIterator = campaign.adGroups().get()
    
    while(adGroupIterator.hasNext())
    {
      var adGroup = adGroupIterator.next();
      if(!adGroup.isEnabled()) continue;
      
      var keywords = adGroup.keywords().get();
      while (keywords.hasNext()) 
      {
        var keyword = keywords.next();
        if(!keyword.isEnabled()) continue;
        
        keyword.setAdParam(1, rate );
      }  
    }
  }
}


function rates(sending, receiving) {

  var url = 'https://some.url/query?from=' + sending + '&to=' + receiving + '&format=json';
  var json = Utilities.jsonParse(UrlFetchApp.fetch(url).getContentText());
  return json.lowest;
}

 

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author taewoo
November 2015

Re: What's wrong with this script?

Follower ✭ ✭ ✭
# 2
Follower ✭ ✭ ✭

I think that as has been correctly implemented and executed.

Please try to run is not a preview.

The following code you can check the value of adparam that is set in the keyword.

 

function main () {
  var keywords = AdWordsApp.keywords().get();
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    var adparams = keyword.adParams().get();
    while (adparams.hasNext()) {
      var adparam = adparams.next();
      Logger.log("keyword: " + keyword.getText() + ', {' + adparam.getIndex() + '} = ' + adparam.getInsertionText());
    }
  }
}

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author taewoo
November 2015

Re: What's wrong with this script?

Follower ✭ ✭ ✭
# 2
Follower ✭ ✭ ✭

I think that as has been correctly implemented and executed.

Please try to run is not a preview.

The following code you can check the value of adparam that is set in the keyword.

 

function main () {
  var keywords = AdWordsApp.keywords().get();
  while (keywords.hasNext()) {
    var keyword = keywords.next();
    var adparams = keyword.adParams().get();
    while (adparams.hasNext()) {
      var adparam = adparams.next();
      Logger.log("keyword: " + keyword.getText() + ', {' + adparam.getIndex() + '} = ' + adparam.getInsertionText());
    }
  }
}

Re: What's wrong with this script?

Top Contributor
# 3
Top Contributor

Hi @taewoo if you're sure the value being returned by the rates function is valid (make sure it's a number, not a string), then I think @Ryota YAMADA is probably right, the script does work, it's just not reporting the change.  This kind of makes sense since you're not actually changing anything in the Ad itself - the value is dynamic.

 

As ryota has suggested, I'd add a check to the script to query the value of the param after the change and ensure it matches the requested value.

 

As an aside, your main() function could build a Keyword iterator much more efficiently by using conditions in your selectors, for example:

 

var keywords = AdWordsApp.keywords()
  .withCondition("CampaignName CONTAINS 'Search'")
  .withCondition("CampaignStatus = ENABLED")
  .withCondition("AdGroupStatus = ENABLED")
  .withCondition("Status = ENABLED")
  .get();

In this way not only do you get your Keyword iterator in one statement, you don't need to test for enabled status, as you're only retrieving enabled elements in the first place.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits