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

AdWords Script - Phrase match to Exact match

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello,

 

I'm facing a problem with an AdWords script. I'm trying to change the keyword match

from Phrase match to exact match. the results the I get is not good since the scripts remains the old match in the new match:

script.JPG

The script is:

 


function main() {
doMain();
}
function doMain() {
//get the Search Campaigns
var campaigns = AdWordsApp.campaigns()
.withCondition("AdNetworkType1 = 'SEARCH'")
.withCondition("Status = 'ENABLED'")
.get();
//iterate them
while(campaigns.hasNext()) {
var thisCampaign = campaigns.next();
//get the Keywords with the right conditions
var keywords = thisCampaign.keywords()
.withCondition("AdGroupStatus = 'ENABLED'")
.withCondition("Status = 'ENABLED'")
.withCondition("KeywordMatchType = PHRASE")
.withCondition("Impressions > 0")
.withCondition("Clicks > 0")
.withCondition("QualityScore < 8")
.forDateRange("LAST_30_DAYS")
.get();
//iterate them
while(keywords.hasNext()) {
var thisKeyword = keywords.next();
var keyText = thisKeyword.getText();
//remove + signs from any modified broad
var newKeyText = "\[" + replaceAll(keyText) + "\]";
//remove old Keyword
thisKeyword.remove();
//create new one NOTE - may want to add Keyword URLs here...
thisKeyword.getAdGroup().newKeywordBuilder()
.withText(newKeyText)
.withCpc(thisKeyword.bidding().getCpc())
.build();
//log results
Logger.log("Campaign: " + thisCampaign.getName() + ", Ad Group: " + thisKeyword.getAdGroup().getName() + ", Old Keyword:" + keyText + ", New Keyword: " + newKeyText);
}
}
}
function replaceAll(str) {
//just replaces + sign with nothing
return str.replace(new RegExp(/[\+]/g),"");
}

 

 

Thanks,

Asaf

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by MosheTLV (Top Contributor)
September 2015

Re: AdWords Script - Phrase match to Exact match

Top Contributor
# 2
Top Contributor

Hi Asaf, your problem is in the replace all function.  This function is currently replacing + signs (for replacing Modified Broad Match Keywords), you need to have it replace double-quotes.

 

Change the line that reads:

 

return str.replace(new RegExp(/[\+]/g),"");

 

to be:

 

return str.replace(new RegExp(/[\"]/g),"");

 

and you should be good.

 

Jon

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

View solution in original post

Marked as Best Answer.
Solution
Accepted by MosheTLV (Top Contributor)
September 2015

Re: AdWords Script - Phrase match to Exact match

Top Contributor
# 2
Top Contributor

Hi Asaf, your problem is in the replace all function.  This function is currently replacing + signs (for replacing Modified Broad Match Keywords), you need to have it replace double-quotes.

 

Change the line that reads:

 

return str.replace(new RegExp(/[\+]/g),"");

 

to be:

 

return str.replace(new RegExp(/[\"]/g),"");

 

and you should be good.

 

Jon

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

Re: AdWords Script - Phrase match to Exact match

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Jon thanks you for you help. It's working now.