您可以在目標對象名單中填入已採取特定動作的使用者 如果您使用轉換追蹤,就可以指定向以下使用者放送廣告: 先前曾在你的網站上觸發轉換 (例如購物) 的使用者 網站。
您也可以指定向曾在您網站上進行特定動作的使用者放送廣告 「您不」視為轉換的網站,例如使用者將使用者加入 客戶卻將商品從購物車中刪除而沒有消費。
必要條件
如要建立並指定目標對象區隔,您必須先:
詳閱 按照興趣和地區顯示廣告的相關政策。 使用者機密資訊不得用於建立目標對象。
設定 Google 代碼。
如果廣告客戶想根據行動應用程式行為建立使用者名單,應該 如要追蹤,請導入 Firebase SDK 或與第三方 SDK 搭配使用 應用程式內的行為
擷取 Google 代碼
所有 Google Ads 帳戶都只有一個帳戶層級「Google」 標記,自動建立 使用者啟用帳戶時
您可以按照說明中心的說明,在 Google Ads 使用者介面中擷取 Google 代碼
操作說明,或是在
透過 Google Ads API 建立 RemarketingAction
,然後擷取 Google 代碼
透過發出
GoogleAdsService.searchStream
。
使用 remarketing_action
提出要求
資源:
SELECT
remarketing_action.id,
remarketing_action.name,
remarketing_action.tag_snippets
FROM remarketing_action
WHERE remarketing_action.resource_name = 'REMARKETING_ACTION_RESOURCE_NAME'
在網站或應用程式中安插 Google 代碼
下一步是在網站的所有網頁上安插 Google 代碼。瞭解詳情 進一步瞭解如何將 Google 代碼加進網站或行動版 app。
如果您打算只根據造訪過的網頁網址建立目標對象區隔, 不需要修改 Google 代碼如果你使用的是自訂區域 參數時,必須修改代碼才能加入這些參數,詳情請參閱「進階 標記和建立再行銷的策略 清單。
您可以使用 Google Tag Assistant 進行驗證 導入代碼
內建 Google 代碼參數
您可以使用內建的再行銷參數「url__
」來指定使用者名單
以根據
您網站的
範例。
自訂 Google 代碼參數
您可以新增自訂 Google 代碼 參數 加入 Google 代碼,建立更切合需求的使用者名單。
建立自訂參數之前,請先查看 預先定義的參數 您也可以使用適合的選項 找出適合的模式使用預先定義的參數 可輕鬆與其他 Google Ads 再行銷功能整合
建立使用者名單
若要指定已採取特定動作的訪客,就必須設定
basic_user_list
欄位,
UserList
,其中包含
BasicUserListInfo
物件包含
與動作 (無論是轉換或非轉換) 的參考價值
動作,例如您指定的目標
查看您指定的使用者情境示例 依據轉換與非轉換動作的組合計算出的 範例情境。
觸發轉換的訪客
基本的使用者名單會將成員資格定義為觸發一或多項的使用者
網站上的轉換動作。建立基本使用者名單時
請在 Cloud Shell 中
將 ConversionAction
轉換為
UserListActionInfo
物件,也就是
最終會傳遞至 UserList
。
下例會建立與兩個現有使用者 轉換動作:
Java
private void runExample( GoogleAdsClient googleAdsClient, long customerId, List<Long> conversionActionIds) { List<UserListActionInfo> userListActionInfoList = new ArrayList<>(); for (long conversionActionId : conversionActionIds) { // Creates the UserListActionInfo object for a given conversion action. This specifies the // conversion action that, when triggered, will cause a user to be added to a UserList. UserListActionInfo userListActionInfo = UserListActionInfo.newBuilder() .setConversionAction(ResourceNames.conversionAction(customerId, conversionActionId)) .build(); userListActionInfoList.add(userListActionInfo); } // Creates a basic user list info object with all of the conversion actions. BasicUserListInfo basicUserListInfo = BasicUserListInfo.newBuilder().addAllActions(userListActionInfoList).build(); // Creates the basic user list. UserList basicUserList = UserList.newBuilder() .setName("Example BasicUserList #" + getPrintableDateTime()) .setDescription("A list of people who have triggered one or more conversion actions") .setMembershipLifeSpan(365) .setBasicUserList(basicUserListInfo) .setMembershipStatus(UserListMembershipStatus.OPEN) .build(); // Creates the operation. UserListOperation operation = UserListOperation.newBuilder().setCreate(basicUserList).build(); // Creates the service client. try (UserListServiceClient userListServiceClient = googleAdsClient.getLatestVersion().createUserListServiceClient()) { // Adds the basic user list. MutateUserListsResponse response = userListServiceClient.mutateUserLists( Long.toString(customerId), ImmutableList.of(operation)); // Prints the results. System.out.printf( "Created basic user list with resource name '%s'.%n", response.getResults(0).getResourceName()); } }
C#
public void Run(GoogleAdsClient client, long customerId, long[] conversionActionIds) { // Creates the service client. UserListServiceClient userListServiceClient = client.GetService(Services.V17.UserListService); List<UserListActionInfo> userListActionInfoList = new List<UserListActionInfo>(); foreach (long conversionActionId in conversionActionIds) { // Creates the UserListActionInfo object for a given conversion action. This // specifies the conversion action that, when triggered, will cause a user to be // added to a UserList. userListActionInfoList.Add(new UserListActionInfo { ConversionAction = ResourceNames.ConversionAction(customerId, conversionActionId) }); } // Creates a basic user list info object with all of the conversion actions. BasicUserListInfo basicUserListInfo = new BasicUserListInfo(); basicUserListInfo.Actions.Add(userListActionInfoList); // Creates the basic user list. UserList basicUserList = new UserList { Name = $"Example BasicUserList #{ExampleUtilities.GetShortRandomString()}", Description = "A list of people who have triggered one or more conversion actions", MembershipLifeSpan = 365L, BasicUserList = basicUserListInfo, MembershipStatus = UserListMembershipStatus.Open }; // Creates the operation. UserListOperation operation = new UserListOperation { Create = basicUserList }; try { // Adds the new user list. MutateUserListsResponse response = userListServiceClient.MutateUserLists (customerId.ToString(), new[] { operation }); // Prints the result. Console.WriteLine("Created basic user list with resource name: " + $"{response.Results.First().ResourceName}"); } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
PHP
public static function runExample( GoogleAdsClient $googleAdsClient, int $customerId, array $conversionActionIds ) { $userListActionInfoList = []; foreach ($conversionActionIds as $conversionActionId) { // Creates the UserListActionInfo object for a given conversion action. This specifies // the conversion action that, when triggered, will cause a user to be added to a // UserList. $userListActionInfoList[] = new UserListActionInfo([ 'conversion_action' => ResourceNames::forConversionAction( $customerId, $conversionActionId ) ]); } // Creates a basic user list info object with all of the conversion actions. $basicUserListInfo = new BasicUserListInfo(['actions' => $userListActionInfoList]); // Creates the basic user list. $basicUserList = new UserList([ 'name' => 'Example BasicUserList #' . Helper::getPrintableDatetime(), 'description' => 'A list of people who have triggered one or more conversion actions', 'membership_status' => UserListMembershipStatus::OPEN, 'membership_life_span' => 365, 'basic_user_list' => $basicUserListInfo ]); // Creates the operation. $operation = new UserListOperation(); $operation->setCreate($basicUserList); // Issues a mutate request to add the user list and prints some information. $userListServiceClient = $googleAdsClient->getUserListServiceClient(); $response = $userListServiceClient->mutateUserLists( MutateUserListsRequest::build($customerId, [$operation]) ); printf( "Created basic user list with resource name '%s'.%s", $response->getResults()[0]->getResourceName(), PHP_EOL ); }
Python
def main(client, customer_id, conversion_action_ids): """Creates a combination user list. Args: client: The Google Ads client. customer_id: The customer ID for which to add the user list. conversion_action_ids: The IDs of the conversion actions for the basic user list. """ # Get the UserListService and ConversionActionService clients. user_list_service = client.get_service("UserListService") conversion_action_service = client.get_service("ConversionActionService") # Create a list of UserListActionInfo objects for the given conversion # actions. These specify the conversion actions that, when triggered, will # cause a user to be added to a UserList. user_list_action_info_list = [] for conversion_action_id in conversion_action_ids: user_list_action_info = client.get_type("UserListActionInfo") user_list_action_info.conversion_action = ( conversion_action_service.conversion_action_path( customer_id, conversion_action_id ) ) user_list_action_info_list.append(user_list_action_info) # Create a UserListOperation and populate the UserList. user_list_operation = client.get_type("UserListOperation") user_list = user_list_operation.create user_list.name = f"Example BasicUserList #{uuid4()}" user_list.description = ( "A list of people who have triggered one or more conversion actions" ) user_list.membership_status = client.enums.UserListMembershipStatusEnum.OPEN user_list.membership_life_span = 365 # The basic user list info object contains the conversion action info. user_list.basic_user_list.actions.extend(user_list_action_info_list) # Issue a mutate request to add the user list, then print the results. response = user_list_service.mutate_user_lists( customer_id=customer_id, operations=[user_list_operation] ) print( "Created basic user list with resource name " f"'{response.results[0].resource_name}.'" )
小茹
def add_conversion_based_user_list(customer_id, conversion_action_ids) # GoogleAdsClient will read a config file from # ENV['HOME']/google_ads_config.rb when called without parameters client = Google::Ads::GoogleAds::GoogleAdsClient.new # Creates the basic user list. operation = client.operation.create_resource.user_list do |u| u.name = "Example BasicUserList ##{(Time.new.to_f * 100).to_i}" u.description = "A list of people who have triggered one or more conversion actions" u.membership_status = :OPEN u.membership_life_span = 365 # Creates a basic user list info object with all of the conversion actions. u.basic_user_list = client.resource.basic_user_list_info do |info| conversion_action_ids.each do |conversion_action_id| # Creates the UserListActionInfo object for a given conversion action. # This specifies the conversion action that, when triggered, will cause a # user to be added to a user_list. info.actions << client.resource.user_list_action_info do |action| action.conversion_action = client.path.conversion_action(customer_id, conversion_action_id) end end end end # Issues a mutate request to add the user list and prints some information. response = client.service.user_list.mutate_user_lists( customer_id: customer_id, operations: [operation], ) puts "Created basic user list with resource name " \ "#{response.results.first.resource_name}" end
Perl
sub add_conversion_based_user_list { my ($api_client, $customer_id, $conversion_action_ids) = @_; my $user_list_action_info_list = []; foreach my $conversion_action_id (@$conversion_action_ids) { # Create the UserListActionInfo object for a given conversion action. This # specifies the conversion action that, when triggered, will cause a user to # be added to a UserList. push @$user_list_action_info_list, Google::Ads::GoogleAds::V17::Common::UserListActionInfo->new({ conversionAction => Google::Ads::GoogleAds::V17::Utils::ResourceNames::conversion_action( $customer_id, $conversion_action_id )}); } # Create a basic user list info object with all of the conversion actions. my $basic_user_list_info = Google::Ads::GoogleAds::V17::Common::BasicUserListInfo->new({ actions => $user_list_action_info_list }); # Create the basic user list. my $basic_user_list = Google::Ads::GoogleAds::V17::Resources::UserList->new({ name => "Example BasicUserList #" . uniqid(), description => "A list of people who have triggered one or more conversion actions", membershipStatus => OPEN, membershipLifeSpan => 365, basicUserList => $basic_user_list_info }); # Create the operation. my $user_list_operation = Google::Ads::GoogleAds::V17::Services::UserListService::UserListOperation-> new({ create => $basic_user_list }); # Issue a mutate request to add the user list and print some information. my $user_lists_response = $api_client->UserListService()->mutate({ customerId => $customer_id, operations => [$user_list_operation]}); printf "Created basic user list with resource name '%s'.\n", $user_lists_response->{results}[0]{resourceName}; return 1; }
採取非轉換動作的訪客
您可以建立基本使用者名單,納入曾在您網站上採取行動的使用者
如果您將轉換與
RemarketingAction
而非
ConversionAction
。
擷取清單
若要擷取使用者名單,您可以對著
user_list
資源。
SELECT
user_list.name,
user_list.membership_status,
user_list.membership_life_span
FROM user_list
WHERE
user_list.resource_name = 'USER_LIST_RESOURCE_NAME'
指定名單
建立目標對象區隔後,下一步就是指定 基礎架構
目標對象區隔指定規則
無法在廣告活動層級設定肯定 (可出價) 的使用者名單,且無法設定 廣告群組層級必須移除肯定使用者名單條件 就可以先從廣告活動內所有的廣告群組設定一個
只有搜尋廣告活動才能使用按使用者名單進行明確指定。適用對象 多媒體廣告活動、
CampaignCriterion
設定user_list
的 已排除。在搜尋和購物廣告活動中,使用者名單目標不支援設定 以下欄位:
指定向使用者名單放送廣告
這個過程與 API 中其他類型的指定條件類似。
以下程式碼示範如何使用 AdGroupCriterion
,將廣告群組中的廣告指定至使用者名單:
Java
private String targetAdsInAdGroupToUserList( GoogleAdsClient googleAdsClient, long customerId, long adGroupId, String userList) { // Creates the ad group criterion targeting members of the user list. AdGroupCriterion adGroupCriterion = AdGroupCriterion.newBuilder() .setAdGroup(ResourceNames.adGroup(customerId, adGroupId)) .setUserList(UserListInfo.newBuilder().setUserList(userList).build()) .build(); // Creates the operation. AdGroupCriterionOperation operation = AdGroupCriterionOperation.newBuilder().setCreate(adGroupCriterion).build(); // Creates the ad group criterion service. try (AdGroupCriterionServiceClient adGroupCriterionServiceClient = googleAdsClient.getLatestVersion().createAdGroupCriterionServiceClient()) { // Adds the ad group criterion. MutateAdGroupCriteriaResponse response = adGroupCriterionServiceClient.mutateAdGroupCriteria( Long.toString(customerId), ImmutableList.of(operation)); // Gets and prints the results. String adGroupCriterionResourceName = response.getResults(0).getResourceName(); System.out.printf( "Successfully created ad group criterion with resource name '%s' " + "targeting user list with resource name '%s' with ad group with ID %d.%n", adGroupCriterionResourceName, userList, adGroupId); return adGroupCriterionResourceName; } }
C#
private string TargetAdsInAdGroupToUserList( GoogleAdsClient client, long customerId, long adGroupId, string userListResourceName) { // Get the AdGroupCriterionService client. AdGroupCriterionServiceClient adGroupCriterionServiceClient = client.GetService (Services.V17.AdGroupCriterionService); // Create the ad group criterion targeting members of the user list. AdGroupCriterion adGroupCriterion = new AdGroupCriterion { AdGroup = ResourceNames.AdGroup(customerId, adGroupId), UserList = new UserListInfo { UserList = userListResourceName } }; // Create the operation. AdGroupCriterionOperation adGroupCriterionOperation = new AdGroupCriterionOperation { Create = adGroupCriterion }; // Add the ad group criterion, then print and return the new criterion's resource name. MutateAdGroupCriteriaResponse mutateAdGroupCriteriaResponse = adGroupCriterionServiceClient.MutateAdGroupCriteria(customerId.ToString(), new[] { adGroupCriterionOperation }); string adGroupCriterionResourceName = mutateAdGroupCriteriaResponse.Results.First().ResourceName; Console.WriteLine("Successfully created ad group criterion with resource name " + $"'{adGroupCriterionResourceName}' targeting user list with resource name " + $"'{userListResourceName}' with ad group with ID {adGroupId}."); return adGroupCriterionResourceName; }
PHP
private static function targetAdsInAdGroupToUserList( GoogleAdsClient $googleAdsClient, int $customerId, int $adGroupId, string $userListResourceName ): string { // Creates the ad group criterion targeting members of the user list. $adGroupCriterion = new AdGroupCriterion([ 'ad_group' => ResourceNames::forAdGroup($customerId, $adGroupId), 'user_list' => new UserListInfo(['user_list' => $userListResourceName]) ]); // Creates the operation. $operation = new AdGroupCriterionOperation(); $operation->setCreate($adGroupCriterion); // Issues a mutate request to add an ad group criterion. $adGroupCriterionServiceClient = $googleAdsClient->getAdGroupCriterionServiceClient(); /** @var MutateAdGroupCriteriaResponse $adGroupCriterionResponse */ $adGroupCriterionResponse = $adGroupCriterionServiceClient->mutateAdGroupCriteria( MutateAdGroupCriteriaRequest::build($customerId, [$operation]) ); $adGroupCriterionResourceName = $adGroupCriterionResponse->getResults()[0]->getResourceName(); printf( "Successfully created ad group criterion with resource name '%s' " . "targeting user list with resource name '%s' with ad group with ID %d.%s", $adGroupCriterionResourceName, $userListResourceName, $adGroupId, PHP_EOL ); return $adGroupCriterionResourceName; }
Python
def target_ads_in_ad_group_to_user_list( client, customer_id, ad_group_id, user_list_resource_name ): """Creates an ad group criterion that targets a user list with an ad group. Args: client: an initialized GoogleAdsClient instance. customer_id: a str client customer ID used to create an ad group criterion. ad_group_id: a str ID for an ad group used to create an ad group criterion that targets members of a user list. user_list_resource_name: a str resource name for a user list. Returns: a str resource name for an ad group criterion. """ ad_group_criterion_operation = client.get_type("AdGroupCriterionOperation") # Creates the ad group criterion targeting members of the user list. ad_group_criterion = ad_group_criterion_operation.create ad_group_criterion.ad_group = client.get_service( "AdGroupService" ).ad_group_path(customer_id, ad_group_id) ad_group_criterion.user_list.user_list = user_list_resource_name ad_group_criterion_service = client.get_service("AdGroupCriterionService") response = ad_group_criterion_service.mutate_ad_group_criteria( customer_id=customer_id, operations=[ad_group_criterion_operation] ) resource_name = response.results[0].resource_name print( "Successfully created ad group criterion with resource name: " f"'{resource_name}' targeting user list with resource name: " f"'{user_list_resource_name}' and with ad group with ID " f"{ad_group_id}." ) return resource_name
小茹
def target_ads_in_ad_group_to_user_list( client, customer_id, ad_group_id, user_list ) # Creates the ad group criterion targeting members of the user list. operation = client.operation.create_resource.ad_group_criterion do |agc| agc.ad_group = client.path.ad_group(customer_id, ad_group_id) agc.user_list = client.resource.user_list_info do |info| info.user_list = user_list end end # Issues a mutate request to create the ad group criterion. response = client.service.ad_group_criterion.mutate_ad_group_criteria( customer_id: customer_id, operations: [operation], ) ad_group_criterion_resource_name = response.results.first.resource_name puts "Successfully created ad group criterion with resource name " \ "'#{ad_group_criterion_resource_name}' targeting user list with resource name " \ "'#{user_list}' with ad group with ID #{ad_group_id}" ad_group_criterion_resource_name end
Perl
sub target_ads_in_ad_group_to_user_list { my ($api_client, $customer_id, $ad_group_id, $user_list_resource_name) = @_; # Create the ad group criterion targeting members of the user list. my $ad_group_criterion = Google::Ads::GoogleAds::V17::Resources::AdGroupCriterion->new({ adGroup => Google::Ads::GoogleAds::V17::Utils::ResourceNames::ad_group( $customer_id, $ad_group_id ), userList => Google::Ads::GoogleAds::V17::Common::UserListInfo->new({ userList => $user_list_resource_name })}); # Create the operation. my $ad_group_criterion_operation = Google::Ads::GoogleAds::V17::Services::AdGroupCriterionService::AdGroupCriterionOperation ->new({ create => $ad_group_criterion }); # Add the ad group criterion, then print and return the new criterion's resource name. my $ad_group_criteria_response = $api_client->AdGroupCriterionService()->mutate({ customerId => $customer_id, operations => [$ad_group_criterion_operation]}); my $ad_group_criterion_resource_name = $ad_group_criteria_response->{results}[0]{resourceName}; printf "Successfully created ad group criterion with resource name '%s' " . "targeting user list with resource name '%s' with ad group with ID %d.\n", $ad_group_criterion_resource_name, $user_list_resource_name, $ad_group_id; return $ad_group_criterion_resource_name; }
就像其他類型的條件一樣,您也可以將其他屬性指派給
AdGroupCriterion
物件,例如出價覆寫。
切換指定層級
如果要從廣告群組層級使用者名單條件切換為廣告活動層級 您必須先將現有的使用者名單條件從每個已啟用的 該廣告活動中的已暫停廣告群組。按一下可展開的元素即可檢視 。
首先,擷取指定廣告活動下的所有 廣告群組條件。
Java
private List<String> getUserListAdGroupCriterion( GoogleAdsClient googleAdsClient, long customerId, long campaignId) { List<String> userListCriteria = new ArrayList<>(); // Creates the Google Ads service client. try (GoogleAdsServiceClient googleAdsServiceClient = googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) { // Creates a request that will retrieve all of the ad group criteria under a campaign. SearchGoogleAdsRequest request = SearchGoogleAdsRequest.newBuilder() .setCustomerId(Long.toString(customerId)) .setQuery( "SELECT ad_group_criterion.criterion_id" + " FROM ad_group_criterion" + " WHERE campaign.id = " + campaignId + " AND ad_group_criterion.type = 'USER_LIST'") .build(); // Issues the search request. SearchPagedResponse searchPagedResponse = googleAdsServiceClient.search(request); // Iterates over all rows in all pages. Prints the results and adds the ad group criteria // resource names to the list. for (GoogleAdsRow googleAdsRow : searchPagedResponse.iterateAll()) { String adGroupCriterionResourceName = googleAdsRow.getAdGroupCriterion().getResourceName(); System.out.printf( "Ad group criterion with resource name '%s' was found.%n", adGroupCriterionResourceName); userListCriteria.add(adGroupCriterionResourceName); } } return userListCriteria; }
C#
private List<string> GetUserListAdGroupCriteria( GoogleAdsClient client, long customerId, long campaignId) { // Get the GoogleAdsService client. GoogleAdsServiceClient googleAdsServiceClient = client.GetService(Services.V17.GoogleAdsService); List<string> userListCriteriaResourceNames = new List<string>(); // Create a query that will retrieve all of the ad group criteria under a campaign. string query = $@" SELECT ad_group_criterion.criterion_id FROM ad_group_criterion WHERE campaign.id = {campaignId} AND ad_group_criterion.type = 'USER_LIST'"; // Issue the search request. googleAdsServiceClient.SearchStream(customerId.ToString(), query, delegate (SearchGoogleAdsStreamResponse resp) { // Display the results and add the resource names to the list. foreach (GoogleAdsRow googleAdsRow in resp.Results) { string adGroupCriterionResourceName = googleAdsRow.AdGroupCriterion.ResourceName; Console.WriteLine("Ad group criterion with resource name " + $"{adGroupCriterionResourceName} was found."); userListCriteriaResourceNames.Add(adGroupCriterionResourceName); } }); return userListCriteriaResourceNames; }
PHP
private static function getUserListAdGroupCriteria( GoogleAdsClient $googleAdsClient, int $customerId, int $campaignId ): array { // Creates a query that retrieves all of the ad group criteria under a campaign. $query = sprintf( "SELECT ad_group_criterion.criterion_id " . "FROM ad_group_criterion " . "WHERE campaign.id = %d " . "AND ad_group_criterion.type = 'USER_LIST'", $campaignId ); // Creates the Google Ads service client. $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient(); // Issues the search request. $response = $googleAdsServiceClient->search(SearchGoogleAdsRequest::build($customerId, $query)); $userListCriteria = []; // Iterates over all rows in all pages. Prints the user list criteria and adds the ad group // criteria resource names to the list. foreach ($response->iterateAllElements() as $googleAdsRow) { /** @var GoogleAdsRow $googleAdsRow */ $adGroupCriterionResourceName = $googleAdsRow->getAdGroupCriterion()->getResourceName(); printf( "Ad group criterion with resource name '%s' was found.%s", $adGroupCriterionResourceName, PHP_EOL ); $userListCriteria[] = $adGroupCriterionResourceName; } return $userListCriteria; }
Python
def get_user_list_ad_group_criteria(client, customer_id, campaign_id): """Finds all of user list ad group criteria under a campaign. Args: client: an initialized GoogleAdsClient instance. customer_id: a str client customer ID. campaign_id: a str campaign ID. Returns: a list of ad group criterion resource names. """ # Creates a query that retrieves all of the ad group criteria under a # campaign. query = f""" SELECT ad_group_criterion.criterion_id FROM ad_group_criterion WHERE campaign.id = {campaign_id} AND ad_group_criterion.type = USER_LIST""" googleads_service = client.get_service("GoogleAdsService") search_request = client.get_type("SearchGoogleAdsRequest") search_request.customer_id = customer_id search_request.query = query response = googleads_service.search(request=search_request) # Iterates over all rows in all pages. Prints the user list criteria and # adds the ad group criteria resource names to the list. user_list_criteria = [] for row in response: resource_name = row.ad_group_criterion.resource_name print( "Ad group criterion with resource name '{resource_name}' was " "found." ) user_list_criteria.append(resource_name) return user_list_criteria
小茹
def get_user_list_ad_group_criterion( client, customer_id, campaign_id ) user_list_criteria = [] # Creates a query that will retrieve all of the ad group criteria # under a campaign. query = <<~QUERY SELECT ad_group_criterion.criterion_id FROM ad_group_criterion WHERE campaign.id = #{campaign_id} AND ad_group_criterion.type = 'USER_LIST' QUERY # Issues the search request. response = client.service.google_ads.search( customer_id: customer_id, query: query, page_size: PAGE_SIZE, ) # Iterates over all rows in all pages. Prints the results and adds the ad # group criteria resource names to the list. response.each do |row| ad_group_criterion_resource_name = row.ad_group_criterion.resource_name puts "Ad group criterion with resource name " \ "'#{ad_group_criterion_resource_name}' was found" user_list_criteria << ad_group_criterion_resource_name end user_list_criteria end
Perl
sub get_user_list_ad_group_criteria { my ($api_client, $customer_id, $campaign_id) = @_; my $user_list_criterion_resource_names = []; # Create a search stream request that will retrieve all of the user list ad # group criteria under a campaign. my $search_stream_request = Google::Ads::GoogleAds::V17::Services::GoogleAdsService::SearchGoogleAdsStreamRequest ->new({ customerId => $customer_id, query => sprintf( "SELECT ad_group_criterion.criterion_id " . "FROM ad_group_criterion " . "WHERE campaign.id = %d AND ad_group_criterion.type = 'USER_LIST'", $campaign_id )}); my $search_stream_handler = Google::Ads::GoogleAds::Utils::SearchStreamHandler->new({ service => $api_client->GoogleAdsService(), request => $search_stream_request }); # Issue a search request and process the stream response. $search_stream_handler->process_contents( sub { # Display the results and add the resource names to the list. my $google_ads_row = shift; my $ad_group_criterion_resource_name = $google_ads_row->{adGroupCriterion}{resourceName}; printf "Ad group criterion with resource name '%s' was found.\n", $ad_group_criterion_resource_name; push(@$user_list_criterion_resource_names, $ad_group_criterion_resource_name); }); return $user_list_criterion_resource_names; }
然後移除傳回的所有廣告群組條件目標。
Java
private void removeExistingListCriteriaFromAdGroup( GoogleAdsClient googleAdsClient, long customerId, long campaignId) { // Retrieves all of the ad group criteria under a campaign. List<String> adGroupCriteria = getUserListAdGroupCriterion(googleAdsClient, customerId, campaignId); List<AdGroupCriterionOperation> operations = new ArrayList<>(); // Creates a list of remove operations. for (String adGroupCriterion : adGroupCriteria) { operations.add(AdGroupCriterionOperation.newBuilder().setRemove(adGroupCriterion).build()); } // Creates the ad group criterion service. try (AdGroupCriterionServiceClient adGroupCriterionServiceClient = googleAdsClient.getLatestVersion().createAdGroupCriterionServiceClient()) { // Removes the ad group criterion. MutateAdGroupCriteriaResponse response = adGroupCriterionServiceClient.mutateAdGroupCriteria( Long.toString(customerId), operations); // Gets and prints the results. System.out.printf("Removed %d ad group criteria.%n", response.getResultsCount()); for (MutateAdGroupCriterionResult result : response.getResultsList()) { System.out.printf( "Successfully removed ad group criterion with resource name '%s'.%n", result.getResourceName()); } } }
C#
private void RemoveExistingListCriteriaFromAdGroup(GoogleAdsClient client, long customerId, long campaignId) { // Get the AdGroupCriterionService client. AdGroupCriterionServiceClient adGroupCriterionServiceClient = client.GetService(Services.V17.AdGroupCriterionService); // Retrieve all of the ad group criteria under a campaign. List<string> adGroupCriteria = GetUserListAdGroupCriteria(client, customerId, campaignId); // Create a list of remove operations. List<AdGroupCriterionOperation> operations = adGroupCriteria.Select(adGroupCriterion => new AdGroupCriterionOperation { Remove = adGroupCriterion }).ToList(); // Remove the ad group criteria and print the resource names of the removed criteria. MutateAdGroupCriteriaResponse mutateAdGroupCriteriaResponse = adGroupCriterionServiceClient.MutateAdGroupCriteria(customerId.ToString(), operations); Console.WriteLine($"Removed {mutateAdGroupCriteriaResponse.Results.Count} ad group " + "criteria."); foreach (MutateAdGroupCriterionResult result in mutateAdGroupCriteriaResponse.Results) { Console.WriteLine("Successfully removed ad group criterion with resource name " + $"'{result.ResourceName}'."); } }
PHP
private static function removeExistingListCriteriaFromAdGroup( GoogleAdsClient $googleAdsClient, int $customerId, int $campaignId ) { // Retrieves all of the ad group criteria under a campaign. $allAdGroupCriteria = self::getUserListAdGroupCriteria( $googleAdsClient, $customerId, $campaignId ); $removeOperations = []; // Creates a list of remove operations. foreach ($allAdGroupCriteria as $adGroupCriterionResourceName) { $operation = new AdGroupCriterionOperation(); $operation->setRemove($adGroupCriterionResourceName); $removeOperations[] = $operation; } // Issues a mutate request to remove the ad group criteria. $adGroupCriterionServiceClient = $googleAdsClient->getAdGroupCriterionServiceClient(); /** @var MutateAdGroupCriteriaResponse $adGroupCriteriaResponse */ $adGroupCriteriaResponse = $adGroupCriterionServiceClient->mutateAdGroupCriteria( MutateAdGroupCriteriaRequest::build($customerId, $removeOperations) ); foreach ($adGroupCriteriaResponse->getResults() as $adGroupCriteriaResult) { printf( "Successfully removed ad group criterion with resource name '%s'.%s", $adGroupCriteriaResult->getResourceName(), PHP_EOL ); } }
Python
def remove_existing_criteria_from_ad_group(client, customer_id, campaign_id): """Removes all ad group criteria targeting a user list under a campaign. This is a necessary step before targeting a user list at the campaign level. Args: client: an initialized GoogleAdsClient instance. customer_id: a str client customer ID. campaign_id: a str ID for a campaign that will have all ad group criteria that targets user lists removed. """ # Retrieves all of the ad group criteria under a campaign. all_ad_group_criteria = get_user_list_ad_group_criteria( client, customer_id, campaign_id ) # Creates a list of remove operations. remove_operations = [] for ad_group_criterion_resource_name in all_ad_group_criteria: remove_operation = client.get_type("AdGroupCriterionOperation") remove_operation.remove = ad_group_criterion_resource_name remove_operations.append(remove_operation) ad_group_criterion_service = client.get_service("AdGroupCriterionService") response = ad_group_criterion_service.mutate_ad_group_criteria( customer_id=customer_id, operations=remove_operations ) print( "Successfully removed ad group criterion with resource name: " f"'{response.results[0].resource_name}'" )
小茹
def remove_existing_list_criteria_from_ad_group( client, customer_id, campaign_id ) # Retrieves all of the ad group criteria under a campaign. ad_group_criteria = get_user_list_ad_group_criterion( client, customer_id, campaign_id) # Creates a list of remove operations. operations = [] ad_group_criteria.each do |agc| operations << client.operation.remove_resource.ad_group_criterion(agc) end # Issues a mutate request to remove all ad group criteria. response = client.service.ad_group_criterion.mutate_ad_group_criteria( customer_id: customer_id, operations: operations, ) puts "Removed #{response.results.size} ad group criteria." response.results.each do |result| puts "Successfully removed ad group criterion with resource name " \ "'#{result.resource_name}'" end end
Perl
sub remove_existing_list_criteria_from_ad_group { my ($api_client, $customer_id, $campaign_id) = @_; # Retrieve all of the ad group criteria under a campaign. my $ad_group_criteria = get_user_list_ad_group_criteria($api_client, $customer_id, $campaign_id); # Create a list of remove operations. my $operations = []; foreach my $ad_group_criterion (@$ad_group_criteria) { push( @$operations, Google::Ads::GoogleAds::V17::Services::AdGroupCriterionService::AdGroupCriterionOperation ->new({ remove => $ad_group_criterion })); } # Remove the ad group criteria and print the resource names of the removed criteria. my $ad_group_criteria_response = $api_client->AdGroupCriterionService()->mutate({ customerId => $customer_id, operations => $operations }); printf "Removed %d ad group criteria.\n", scalar @{$ad_group_criteria_response->{results}}; foreach my $result (@{$ad_group_criteria_response->{results}}) { printf "Successfully removed ad group criterion with resource name '%s'.\n", $result->{resourceName}; } }
切換時,必須一併移除現有廣告活動層級的使用者名單條件 相關程序剛好符合上述範例,
利用 CampaignCriterion 將廣告活動中的廣告指定至使用者名單。
Java
private String targetAdsInCampaignToUserList( GoogleAdsClient googleAdsClient, long customerId, long campaignId, String userList) { // Creates the campaign criterion. CampaignCriterion campaignCriterion = CampaignCriterion.newBuilder() .setCampaign(ResourceNames.campaign(customerId, campaignId)) .setUserList(UserListInfo.newBuilder().setUserList(userList).build()) .build(); // Creates the operation. CampaignCriterionOperation operation = CampaignCriterionOperation.newBuilder().setCreate(campaignCriterion).build(); // Creates the campaign criterion service client. try (CampaignCriterionServiceClient campaignCriterionServiceClient = googleAdsClient.getLatestVersion().createCampaignCriterionServiceClient()) { // Adds the campaign criterion. MutateCampaignCriteriaResponse response = campaignCriterionServiceClient.mutateCampaignCriteria( Long.toString(customerId), ImmutableList.of(operation)); // Gets and prints the campaign criterion resource name. String campaignCriterionResourceName = response.getResults(0).getResourceName(); System.out.printf( "Successfully created campaign criterion with resource name '%s' " + "targeting user list with resource name '%s' with campaign with ID %d.%n", campaignCriterionResourceName, userList, campaignId); return campaignCriterionResourceName; } }
C#
private string TargetAdsInCampaignToUserList( GoogleAdsClient client, long customerId, long campaignId, string userListResourceName) { // Get the CampaignCriterionService client. CampaignCriterionServiceClient campaignCriterionServiceClient = client.GetService(Services.V17.CampaignCriterionService); // Create the campaign criterion. CampaignCriterion campaignCriterion = new CampaignCriterion { Campaign = ResourceNames.Campaign(customerId, campaignId), UserList = new UserListInfo { UserList = userListResourceName } }; // Create the operation. CampaignCriterionOperation campaignCriterionOperation = new CampaignCriterionOperation { Create = campaignCriterion }; // Add the campaign criterion and print the resulting criterion's resource name. MutateCampaignCriteriaResponse mutateCampaignCriteriaResponse = campaignCriterionServiceClient.MutateCampaignCriteria(customerId.ToString(), new[] { campaignCriterionOperation }); string campaignCriterionResourceName = mutateCampaignCriteriaResponse.Results.First().ResourceName; Console.WriteLine("Successfully created campaign criterion with resource name " + $"'{campaignCriterionResourceName}' targeting user list with resource name " + $"'{userListResourceName}' with campaign with ID {campaignId}."); return campaignCriterionResourceName; }
PHP
private static function targetAdsInCampaignToUserList( GoogleAdsClient $googleAdsClient, int $customerId, int $campaignId, string $userListResourceName ): string { // Creates the campaign criterion. $campaignCriterion = new CampaignCriterion([ 'campaign' => ResourceNames::forCampaign($customerId, $campaignId), 'user_list' => new UserListInfo(['user_list' => $userListResourceName]) ]); // Creates the operation. $operation = new CampaignCriterionOperation(); $operation->setCreate($campaignCriterion); // Issues a mutate request to create a campaign criterion. $campaignCriterionServiceClient = $googleAdsClient->getCampaignCriterionServiceClient(); /** @var MutateCampaignCriteriaResponse $campaignCriteriaResponse */ $campaignCriteriaResponse = $campaignCriterionServiceClient->mutateCampaignCriteria( MutateCampaignCriteriaRequest::build($customerId, [$operation]) ); $campaignCriterionResourceName = $campaignCriteriaResponse->getResults()[0]->getResourceName(); printf( "Successfully created campaign criterion with resource name '%s' " . "targeting user list with resource name '%s' with campaign with ID %d.%s", $campaignCriterionResourceName, $userListResourceName, $campaignId, PHP_EOL ); return $campaignCriterionResourceName; }
Python
def target_ads_in_campaign_to_user_list( client, customer_id, campaign_id, user_list_resource_name ): """Creates a campaign criterion that targets a user list with a campaign. Args: client: an initialized GoogleAdsClient instance. customer_id: a str client customer ID used to create an campaign criterion. campaign_id: a str ID for a campaign used to create a campaign criterion that targets members of a user list. user_list_resource_name: a str resource name for a user list. Returns: a str resource name for a campaign criterion. """ campaign_criterion_operation = client.get_type("CampaignCriterionOperation") campaign_criterion = campaign_criterion_operation.create campaign_criterion.campaign = client.get_service( "CampaignService" ).campaign_path(customer_id, campaign_id) campaign_criterion.user_list.user_list = user_list_resource_name campaign_criterion_service = client.get_service("CampaignCriterionService") response = campaign_criterion_service.mutate_campaign_criteria( customer_id=customer_id, operations=[campaign_criterion_operation] ) resource_name = response.results[0].resource_name print( "Successfully created campaign criterion with resource name " f"'{resource_name}' targeting user list with resource name " f"'{user_list_resource_name}' with campaign with ID {campaign_id}" ) return resource_name
小茹
def target_ads_in_campaign_to_user_list( client, customer_id, campaign_id, user_list ) # Creates the campaign criterion targeting members of the user list. operation = client.operation.create_resource.campaign_criterion do |cc| cc.campaign = client.path.campaign(customer_id, campaign_id) cc.user_list = client.resource.user_list_info do |info| info.user_list = user_list end end # Issues a mutate request to create the campaign criterion. response = client.service.campaign_criterion.mutate_campaign_criteria( customer_id: customer_id, operations: [operation], ) campaign_criterion_resource_name = response.results.first.resource_name puts "Successfully created campaign criterion with resource name " \ "'#{campaign_criterion_resource_name}' targeting user list with resource name " \ "'#{user_list}' with campaign with ID #{campaign_id}" campaign_criterion_resource_name end
Perl
sub target_ads_in_campaign_to_user_list { my ($api_client, $customer_id, $campaign_id, $user_list_resource_name) = @_; # Create the campaign criterion. my $campaign_criterion = Google::Ads::GoogleAds::V17::Resources::CampaignCriterion->new({ campaign => Google::Ads::GoogleAds::V17::Utils::ResourceNames::campaign( $customer_id, $campaign_id ), userList => Google::Ads::GoogleAds::V17::Common::UserListInfo->new({ userList => $user_list_resource_name })}); # Create the operation. my $campaign_criterion_operation = Google::Ads::GoogleAds::V17::Services::CampaignCriterionService::CampaignCriterionOperation ->new({ create => $campaign_criterion }); # Add the campaign criterion and print the resulting criterion's resource name. my $campaign_criteria_response = $api_client->CampaignCriterionService()->mutate({ customerId => $customer_id, operations => [$campaign_criterion_operation]}); my $campaign_criterion_resource_name = $campaign_criteria_response->{results}[0]{resourceName}; printf "Successfully created campaign criterion with resource name '%s' " . "targeting user list with resource name '%s' with campaign with ID %d.\n", $campaign_criterion_resource_name, $user_list_resource_name, $campaign_id; return $campaign_criterion_resource_name; }
查看名單成效
如要收集目標對象區隔的成效資料,請進行搜尋
對 ad_group_audience_view
提出的要求
或 campaign_audience_view
資源
舉例來說,您可以查看 conversions
或 cost_per_conversion
,
判斷指定目標對象區隔是否促成更多
,即可據此調整出價調節係數。
SELECT
ad_group_criterion.criterion_id,
metrics.conversions,
metrics.cost_per_conversion
FROM ad_group_audience_view