Setting Campaign Level Conversion Action

387 views
Skip to first unread message

PPC Developer

unread,
Aug 7, 2019, 2:18:55 PM8/7/19
to AdWords API and Google Ads API Forum
Hi,

I'd like to set a campaign's conversion action progrmattically via the API. Today, this is available in Search campaign settings page, the default is "use account level conversion action", see attached. 

I can manually select a specific conversion action if I click on the radio button  "Choose conversion actions for this campaign"

So my question is : How can I do this via the API? 
Capture.PNG

Google Ads API Forum Advisor Prod

unread,
Aug 7, 2019, 5:07:37 PM8/7/19
to ppcdev...@mineeds.com, adwor...@googlegroups.com
Hello, 

You may use the SelectiveOptimization to set the optimization settings in the Google Ads UI. Please find below the code snippet to set the conversion tracker:

SelectiveOptimization optimize =  new SelectiveOptimization();
optimize.setConversionTypeIds(new long[] {257993218L});
campaign.setSelectiveOptimization(optimize);

Could you please give it a try and let me know if you encounter any issues?

Thanks,
Bharani, Google Ads API Team

ref:_00D1U1174p._5001UEIH1s:ref

PPC Developer

unread,
Aug 12, 2019, 12:23:55 PM8/12/19
to AdWords API and Google Ads API Forum
Thank you, it's the right Type to work with, however, this works only when the campaign has no selectiveoptimization settings currently.

If you want to manage the Conversion Type IDs at the campaign level, you need to use the ListOperations  

 Below code is working, it overrides the campaign's current optmization list with conversions in the camTargetConvList variable. 


                ListOperations listOperation = new ListOperations();
                listOperation.operators = new ListOperationsListOperator[] { ListOperationsListOperator.PUT };
                if (entry.selectiveOptimization == null)
                    entry.selectiveOptimization = new SelectiveOptimization();
                entry.selectiveOptimization.conversionTypeIdsOps = listOperation;
                entry.selectiveOptimization.conversionTypeIdsOps.clear = true;
                entry.selectiveOptimization.conversionTypeIds = camTargetConvList.ToArray();


                List<CampaignOperation> opList = new List<CampaignOperation>();

                CampaignOperation operation = new CampaignOperation
                {
                    @operator = Operator.SET,
                    operand = entry
                };
                opList.Add(operation);

                campaignService.mutate(opList.ToArray());

KL

unread,
Mar 25, 2021, 6:26:08 AM3/25/21
to AdWords API and Google Ads API Forum
On Monday, August 12, 2019 at 7:23:55 PM UTC+3 PPC Developer wrote:
 Below code is working, it overrides the campaign's current optmization list with conversions in the camTargetConvList variable. 


Hi Everybody,

Is there a chance with the v201809 API to set several campaign level conversions?
The code above and below seems to be working for a single conversion only, however, an attempt to set several leads to the CAMPAIGN_CANNOT_SET_MORE_THAN_ONE_CONVERSION_TYPE_ID error.
This happens for both SEARCH and DISPLAY campaign
<errorString>CampaignError.CAMPAIGN_CANNOT_SET_MORE_THAN_ONE_CONVERSION_TYPE_ID</errorString>
<ApiError.Type>CampaignError</ApiError.Type>
<reason>UNKNOWN</reason>

The new v6 API has an ability to do it via conversion action set just like it happens in GUI.


ListOperations listOperation = new ListOperations();
ListOperationsListOperator[] operators = new ListOperationsListOperator[] {
ListOperationsListOperator.PUT,
ListOperationsListOperator.PUT,
ListOperationsListOperator.PUT };
long[] conversionIds = new long[] {526204302, 527630287, 527627998};

listOperation.setOperators(operators);
listOperation.setClear(true);

CampaignServiceInterface campaignService =
adWordsServices.get(session, CampaignServiceInterface.class);

// Create campaign with updated status.
Campaign campaign = new Campaign();
campaign.setId(11002617728L);
campaign.setStatus(CampaignStatus.PAUSED);
campaign.setSelectiveOptimization(new SelectiveOptimization());
campaign.getSelectiveOptimization().setConversionTypeIdsOps(listOperation);
campaign.getSelectiveOptimization().setConversionTypeIds(conversionIds);


// Create operations.
CampaignOperation operation = new CampaignOperation();
operation.setOperand(campaign);
operation.setOperator(Operator.SET);

CampaignOperation[] operations = new CampaignOperation[] {operation};

CampaignReturnValue result = campaignService.mutate(operations);

// Display campaigns.
for (Campaign campaignResult : result.getValue()) {
System.out.println("Campaign: " + campaignResult);
}

KL

unread,
Mar 25, 2021, 6:35:09 AM3/25/21
to AdWords API and Google Ads API Forum
The answer seems to be NO.
The explanation is in another thread.

Google Ads API Forum Advisor Prod

unread,
Mar 25, 2021, 9:25:27 PM3/25/21
to ya.g...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for posting your concern.

