Clone Campaign Settings

141 views
Skip to first unread message

TommyTek

unread,
May 10, 2019, 1:57:29 AM5/10/19
to AdWords API and Google Ads API Forum
Hello,
  I would create a function to clone campaign settings (without cloning adgroups etc).
I've read several discussions on this topic, eg https://groups.google.com/forum/#!newtopic/adwords-api/adwords-api/rErEluYfpAQ but the solution proposed to first get the campaign and then adding again doesn't seem to work because some attributes can't be copied; eg:

function cloneCampaign(
    AdWordsServices $adWordsServices,
    AdWordsSession $session,
    $campaignId
) {
    $campaignService = $adWordsServices->get($session, CampaignService::class);
    
    
    // Create selector.
    $selector = new Selector();
    $selector->setFields(['Id','CampaignGroupId','Name','Status','ServingStatus','StartDate','EndDate',
        //'Budget',
        //'ConversionOptimizerEligibility', // This field is read only and will be ignored when sent to the API.
        'AdServingOptimizationStatus',
        //'FrequencyCap',
        'Settings','AdvertisingChannelType',
        'AdvertisingChannelSubType',
        //'NetworkSetting',
        'Labels',
        //'BiddingStrategyConfiguration',
        'CampaignTrialType',
        'BaseCampaignId',
        //'ForwardCompatibilityMap', // This Map provides a place to put new features and settings in older versions of the AdWords API in the rare instance we need to introduce a new feature in an older version. It is presently unused. Do not set a value.
        'TrackingUrlTemplate','FinalUrlSuffix','UrlCustomParameters',
        //'VanityPharma',   // Describes how unbranded pharma ads will be displayed.
        //'UniversalAppCampaignInfo', // Stores information specific to Universal App Campaigns. This field may not be set.
        'SelectiveOptimization'
        ]);
    
    // Create predicates.
    $selector->setPredicates([
        new Predicate('CampaignId', 'EQUALS', array($campaignId)),
       ]);
    
    $page = $campaignService->get($selector);
    
    $campaign = $page->getEntries()[0];
    
    if ($campaign->getStartDate()<date("Ymd"))
        $campaign->setStartDate(date("Ymd"));
    
    $campaign->setName($campaign->getName().' cloned '.date("Ymd His"));
    
    print_r($campaign);
    
    // Create an ad group criterion operation and add it to the list.
    $operation = new CampaignOperation();
    $operation->setOperand($campaign);
    $operation->setOperator(Operator::ADD);
    $operations[] = $operation;
    
    $ret = $campaignService->mutate($operations);   
    
    $newCampaign = $ret->getValue()[0];
    
    echo "New Campaign ID: ".$newCampaign->getId()."\n\n";
    
    print_r($newCampaign);
    
    exit;   
}

If you see the Selector there are many rows commented out:
$selector->setFields(['Id','CampaignGroupId','Name','Status','ServingStatus','StartDate','EndDate',
        //'Budget',
        //'ConversionOptimizerEligibility', // This field is read only and will be ignored when sent to the API.
        'AdServingOptimizationStatus',
        //'FrequencyCap',
        'Settings','AdvertisingChannelType',
        'AdvertisingChannelSubType',
        //'NetworkSetting',
        'Labels',
        //'BiddingStrategyConfiguration',
        'CampaignTrialType',
        'BaseCampaignId',
        //'ForwardCompatibilityMap', // This Map provides a place to put new features and settings in older versions of the AdWords API in the rare instance we need to introduce a new feature in an older version. It is presently unused. Do not set a value.
        'TrackingUrlTemplate','FinalUrlSuffix','UrlCustomParameters',
        //'VanityPharma',   // Describes how unbranded pharma ads will be displayed.
        //'UniversalAppCampaignInfo', // Stores information specific to Universal App Campaigns. This field may not be set.
        'SelectiveOptimization'
        ]);

All those rows can't be read, I've the following errors:
[SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'Budget', SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'ConversionOptimizerEligibility', SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'FrequencyCap', SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'NetworkSetting', SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'BiddingStrategyConfiguration', SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'ForwardCompatibilityMap', SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'VanityPharma', SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'UniversalAppCampaignInfo']

So how can I clone a campaign and clone budget and other settings too?

If I comment out those fields and I run the script I see these settings in one of my campaign:

[settings:protected] => Array
        (
            [0] => Google\AdsApi\AdWords\v201809\cm\GeoTargetTypeSetting Object
                (
                    [positiveGeoTargetType:protected] => DONT_CARE
                    [negativeGeoTargetType:protected] => DONT_CARE
                    [SettingType:protected] => GeoTargetTypeSetting
                    [parameterMap:Google\AdsApi\AdWords\v201809\cm\Setting:private] => Array
                        (
                            [Setting.Type] => SettingType
                        )

                )

            [1] => Google\AdsApi\AdWords\v201809\cm\ShoppingSetting Object
                (
                    [merchantId:protected] => 10677451
                    [salesCountry:protected] => NL
                    [campaignPriority:protected] => 0
                    [enableLocal:protected] =>
                    [SettingType:protected] => ShoppingSetting
                    [parameterMap:Google\AdsApi\AdWords\v201809\cm\Setting:private] => Array
                        (
                            [Setting.Type] => SettingType
                        )

                )

        )

For the geotargeting you see the DONT_CARE, while in my real campaign I've some specific positive and negative locations. Do you know why?

Any help is appreciated. I'm looking into a reliable way to create campaigns from starting campaign templates.

Thank you!

googleadsapi...@google.com

unread,
May 10, 2019, 5:28:59 AM5/10/19
to AdWords API and Google Ads API Forum
Hi,

