Adding keywords + dest urls, I get an error saying that keyword can't have more than 80 characters

29 views
Skip to first unread message

Jean-Francois PEN

unread,
Feb 26, 2015, 10:38:39 AM2/26/15
to adwords...@googlegroups.com
Hello,

Why do I get an error message saying that a keyword can't have more than 80 character despite my keywords don't have more than 80 characters?

Thanks in advance

Here's my script:
// Minimum number of clicks to consider "enough data"
var CLICKs_THRESHOLD = 2;

function main() {
  var report = AdWordsApp.report(
      'SELECT Query, Clicks, Cost, Ctr, ' +
      ' Conversions,CampaignId,AdGroupId ' +
      ' FROM SEARCH_QUERY_PERFORMANCE_REPORT ' +
      ' WHERE ' +
          ' Clicks >= ' + CLICKs_THRESHOLD +
      ' DURING 20140901,20990101');
  var rows = report.rows();

  var positiveKeywords = {};
  var allAdGroupIds = {};
  // Iterate through search query and decide whether to
  // add them as positive keywords (or ignore).
  while (rows.hasNext()) {
    var row = rows.next();
    if (parseFloat(row['Clicks']) >= 0) {
         addToMultiMap(positiveKeywords, row['AdGroupId'], row['Query']);
      allAdGroupIds[row['AdGroupId']] = true;
    }
  }

  // Copy all the adGroupIds from the object into an array.
  var adGroupIdList = [];
  for (var adGroupId in allAdGroupIds) {
    adGroupIdList.push(adGroupId);
  }

  // Add the keywords as positive to the applicable ad groups.
  var adGroups = AdWordsApp.adGroups().withIds(adGroupIdList).get();
  while (adGroups.hasNext()) {
    var adGroup = adGroups.next();
        if (positiveKeywords[adGroup.getId()]) {
      for (var i = 0; i < positiveKeywords[adGroup.getId()].length; i++) {
        adGroup.createKeyword('\"' +  positiveKeywords[adGroup.getId()][i] 
                                   + '\", 0.03, http://www.mysite.com/click-111111-222222?sid='
                                   +  adGroup.getName()
                                   +  '&url=http://search.mysite.com/search?keywords='
                                   + positiveKeywords[adGroup.getId()][i]
                                   );
      }
    }
  }
}

function addToMultiMap(map, key, value) {
  if (!map[key]) {
    map[key] = [];
  }
  map[key].push(value);
}

Alexander Wang

unread,
Feb 26, 2015, 8:53:59 PM2/26/15
to adwords...@googlegroups.com
Hi Jean-Francois,

I think you've forgotten a couple of quotation marks and are thus trying to create a keyword that looks like:

Without the necessary quotation marks, you are calling adGroup.createKeyword with a single string. The script interprets this single string as the keyword text rather than keyword text, max cpc, and destination url as you intend.

Here's an updated snippet of your code that should fix the issue:
for (var i = 0; i < positiveKeywords[adGroup.getId()].length; i++) {
  adGroup
.createKeyword('\"' +  positiveKeywords[adGroup.getId()][i]
                             
+ '\"', 0.03, 'http://www.mysite.com/click-111111-222222?sid='
                             
+  adGroup.getName()
                             
+  '&url=http://search.mysite.com/search?keywords='
                             
+ positiveKeywords[adGroup.getId()][i]
                             
);
}
It's hard to see the fix here, but basically your code was missing quotation marks here (I've added them in red):
+ '\"', 0.03, 'http://www.mysite.com/click-111111-222222?sid='

This sort of mistake is fairly easy to make when you use adGroup.createKeyword, so I recommend switching your code over to using adGroup.newKeywordBuilder(). Your new code could look like:
for (var i = 0; i < positiveKeywords[adGroup.getId()].length; i++) {

  adGroup
.newKeywordBuilder()
     
.withText('\"' +  positiveKeywords[adGroup.getId()][i] + '\"')
     
.withCpc(0.03)
     
.withDestinationUrl('http://www.mysite.com/click-111111-222222?sid='

                         
+ adGroup.getName()
                         
+ '&url=http://search.mysite.com/search?keywords='
                         
+ positiveKeywords[adGroup.getId()][i])

     
.build();
}

I think this code is a bit easier to read and makes it harder to make this sort of mistake.

Cheers,
Alex

Jean-Francois PEN

unread,
Feb 27, 2015, 2:04:24 AM2/27/15
to adwords...@googlegroups.com
Many thanks Alex! 
Your script works great but most of my destination urls get refused, I think, because they have spaces due to the adgroup name and the keyword text insertions.
I assume that I need to replace blank spaces with %20 but I don't know how.

Thanks again

Alexander Wang

unread,
Feb 27, 2015, 2:10:10 PM2/27/15
to adwords...@googlegroups.com
No problem,

Your intuition is correct that you need to replace the blank spaces with %20. Fortunately that's actually an easy fix. There's a function that's cooked into javascript called 'encodeURI'. You can use that to automatically convert the blank spaces (and any other bad characters) into values that the browser will understand.

var url = 'http://www.example.com/keyword=bad text';
var encodedUrl = encodeURI(url);
Logger.log(encodedUrl);
Logs this:

So just update your script to build the url string as you are right now, encode the url, and then use the encoded url when creating keywords.

Cheers,
Alex

Jean-Francois PEN

unread,
Feb 28, 2015, 1:41:18 AM2/28/15
to adwords...@googlegroups.com
Thank you Alex. That works perfectly! :)
Reply all
Reply to author
Forward
0 new messages