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
<https://developers.google.com/adwords/api/docs/reference/v201809/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
<https://developers.google.com/adwords/api/docs/samples/php/basic-operations#add-campaigns> 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 <https://github.com/googleads/googleads-php-lib#logging>.

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/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

On 05/10/19 13:57:29 [email protected] wrote:

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);

    //
https://developers.google.com/adwords/api/docs/samples/php/basic-operations#add-campaigns

    // 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!

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
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
<https://groups.google.com/d/msgid/adwords-api/3132e70c-c127-4a10-891d-9761d010092f%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
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/180ic4g000000000o1r03u000ndg98x6gmj0d1o68o30c1g68r32dpj%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
  • Clone C... TommyTek
    • RE... googleadsapi-forumadvisor via AdWords API and Google Ads API Forum
    • Re... TommyTek
    • Re... TommyTek
      • ... googleadsapi-forumadvisor via AdWords API and Google Ads API Forum

Reply via email to