keyword insertion in ad path1

41 views
Skip to first unread message

Rc B

unread,
Jun 5, 2019, 2:31:09 PM6/5/19
to Google Ads Scripts Forum
I'm trying to use keyword insertion as ad path1 and i keep getting the following error:
"Enter a value for the first "Path" field or use the first field only
it seems like the engine ignores it deliberately... 

sample code:

function CreateAd(adManagerService, adGroup, adData, price){
   var param1Value = '{param1:' + price + '}';
  
   if(adData.url.segment1.length > 15) 
        adData.url.segment1 = '{KeyWord:Top_Preise}'; // default 
  
   return adManagerService.createAd(
        adGroup, 
        adData.header.line1, 
        adData.header.line2 + ' ' + param1Value, 
        adData.header.line3, 
        adData.description.line1, 
        adData.description.line2, 
        adData.url.path, 
        adData.url.segment1, 
        adData.url.segment2
  );

when the length is bigger than 15, I try to inject the keyword that triggered the ad. 
the line {KeyWord:Top_Preise} create the above exception. 

what am I doing wrong?  

Google Ads Scripts Forum Advisor Prod

unread,
Jun 5, 2019, 4:42:18 PM6/5/19
to adwords-scripts+apn2wqey1opwrzqa...@googlegroups.com, adwords...@googlegroups.com

Hi,
 

I will need to see the full script to see how it is acting. Can you provide me your CID and script name through reply privately to author?

Thanks,
Anthony
Google Ads Scripts Team



ref:_00D1U1174p._5001UBlhnO:ref
Message has been deleted
Message has been deleted

Rc B

unread,
Jun 7, 2019, 10:39:02 AM6/7/19
to Google Ads Scripts Forum
found it! was my bad... (-:
I have a validation layer which creates a sub-string if a value is too long (which causes an ad creation failure)
once this mechanism identifies such an input - it creates a substring from it till the allowed length. 
e.g: if the length is 20 and allowed is 15 - it cuts 5 characters from the end of the value.  
that caused the value to be invalid! 

thanks

Rc B

unread,
Jun 7, 2019, 10:41:33 AM6/7/19
to Google Ads Scripts Forum
the solution is to count the value while ignoring the keyword insertion pattern.

see below: 
},
    /*
    keyword insertion allows us to auto-inject the triggered keyword into the ad content (kind-of a placeholder). 
        structure: '{KeyWord: Value}'         
        the word 'KeyWord' plus the curly brackets are being ignored by the adwords engine so the actual length of such expression equals to the Value length alone
        e.g: the length of '{KeyWord: Chocolate}' is 9! (counting only the Chocolate) 
    */    
countWithoutKeywordInsertion: function(input){      
      /*
        // the value does not include a keyword insertion - return it as is 
        if(input.indexOf('{') == -1 && input.indexOf('}') == -1) 
          return input;
      */
      
      var keywordInsertionPattern = /{\s*KeyWord\s*:(.*?)\s*}/ig;
      return input.replace(keywordInsertionPattern, '$1').length;     
    }

On Wednesday, 5 June 2019 21:31:09 UTC+3, Rc B wrote:
Reply all
Reply to author
Forward
0 new messages