Copy / Clone Campaign using Adwords Scripts

642 views
Skip to first unread message

MWA

unread,
Apr 30, 2019, 2:41:04 PM4/30/19
to Google Ads Scripts Forum
Hi,

I'm new to Adwords Scripts, can someone help me, I need to clone a campaign along with AdGroups, Keywords and Ads using Script.
Can someone guide me?

I'm trying this way:

function main() {  
  var campName="TestCamp";
  var campaignIterator = AdsApp.campaigns()
   //   .withCondition('Status = "ENABLED"')
   .withCondition('Name = "'+campName+'"')
.get();
  Logger.log('Total campaigns found : ' +
      campaignIterator.totalNumEntities());
  while (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
   
    var campaignName=campaign.getName();
    var budget=campaign.getBudget().getAmount();
    var bidType=campaign.getBiddingStrategyType();
    var campaignType='Search only'
   
    createCampaigns(campaignName,budget,bidType,campaignType);
   
  }
 
}

function createCampaigns(campaignName,budget,bidType,campaignType) {
  // See https://developers.google.com/adwords/scripts/docs/features/bulk-upload
  // for the list of supported bulk upload templates and their column names.
  var columns = [
    'Campaign', 'Budget', 'Bid Strategy type', 'Campaign type'
  ];

  var upload = AdWordsApp.bulkUploads().newCsvUpload(
      columns, {moneyInMicros: false});

  // AdWords identify existing campaigns using its name. To create a new
  // campaign, use a campaign name that doesn't exist in your account.
  upload.append({
    'Campaign': campaignName+' Clone',
    'Budget': budget,
    'Bid Strategy type': 'cpc',
    'Campaign type': campaignType
  });
  // Use upload.apply() to make changes without previewing.
  upload.apply();
 
}

 and I think it will take way more coding, is there a simpler way?

Thanks in advance.

googleadsscrip...@google.com

unread,
Apr 30, 2019, 5:47:56 PM4/30/19
to MWA via Google Ads Scripts Forum, Google Ads Scripts Forum
Hello,

There isn't an issue with the script you have posted above -- is there a particular question you have regarding bulk uploads?

Regards,
Matt
Google Ads Scripts Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_scripts
    https://developers.google.com/google-ads/scripts/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scripts+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/10e3a379-a7cc-4fcd-9a46-655dc531e5d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

MWA

unread,
May 3, 2019, 10:48:08 AM5/3/19
to Google Ads Scripts Forum
How should I pick

'Bid Strategy type': 'cpc'
'Campaign type': 'Search only'
from existing campaign from Script to create new one?



On Wednesday, May 1, 2019 at 2:47:56 AM UTC+5, googleadsscripts-forumadvisor wrote:
Hello,

There isn't an issue with the script you have posted above -- is there a particular question you have regarding bulk uploads?

Regards,
Matt
Google Ads Scripts Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_scripts
    https://developers.google.com/google-ads/scripts/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

googleadsscrip...@google.com

unread,
May 3, 2019, 2:24:38 PM5/3/19
to MWA via Google Ads Scripts Forum, Google Ads Scripts Forum
Hello,

You already accomplished this in your code. You get the bid strategy type and campaign type with the lines:

    var bidType=campaign.getBiddingStrategyType();
    
var campaignType='Search only'

Then you upload a new campaign, with name, campaignName + clone:

  upload.append({
    
'Campaign': campaignName+' Clone',
    
'Budget': budget,
    'Bid Strategy type': 'cpc',
    
'Campaign type': campaignType
  });

Can you please give as much detail as possible if you are looking to accomplish something else?

Thanks,
Matt
Google Ads Scripts Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_scripts
    https://developers.google.com/google-ads/scripts/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

MWA

unread,
May 6, 2019, 10:16:31 AM5/6/19
to Google Ads Scripts Forum
Hi,
Thanks for replying.
As I said I need to make a script to clone any given campaign along with its AdGroups, Keywords and Ads.

value of Bidding Strategy and Campaign Type could be any of the possible values, as you can see in my code its hard coded and
campaign.getBiddingStrategyType(); is returning  MANUAL_CPC not "cpc" and also Campaign type could be "Display only" or other possible value.

Can you help me with this?

googleadsscrip...@google.com

unread,
May 6, 2019, 3:31:44 PM5/6/19
to MWA via Google Ads Scripts Forum, Google Ads Scripts Forum
Hello,

If you are simply cloning one or a few campaigns (along with all the entities in the campaign), the easiest way to do this is through the UI. Scripts does not support a copy method, so you will have to specify values for each entity. Additionally, you can bulk upload each entity type from a spreadsheet with this sample code.

Regards,
Matt
Google Ads Scripts Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_scripts
    https://developers.google.com/google-ads/scripts/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scripts+unsubscribe@googlegroups.com.

MWA