It appears that you have the same concern as posted on the other email thread. With this, since you are setting multiple conversions on the same campaign type, then you are correct that this is not possible because there are some campaigns that can only support 1 conversion type IDs

Let me know if you have further questions.

Regards,
Google Logo
Ernie John Blanca Tacata
Google Ads API Team
 


ref:_00D1U1174p._5004Q2En5tg:ref
Message has been deleted

Google Ads API Forum Advisor Prod

unread,
Apr 13, 2021, 9:46:54 PM4/13/21
to ya.g...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for reaching out. However, I had to delete your initial post as it contained your logs.

Regarding your question :

Is there documentation describing if campaign can or cannot have selective optimization on multiple conversion actions?
For example, in UI I can assign either single conversion action (CA) or conversion action set (CAS).
However, I can read via API only data with single CA:
SELECT campaign.id, campaign.selective_optimization.conversion_actions FROM campaign;


For campaigns with CAS this field is empty so there should be another one.
Please describe how to manage CAS with API and assign it in certain campaign selective optimization.

Currently even single CA assignment via API does not work for me:


A conversion action can be specified in the selective optimization attribute for you app campaigns, as seen in this guide. However, conversion action sets are currently not supported in the Google Ads API and therefore cannot be managed and could be the reason why they are not visible in the report.

Best regards,

Google Logo
Peter Laurence Napa Oliquino
Google Ads API Team
 


ref:_00D1U1174p._5004Q2FY4PC:ref

KL

unread,
Apr 15, 2021, 11:49:46 AM4/15/21
to AdWords API and Google Ads API Forum
The code below works fine only when assigning a single conversion.
It does not work for multiple as it was told above and also it does not work in conversion action set is already assigned via UI.
BTW,  AdWords API was better in terms of giving specific errors for such cases.

It would be interesting to see:
1) some compact code that sets conversion action set via SOAP API, not using Java wrapper in case it does not support it
2) an approximate date (if it is already planned) when it is planned for support in Java API

private void runExample(GoogleAdsClient googleAdsClient, long customerId) {
//List<Long> conversionIds = Arrays.asList(526204302L, 527630287L, 527627998L);

List<Long> conversionIds = Arrays.asList(526204302L);

Campaign campaign =
Campaign.newBuilder()
//.setResourceName(ResourceNames.campaign(customerId, 11002617728L)) //11002617728 - search, 11662629026L - display
.setResourceName(ResourceNames.campaign(customerId, 11662629026L)) //11002617728 - search, 11662629026L - display
.setSelectiveOptimization(Campaign.SelectiveOptimization.newBuilder()
.addAllConversionActions(
conversionIds.stream().map(
c -> ResourceNames.conversionAction(customerId, c)
).collect(toList())
)
.build())
.build();

// Creates the operation.
CampaignOperation op = CampaignOperation.newBuilder()
.setUpdate(campaign)
.setUpdateMask(FieldMasks. allSetFieldsOf(campaign))
.build();
try (CampaignServiceClient campaignServiceClient =
googleAdsClient.getLatestVersion().createCampaignServiceClient())
{
MutateCampaignsResponse response =
campaignServiceClient.mutateCampaigns(
Long.toString(customerId), Collections.singletonList(op));
System.out.printf("Added %d conversion actions:%n", response.getResultsCount());
for (MutateCampaignResult result : response.getResultsList()) {
System.out.printf(
"New conversion action added with resource name: '%s'%n", result.getResourceName());
}
}
}

Google Ads API Forum Advisor Prod

unread,
Apr 16, 2021, 3:30:24 AM4/16/21
to ya.g...@gmail.com, adwor...@googlegroups.com
Hi,

I work with Peter and let me provide support to your concern.

Since conversion action sets are currently not supported in the API, a code or SOAP or REST interface example is also not available at the moment.

We also do not have any information on the timeline when features will be made available. For now, you may keep an eye on our blog for updates or announcements.

Regards,
Google Logo
Ernie John Blanca Tacata
Google Ads API Team
 


ref:_00D1U1174p._5004Q2FY4PC:ref

Zorion

unread,
Oct 29, 2021, 12:59:17 PM10/29/21
to AdWords API and Google Ads API Forum
Hi,

I just tried to retrieve/update conversion_actions using python's library (v14.0.0 for API v8) and it didn't work (we received an "StatusCode.INVALID_ARGUMENT" with error_code:{ request_error:UNKOWN}, message: "The error code is not in this version" and location operations -> update -> selective_optimization -> conversion_actions).
The field is documented, by the way (even for v7):

So I'm not sure if we do something wrong or it is still not covered in the API although it is documented.
Please, could you check it?

Thanks in advance!!
Zorion

Google Ads API Forum Advisor

unread,
Nov 1, 2021, 12:47:48 PM11/1/21
to zarriz...@g-n.com, adwor...@googlegroups.com
Hi Zorion,

Could you send us privately a request and response log of API communications for this error? Here's logging instructions, when the logger is set to 'DEBUG' the logs could be created.

Regards,

Google Logo
Aryeh Baker
Google Ads API Team
 
 

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