How do you create a dynamic search ads campaign using the Google Ads API?

Started by 4wm3uoej, Jul 14, 2024, 10:24 AM

Previous topic - Next topic

4wm3uoej

How do you create a dynamic search ads campaign using the Google Ads API?

em1y70j0cf

To create a dynamic search ads campaign using the Google Ads API, you'll need to follow these general steps:

1. **Create a new campaign:** You can use the `CampaignService` to create a new campaign with the `CREATE` method. Set the campaign type to `Search` and the ad rotation to `Optimize`.

2. **Create ad group(s):** Use the `AdGroupService` to create ad group(s) within the campaign. You can set the bidding strategy to `ENSEMBLE_AUTO_RULES` to enable automated bidding.

3. **Create dynamic targets:** Use the `DynamicSearchAdsTargetService` to create dynamic targets for the ad group(s). Dynamic targets determine which pages on your website are eligible to match with search queries. You can create targets based on URL templates, page titles, or page content.

4. **Create dynamic ad(s):** Use the `DynamicSearchAdsAdService` to create dynamic ad(s) for the ad group(s). Dynamic ads automatically generate headlines based on the content of your website. You can set the description, display URL, and final URL for the ad.

Here's some sample code in Python to get you started:

```python
# Import the necessary libraries
from google.ads.google_ads.client import GoogleAdsClient
from google.ads.google_ads.errors import GoogleAdsException

# Create a Google Ads client
client = GoogleAdsClient.load_from_dict({
    'developer_token': 'YOUR_DEVELOPER_TOKEN',
    'client_id': 'YOUR_CLIENT_ID',
    'client_secret': 'YOUR_CLIENT_SECRET',
    'refresh_token': 'YOUR_REFRESH_TOKEN',
    'login_customer_id': 'YOUR_LOGIN_CUSTOMER_ID',
})

# Create a new campaign
campaign_service = client.get_service('CampaignService', version='v10')
campaign = client.get_type('SearchCampaign')
campaign.name = 'Dynamic Search Ads Campaign'
campaign.advertising_channel_type = client.enums.AdvertisingChannelTypeEnum.SEARCH
campaign.status = client.enums.CampaignStatusEnum.PAUSED
campaign = campaign_service.create_campaign(parent=client.path('/customer/{}/advertisingAccounts/{}'.format(client.customer_id, client.customer_id)), campaign=campaign)
print('Campaign with campaign ID "{}" created.'.format(campaign.id))

# Create an ad group
ad_group_service = client.get_service('AdGroupService', version='v10')
ad_group = client.get_type('SearchAdGroup')
ad_group.name = 'Dynamic Search Ads Ad Group'
ad_group.status = client.enums.AdGroupStatusEnum.PAUSED
ad_group = ad_group_service.create_ad_group(parent=client.path('/customer/{}/advertisingAccounts/{}'.format(client.customer_id, client.customer_id), 'campaigns/{}'.format(campaign.id)), ad_group=ad_group)
print('Ad group with ad group ID "{}" created.'.format(ad_group.id))

# Create a dynamic target
dynamic_search_ads_target_service = client.get_service('DynamicSearchAdsTargetService', version='v10')
dynamic_search_ads_target = client.get_type('DynamicSearchAdsTarget')
dynamic_search_ads_target.name = 'Dynamic Search Ads Target'
dynamic_search_ads_target.ad_group = client.path('/customer/{}/advertisingAccounts/{}'.format(client.customer_id, client.customer_id), 'campaigns/{}/adGroups/{}'.format(campaign.id, ad_group.id))
dynamic_search_ads_target.page_feed_url = 'YOUR_PAGE_FEED_URL'
dynamic_search_ads_target = dynamic_search_ads_target_service.create_dynamic_search_ads_target(parent=client.path('/customer/{}/advertisingAccounts/{}'.format(client.customer_id, client.customer_id), 'campaigns/{}/adGroups/{}'.format(campaign.id, ad_group.id)), dynamic_search_ads_target=dynamic_search_ads_target)
print('Dynamic search ads target with target ID "{}" created.'.format(dynamic_search_ads_target.id))

# Create a dynamic ad
dynamic_search_ads_ad_service = client.get_service('DynamicSearchAdsAdService', version='v10')
dynamic_search_ads_ad = client.get_type('DynamicSearchAdsAd')
dynamic_search_ads_ad.name = 'Dynamic Search Ads Ad'
dynamic_search_ads_ad.description = 'Check out our website for more information.'
dynamic_search_ads_ad.display_url = 'www.example.com'
dynamic_search_ads_ad.final_urls = ['www.example.com']
dynamic_search_ads_ad.ad_group = client.path('/customer/{}/advertisingAccounts/{}'.format(client.customer_id, client.customer_id), 'campaigns/{}/adGroups/{}'.format(campaign.id, ad_group.id))
dynamic

Didn't find what you were looking for? Search Below