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.
For more options, visit https://groups.google.com/d/optout.