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

Advanced Scripts - AdWords

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello!

 

I'm building up a new adwords campaign for my business and I'm trying to define in the application a new script.

 

The code should be relevant for all the keywords in the search network:

-when it identifies a keyword in broad match and CTR lower than 0.5% it will change the keywords matching from 'broad match' to 'phrase match'.

- the script should be run every 24 hours.

 

Can someone help me with that? I have no idea how to program it.

Thank you very much for your help.

 

Asaf B.

 

3 Expert replyverified_user
1 ACCEPTED SOLUTION

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

Re: Advanced Scripts - AdWords

Top Contributor
# 4
Top Contributor

Hi Asaf, actually, it was even simpler than I thought, this should do it:

 

It's simple because with just the one condition (CTR < 0.5%) you can do all the selection/testing within the Keyword selector itself.


As usual, please PREVIEW this script before running it to make sure it does what you expect it to do and MONITOR it carefully over the first few days.

 

Jon

 

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 = BROAD")
.withCondition("Impressions > 0")
.withCondition("Ctr < 0.005")
.forDateRange("LAST_7_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) + "\"";
//pause old Keyword
thisKeyword.pause();
//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),"");
}

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

View solution in original post

Re: Advanced Scripts - AdWords

Top Contributor
# 2
Top Contributor

Hello,

 

Jon_Gritton might assist you with this.

 

Also, there is a dedicated AdWords script forum. This is the link:- https://groups.google.com/forum/#!forum/adwords-scripts

 

You can re-post there as well for more insights.

 

Pankaj

Re: Advanced Scripts - AdWords

Top Contributor
# 3
Top Contributor

Hi Asaf,

 

Such a script would be relatively easy and short, though you'd probably want to include some other conditions apart from just CTR.  Changing from Broad to Phrase in some instances might result in the Keyword becoming low search volume or may improve CTR but reduce conversions.

 

I may be able to knock something together for you but it may take me a day or so.


Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits
Marked as Best Answer.
Solution
Accepted by pankaj1782 (Top Contributor)
September 2015

Re: Advanced Scripts - AdWords

Top Contributor
# 4
Top Contributor

Hi Asaf, actually, it was even simpler than I thought, this should do it:

 

It's simple because with just the one condition (CTR < 0.5%) you can do all the selection/testing within the Keyword selector itself.


As usual, please PREVIEW this script before running it to make sure it does what you expect it to do and MONITOR it carefully over the first few days.

 

Jon

 

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 = BROAD")
.withCondition("Impressions > 0")
.withCondition("Ctr < 0.005")
.forDateRange("LAST_7_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) + "\"";
//pause old Keyword
thisKeyword.pause();
//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),"");
}

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

Re: Advanced Scripts - AdWords

Top Contributor
# 5
Top Contributor
Nice one, Jon. I was wondering how to get the network type and am amazed to see that AdNetworkType1 does not feature in the adwords scripts documentation, but is present on awql.me.

It's a pity that the adwords scripts help does not feature all possible conditions and the corresponding selectors.
Calin Sandici, AdWords Top Contributor | Find me on: Google+ | Twitter | LinkedIn | myBlog
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.

Re: Advanced Scripts - AdWords

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭
Dear Jon,

Thank you very much for your help.
I will use it in my campaign.
Asaf

Re: Advanced Scripts - AdWords

Top Contributor
# 7
Top Contributor

@AdWiser yep, many of the "column names" you can query through the API reports using AWQL can also be used as conditions in standard selectors, as here.  However, as you say, the documentation is poor in this respect so it's often a case of trial and error, though I suspect the problem with the docs is down to the usual rapid rate of change.

 

@Asaf, hope it works well for you.

 

Jon

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

Re: Advanced Scripts - AdWords

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭
I will check it and if i'll find errors i'll let you know. thanks!

Re: Advanced Scripts - AdWords

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭
Dear Jon,

I have runned it twice and I got an error messege:

Argument cannot be null: cpc (line 36)

I have noticed that the script deleted my keyword but didn't duplicate it in a phrase match, what could be the problem?

thanks
Asaf

Re: Advanced Scripts - AdWords

Top Contributor
# 10
Top Contributor

Hi Asaf,

 

It looks like the script is failing to retrieve the CPC of the old Keyword.  Are all the Campaigns you're running this against using Manual CPC?

 

Hopefully you're still running this as a PREVIEW, as you should do so until you're happy it's fully working.  Does it work for some Campaigns and not others?

 

Jon

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