unread,
May 7, 2019, 7:03:26 AM5/7/19
to Google Ads Scripts Forum
Ok.
Can you tell me how do I get following values with the script.
HeadlinePart1
HeadlinePart2
Description
Path1
Path2
FinalUrl

Closes things I could find are:
SourceAd.getHeadline()
SourceAd.getDescription1()
SourceAd.getDisplayUrl()


I will try following example to copy ExpendedTextAd.

DestAdGroup.
newAd().expandedTextAdBuilder()
       
.withHeadlinePart1('First headline of ad')
       
.withHeadlinePart2('Second headline of ad')
       
.withDescription('Ad description')
       
.withPath1('path1')
       
.withPath2('path2')
       
.withFinalUrl('http://www.example.com')
       
.build();



On Tuesday, April 30, 2019 at 11:41:04 PM UTC+5, MWA wrote:

googleadsscrip...@google.com

unread,
May 7, 2019, 2:31:24 PM5/7/19
to MWA via Google Ads Scripts Forum, Google Ads Scripts Forum
Hello,

For your first request:

Can you tell me how do I get following values with the script.

This depends on the type of ad. For example, if you are looking to get this criteria for an expanded text ad, you can find get methods on this page. You can find the final URL through the urls method.

As you mentioned, you can copy ads using builders, or you can use bulk uploads.

Regards,
Matt 
Google Ads Scripts Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_scripts
    https://developers.google.com/google-ads/scripts/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scripts+unsubscribe@googlegroups.com.

MWA

unread,
May 10, 2019, 6:56:27 AM5/10/19
to Google Ads Scripts Forum
Thanks it was very helpful.

One more thing can you tell me how should I handle TEXT_AD
should I convert it to EXPANDED_TEXT_AD or is there any other way to create a normal TEXT_AD in scripts?

On Tuesday, April 30, 2019 at 11:41:04 PM UTC+5, MWA wrote:

MWA

unread,
May 10, 2019, 8:01:59 AM5/10/19
to Google Ads Scripts Forum
Found it.

AdGroup.newTextAdBuilder()
.withHeadline(Headline)
.withDescription1(Description1)
.withDescription2(Description2)
.withDisplayUrl(DisplayUrl)
.withFinalUrl(DisplayUrl)
.build();

And converted it to extended text ad.
var Headline = Ad.getHeadline();
var Description1 = Ad.getDescription1();
var Description2 = Ad.getDescription2();
var DisplayUrl = Ad.getDisplayUrl();
var FinalUrl = Ad.urls().getFinalUrl();

AdGroup.newAd().expandedTextAdBuilder()
.withHeadlinePart1(Headline)
.withHeadlinePart2(Description1)
.withDescription(Description2)
.withFinalUrl(FinalUrl)
.build();

But ads are not being created...


On Tuesday, April 30, 2019 at 11:41:04 PM UTC+5, MWA wrote:

MWA

unread,
May 16, 2019, 3:28:08 AM5/16/19
to Google Ads Scripts Forum
Hi,

I'm running this code its show no error and Ads are not being created,

AdGroup.newAd().expandedTextAdBuilder()
.withHeadlinePart1(HeadlinePart1)
.withHeadlinePart2(HeadlinePart2)
.withDescription(Description)
.withPath1(Path1)
.withPath2(Path2)
.withFinalUrl(FinalUrl)
.build();

Can you guide me what's wrong with the code?


On Tuesday, April 30, 2019 at 11:41:04 PM UTC+5, MWA wrote:

googleadsscrip...@google.com

unread,
May 16, 2019, 1:30:48 PM5/16/19
to MWA via Google Ads Scripts Forum, Google Ads Scripts Forum
Hello,

It will be easier for me to debug if you post the full script. Have you defined 'AdGroup' as well as each of the arguments for the 'with' functions? For example, the following will build without issue if 'adGroup' is defined:

   adGroup.newAd().expandedTextAdBuilder()
    .withHeadlinePart1("First headline of ad")
    .withHeadlinePart2("Second headline of ad")
    .withDescription("Ad description")
    .withPath1("path1")
    .withPath2("path2")
    .withFinalUrl("http://www.example.com")
    .build();

Regards,
Matt
Google Ads Scripts Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_scripts
    https://developers.google.com/google-ads/scripts/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scripts+unsubscribe@googlegroups.com.

MWA

unread,
May 27, 2019, 6:48:08 AM5/27/19
to Google Ads Scripts Forum
Any update? I replied privately.


On Tuesday, April 30, 2019 at 11:41:04 PM UTC+5, MWA wrote:

Google Ads Scripts Forum Advisor Prod

unread,
Jun 3, 2019, 1:57:39 PM6/3/19
to adwords-scripts+apn2wqe_dqizp6qa...@googlegroups.com, adwords...@googlegroups.com
Hello,

Thank you for your patience on this. Can you please try replying privately again? We did not receive a message.

Thank you,
Matt
Google Ads Scripts Team

ref:_00D1U1174p._5001UApvwm:ref
Reply all
Reply to author
Forward
0 new messages