Thank you for reaching out. Unfortunately, there is no direct way on how you could clone a campaign in AdWords API. Ideally, to clone a campaign, you need to get the existing campaign by using the CampaignService.get() method and then use the values of this existing campaign to your newly created campaign. You may refer to this documentation for the required fields on creating a campaign. You may also refer to this sample code on how to create a campaign.

As per your concern regarding geoTargeting, DONT_CARE is the default value for geoTargetType. So I could further investigate about this, could you provide the complete SOAP request and response logs when you encountered this issue? If you haven't enabled logging yet, you may do so by following this guide.

Regards,
Dave
Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups "AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/3132e70c-c127-4a10-891d-9761d010092f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

TommyTek

unread,
May 10, 2019, 7:05:34 AM5/10/19
to AdWords API and Google Ads API Forum
Hi Dave,
 the instructions you gave are exactly the ones I'm trying to follow if you look at my sample code.
Why I get an error if in the Selector I put Budget and the other marked fields?

For the don't care I don't know what I'm doing wrong, but enabling the logging in the file I only see a line regarding the endpoint the request was made to. Having the complete SOAP request and response is not working to me :/

Could you please help?

Thank you

TommyTek

unread,
May 11, 2019, 4:16:30 PM5/11/19
to AdWords API and Google Ads API Forum
Hello,
 I was able to extra request/response

<SOAP-ENV:Header>
<ns1:RequestHeader>
<ns1:clientCustomerId>xxxxxxxxxxxxx</ns1:clientCustomerId>
<ns1:developerToken>REDACTED</ns1:developerToken>
<ns1:userAgent>xxxxxxxxx
<ns1:validateOnly>false</ns1:validateOnly>
<ns1:partialFailure>false</ns1:partialFailure>
</ns1:RequestHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:get>
<ns1:serviceSelector>
<ns1:fields>Id</ns1:fields>
<ns1:fields>CampaignGroupId</ns1:fields>
<ns1:fields>Name</ns1:fields>
<ns1:fields>Status</ns1:fields>
<ns1:fields>ServingStatus</ns1:fields>
<ns1:fields>StartDate</ns1:fields>
<ns1:fields>EndDate</ns1:fields>
<ns1:fields>AdServingOptimizationStatus</ns1:fields>
<ns1:fields>Settings</ns1:fields>
<ns1:fields>AdvertisingChannelType</ns1:fields>
<ns1:fields>AdvertisingChannelSubType</ns1:fields>
<ns1:fields>Labels</ns1:fields>
<ns1:fields>CampaignTrialType</ns1:fields>
<ns1:fields>BaseCampaignId</ns1:fields>
<ns1:fields>TrackingUrlTemplate</ns1:fields>
<ns1:fields>FinalUrlSuffix</ns1:fields>
<ns1:fields>UrlCustomParameters</ns1:fields>
<ns1:fields>SelectiveOptimization</ns1:fields>
<ns1:predicates>
<ns1:field>CampaignId</ns1:field>
<ns1:operator>EQUALS</ns1:operator>
<ns1:values>1828117917</ns1:values>
</ns1:predicates>
</ns1:serviceSelector>
</ns1:get>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
  
<soap:Header>
<requestId>000588a233dd34b90ae9ef0ffb0c9521</requestId>
<serviceName>CampaignService</serviceName>
<methodName>get</methodName>
<operations>1</operations>
<responseTime>455</responseTime>
</ResponseHeader></soap:Header>
<soap:Body>
<rval>
<totalNumEntries>1</totalNumEntries>
<Page.Type>CampaignPage</Page.Type>
<entries>
<id>1828117917</id>
<name>test campaign</name>
<status>PAUSED</status>
<servingStatus>SERVING</servingStatus>
<startDate>20190426</startDate>
<endDate>20371230</endDate>
<budget></budget>
<adServingOptimizationStatus>ROTATE_INDEFINITELY</adServingOptimizationStatus>
<settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="GeoTargetTypeSetting">
<Setting.Type>GeoTargetTypeSetting</Setting.Type>
<positiveGeoTargetType>DONT_CARE</positiveGeoTargetType>
<negativeGeoTargetType>DONT_CARE</negativeGeoTargetType>
</settings>
<settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ShoppingSetting">
<Setting.Type>ShoppingSetting</Setting.Type>
<merchantId>10677451</merchantId>
<salesCountry>NL</salesCountry>
<campaignPriority>0</campaignPriority>
</settings>
<advertisingChannelType>SHOPPING</advertisingChannelType>
<campaignTrialType>BASE</campaignTrialType>
<baseCampaignId>1828117917</baseCampaignId>
</entries>
</rval>
</getResponse>
</soap:Body>
</soap:Envelope>
  

Could you please explain what I'm doing wrong? 

I'd like to know why I can't request budget and other fields to clone.

Thank you

googleadsapi...@google.com

unread,
May 13, 2019, 11:36:31 PM5/13/19
to AdWords API and Google Ads API Forum
Hi,

I am a colleague of Dave. Allow me to provide further assistance for your concern.

Can you confirm my understanding is correct? Based from the thread, I can see that you wish to clone your campaigns. However, Dave has already mentioned that this is not directly possible in the API. You have to manually get the settings using the CampaignService.get() and use the retrieved settings and configurations to create a new campaign, again by using the CampaignService.mutate(). 

To better assist you, can you elaborate further what issues you are currently encountering? I can see that you were able to successfully GET a campaign in your SOAP logs. You may now use these settings to create a new campaign. However, you have to implement this on your own as this is not supported in the AdWords API.

Regards,
Dannison
Google Ads API Team



=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups "AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
Reply all
Reply to author
Forward
0 new messages