Is it possible to manage Custom ValueTrack parameters via APIat the Campaign level?

66 views
Skip to first unread message

Chad Wood

unread,
Jan 25, 2023, 6:33:50 PM1/25/23
to Google Ads API and AdWords API Forum
Hello,

I am having trouble finding documentation on this.
Is it possible to add, remove, and  change custom ValueTrack parameters at the campaign level via API?

Managing these via the web interface is an incredibly long process. Updating just a handful of campaigns takes well over 10 minutes due to load speed and needing to dig into each campaign individually just to get to this option. So, I want to use the API to build an interface for doing this much more quickly.

I am using the Python framework. If there are examples of this anywhere in the Python language, that would be very appreciated.

Google Ads API Forum Advisor

unread,
Jan 26, 2023, 1:04:20 AM1/26/23
to chadwo...@gmail.com, adwor...@googlegroups.com
Hi Chad,

Thank you for reaching out to Google Ads API Support.


>> Is it possible to add, remove, and change custom ValueTrack parameters at the campaign level via API?
To answer your question, yes, it is possible. As per our documentation about Custom Parameters, the Campaign is a supported entity for Custom Parameters, and this is defined by the url_custom_parameters attribute.

Although there is no code example from the documentation about adding / updating / removing Custom Parameters, you may refer to this update campaign example from the documentation. They are a little bit similar, you just have to define your Campaign object, and set the url_custom_parameters.

Also, you may see the following links for additional references. Let me know if you have any other questions related to the Google Ads API.

Regards,
Google Logo
Abigail
Google Ads API Team
 


ref:_00D1U1174p._5004Q2iNsig:ref

Chad Wood

unread,
Jan 26, 2023, 11:17:57 AM1/26/23
to Google Ads API and AdWords API Forum
Hey Abigail,

Thanks a lot! This is going to be a huge help for tracking.

Chad Wood

unread,
Feb 1, 2023, 11:55:50 AM2/1/23
to Google Ads API and AdWords API Forum
Hello,

Any chance you can help me understand whats going on in the example code from that link? (Its slightly rewritten here)

```
def main(client, customer_id, campaign_id):
    # For creating the campaign object
    campaign_service = client.get_service("CampaignService")
    resource_name = campaign_service.campaign_path(
        customer_id, campaign_id
    )
   
    # Create campaign operation.
    campaign_operation = client.get_type("CampaignOperation")
    campaign = campaign_operation.update
   
    # Updates campaign object with resource ID
    campaign.resource_name = resource_name

    #campaign.status = client.enums.CampaignStatusEnum.PAUSED
    #campaign.network_settings.target_search_network = False
   
    # Retrieve a FieldMask for the fields configured in the campaign.
    client.copy_from(
        campaign_operation.update_mask,
        protobuf_helpers.field_mask(None, campaign._pb),
    )

    campaign_response = campaign_service.mutate_campaigns(
        customer_id=customer_id, operations=[campaign_operation]
    )

    print(f"Updated campaign {campaign_response.results[0].resource_name}.")
```

Specifically, what is client.copy_from doing? What is a "FieldMask", and do I need to reproduce this for what I am trying to achieve?

Thanks,
Chad

Chad Wood

unread,
Feb 1, 2023, 12:02:03 PM2/1/23
to Google Ads API and AdWords API Forum
I think I found my answer. Sorry, seems jumping into the docs at 'update campaign' left me unaware of some important concepts.
You pre-specify what fields you  intend to change, and any attempted changes to a campaign field NOT specified in the field mask is ignored.
To me, this sounds like the concept of scopes, but applied to campaign fields instead of API endpoints, and it just doesn't raise error if breached.

Is this understanding correct?

Chad Wood

unread,
Feb 1, 2023, 2:20:01 PM2/1/23
to Google Ads API and AdWords API Forum
Is it possible to retrieve url_custom_parameters field via the CampaignServiceClient object?
I see it can retrieve the resource name.

campaign_service.url_custom_parameters()
>>> AttributeError: 'CampaignServiceClient' object has no attribute 'url_custom_parameters'

Chad Wood

unread,
Feb 1, 2023, 2:37:06 PM2/1/23
to Google Ads API and AdWords API Forum
Also, whats the best practice here:


# Create campaign operation.
campaign_operation = client.get_type("CampaignOperation")
campaign = campaign_operation.update

campaign.resource_name = resource_name

If I iterate through a list of campaigns that need to be updated, should I recreate the campaign object every time? By calling campaign_operation.update ?
Or can I just clear out the current object? Or perhaps reassign the resource name on it?

Google Ads API Forum Advisor

unread,
Feb 1, 2023, 3:32:33 PM2/1/23
to chadwo...@gmail.com, adwor...@googlegroups.com

Hi Chad,

Thanks for getting back to us.

I’m glad to know that you found your answer by checking documents of 'update campaign', and your understanding is correct.

You may use campaign.url_custom_parameters field from the campaign report via the GoogleAdsServiceClient object of GoogleAdsService. You may use GoogleAdsService.Search or GoogleAdsService.SearchStream to get any report. You may use this code example for reporting examples.

Also, for the best practices on updating campaigns, you may also reassign the resource name on campaign object then add it to campaign_operation, and then send the request by adding to campaign_service.mutate_campaigns(). Also, recreating campaign objects every time should work. You should be able to send 10,000 operations per request that you want to update campaigns.

Regards,

Google Logo
Yasar
Google Ads API Team
 


ref:_00D1U1174p._5004Q2iNsig:ref

Chad Wood

unread,
Feb 1, 2023, 4:51:51 PM2/1/23
to Google Ads API and AdWords API Forum
My day just keeps getting better. 10,000 operations per request?
Awesome. Thanks again for the help. I'll create a Campaign Object and iterate over-top of it, replacing its Resource Name, Campaign ID, and URL Custom Parameters within each iteration right before attaching to the Campaign Operation Object.

Once the loop finishes, I'll send it all over with campaign_service.mutate_campaigns().

Chad Wood

unread,
Feb 1, 2023, 5:08:55 PM2/1/23
to Google Ads API and AdWords API Forum
Guess I was a bit confused. It seems I'd have to recreate the campaign object every time, as the Operations object is just a list of Campaign Operation Objects. And the Campaign Object is just a method of the Campaign Operation Object.

I got this working:

operations = []

used_columns = [
    'campaign.resource_name',
    'url_custom_parameters'
]

for row in df[used_columns].to_dict('records'):

    # Create campaign operation.
    campaign_operation = client.get_type("CampaignOperation")
    campaign = campaign_operation.update
   
    # Updates campaign object
    campaign.resource_name = row['campaign.resource_name']
    campaign.url_custom_parameters = row['url_custom_parameters']
   
    # Grows operations object
    operations.append(campaign_operation)

Chad Wood

unread,
Feb 1, 2023, 5:14:57 PM2/1/23
to Google Ads API and AdWords API Forum
What would cause this:

errors { error_code { operation_access_denied_error: OPERATION_NOT_PERMITTED_FOR_REMOVED_RESOURCE } message: "This operation is not allowed because the resource is removed." trigger { string_value: "Campaign" } location { field_path_elements { field_name: "operations" index: 13 } } }

Chad Wood

unread,
Feb 1, 2023, 5:19:42 PM2/1/23
to Google Ads API and AdWords API Forum
Seems I am getting error from Deleted Resources, and Incompatible Campaign Types.

Is there any way to complete the request, and just let the response contain the errors for specific updates?
Like:

response:
{operation1: successful,
operation2: error,
...}
This is an oversimplification,  but I hope it conveys the idea.

Chad Wood

unread,
Feb 1, 2023, 5:37:32 PM2/1/23
to Google Ads API and AdWords API Forum
Alright, last question...

With the Google Ads web interface, is there an easier way to show the custom valuetracks on each campaign?
Currently, I only see how to do this by manually entering each campaigns settings and checking from the same location I'd use to update them.

A custom column that can display a specific valuetrack would be great. Is there a custom column function that can accomplish this?

Google Ads API Forum Advisor

unread,
Feb 2, 2023, 5:39:37 AM2/2/23
to chadwo...@gmail.com, adwor...@googlegroups.com
Hi Chad,

We are glad that all is working on your end again. If you have other concerns regarding Google Ads API, please do not hesitate to reach us again.

Kind regards,
Google Logo
Sherwin Vincent
Google Ads API Team
 


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