Hi Michael,
Thanks for reaching out. I am Harry from the Google Ads Scripts Team. Allow me to assist you on this.
Implementing a Ads Manager Script should allow you to pause/manage entities between sub accounts of your MCC and since you've mentioned that the keywords would be the same for both of the campaigns (please do correct me if I got this wrong), you may retrieve the ID of the Keyword from Campaign A then, reference the Keyword ID to be paused in Campaign B. Please see Keyword.getID() and Keyword.pause() for your reference.
For further assistance, kindly provide your CID and script name so that I would be able to check what you have so far and guide you accordingly. You may send them here or privately via the reply to author option. If this option is not available at your end, you may send it through our email (googleadsscr...@google.com) instead.
Thanks,
|
||||||
Hi Michael,
Thanks for coming back and providing the details. Please see below a code on how you can retrieve keyword IDs from campaign A then use it to pause keywords in campaign B from another account.
// Retrieve Keyword IDs that satisfied metric clicks condition from Campaign A
var accountIterator = AdsManagerApp.accounts().withIds([123-456-789]).get();
var keywordsIDs = [];
while (accountIterator.hasNext()) {
var account = accountIterator.next();
AdsManagerApp.select(account);
var campaignA = AdsApp.campaigns().withCondition("Name = 'Campaign A'").get().next();
var keywords = campaignA.keywords().withCondition("Clicks > 5").get();
while(keywords.hasNext()) {
var keyword = keywords.next();
keywordsIDs.push(keyword.getId());
}
}
// Access campaign B from the other account and then pause keywords using the keywordsIDs retrieved from campaign A
var accountIterator = AdsManagerApp.accounts().withIds([789-456-123]).get();
while (accountIterator.hasNext()) {
var account = accountIterator.next();
AdsManagerApp.select(account);
var campaignA = AdsApp.campaigns().withCondition("Name = 'Campaign B'").get().next();
var keywords = campaignA.keywords().withIds(keywordsIDs).get();
while(keywords.hasNext()) {
var keyword = keywords.next();
keyword.pause();
}
}
Let me know how it goes after updating the script for your use case and if there would be any issues.
Hi Harry
Thanks for the script. I have a small correction, as it is keywords from Campaign A that must be paused and then activated in Campaign B, but in the same account.
I have inserted the following, but get the error (TypeError: Cannot call method "hasNext" of undefined. (file Script.gs, line 12)) Can you help me with this error?
// Retrieve Keyword IDs that satisfied metric clicks condition from Campaign A (EXACT)
var accountIterator = AdsManagerApp.accounts()
.withIds(['123-456-7890'])
.get();
var keywordsIDs = [];
var Campaign_A = "CampaignName CONTAINS 'Campaign_A'"
var Campaign_B = "CampaignName CONTAINS 'Campaign_B'"
function main() {
while (accountIterator.hasNext()) {
var account = accountIterator.next();
AdsManagerApp.select(account);
var campaignA = AdsApp.campaigns()
.withCondition(Campaign_A).get().next();
var keywords = campaignA.keywords()
.forDateRange("LAST_MONTH")
.withCondition("Clicks >= 1")
// .withCondition("Status = ENABLED")
// .withCondition("CampaignStatus = ENABLED")
// .withCondition("AdGroupStatus = ENABLED")
.withCondition("KeywordMatchType = EXACT")
.get();
while(keywords.hasNext()) {
var keyword = keywords.next();
keywordsIDs.push(keyword.getId());
}
}
// Access campaign B from the same account and then pause keywords using the keywordsIDs retrieved from campaign A
var accountIterator = AdsManagerApp.accounts()
.withIds(['123-456-7890'])
.get();
while (accountIterator.hasNext()) {
var account = accountIterator.next();
AdsManagerApp.select(account);
var campaignA = AdsApp.campaigns()
.withCondition(Campaign_B).get().next();
var keywords = campaignA.keywords()
.withIds(keywordsIDs)
.withCondition("Status = PAUSED")
.withCondition("CampaignStatus = ENABLED")
.withCondition("AdGroupStatus = ENABLED")
.withCondition("KeywordMatchType = EXACT")
Hi Michael,
Thank you for pointing that out and clarifying your requirement. Please see below for the updated code. You would not need to filter the second keyword selector as we have already identified the keyword IDs on the first filtered keywords selector. Kindly take note that you would need to update the account ID and campaign names. Let me know how it goes after trying.
var accountIterator = AdsManagerApp.accounts().withIds(['123-456-789']).get();
var keywordsIDs = [];
var Campaign_A = "CampaignName CONTAINS 'Campaign_A'"
var Campaign_B = "CampaignName CONTAINS 'Campaign_B'"
function main() {
while (accountIterator.hasNext()) {
var account = accountIterator.next();
AdsManagerApp.select(account);
var campaignA = AdsApp.campaigns().withCondition(Campaign_A).get().next();
var keywords = campaignA.keywords()
.forDateRange("LAST_MONTH")
.withCondition("Clicks >= 1")
.withCondition("Status = ENABLED")
.withCondition("CampaignStatus = ENABLED"
.withCondition("AdGroupStatus = ENABLED")
.withCondition("KeywordMatchType = EXACT")
.get();
while(keywords.hasNext()) {
var keyword = keywords.next();
var adGroupID = keyword.getBaseAdGroup().getId();
keywordsIDs.push([adGroupID, keyword.getId()]);
}
var campaignB = AdsApp.campaigns().withCondition(Campaign_B).get().next();
var keywords = campaignB.keywords().withIds(keywordsIDs).get();
while(keywords.hasNext()) {
var keyword = keywords.next();
keyword.pause();
}
}
}
Thanks,
Hi Michael,
Thanks for coming back. Kindly provide the script name and your CID so that I could check this on our end and assist you further. You may send them here or privately via the reply to author option. If this option is not available at your end, you may send it through our email (googleadsscr...@google.com) instead.
Can you also provide context to what you mean by "When the requirements for a keyword in Campaign_B no longer apply" so that I can assist you in this regard?
Hi Michael,
Thanks for providing the requested information. I was not aware that there would be multiple campaigns in Campaign A and Campaign B that you referred to. Kindly iterate through campaigns like in this example instead. Please see Scheduling a script section in this link so that you can automatically set your script to execute daily.
Also, as it seems that you would manage a large amount of keywords kindly save the keywords in a list before pausing them instead of pausing them inside the keyword iterator. Please see the recommended coding approach for your reference. If you would like to pause keywords in campaign B that are referenced from campaign A and vice versa, then I think you would have to create two separate scripts for this respectively or in the same script, but different code blocks.