La publicación de anuncios de generación de demanda se controla mediante la segmentación asignada al socio principal, al anunciante, a la línea de pedido y a los grupos de anuncios.
Usa la segmentación asignada a una línea de pedido y a un grupo de anuncios de generación de demanda para llegar a tus clientes ideales y mejorar el rendimiento de la campaña.
Decide dónde asignar tu segmentación
La segmentación se puede asignar tanto a las líneas de pedido como a los grupos de anuncios de generación de demanda.
Asigna la segmentación a una línea de pedido de generación de demanda si quieres que se aplique a todos los anuncios publicados en esa línea de pedido. De lo contrario, asigna la segmentación a grupos de anuncios individuales.
Compatibilidad con la segmentación por tipo de recurso de generación de demanda
Cada tipo de recurso admite ciertos tipos de segmentación.
La siguiente es una lista de los tipos de segmentación que admiten las líneas de pedido de generación de demanda:
TARGETING_TYPE_CARRIER_AND_ISPTARGETING_TYPE_DAY_AND_TIMETARGETING_TYPE_DEVICE_MAKE_MODELTARGETING_TYPE_DEVICE_TYPETARGETING_TYPE_GEO_REGIONTARGETING_TYPE_KEYWORDTARGETING_TYPE_LANGUAGETARGETING_TYPE_NEGATIVE_KEYWORD_LISTTARGETING_TYPE_OPERATING_SYSTEMTARGETING_TYPE_POI
La siguiente es una lista de los tipos de segmentación que admiten los grupos de anuncios de generación de demanda:
TARGETING_TYPE_AGE_RANGETARGETING_TYPE_APPTARGETING_TYPE_APP_CATEGORYTARGETING_TYPE_AUDIENCE_GROUPTARGETING_TYPE_CATEGORYTARGETING_TYPE_GENDERTARGETING_TYPE_GEO_REGIONTARGETING_TYPE_HOUSEHOLD_INCOMETARGETING_TYPE_KEYWORDTARGETING_TYPE_LANGUAGETARGETING_TYPE_PARENTAL_STATUSTARGETING_TYPE_URLTARGETING_TYPE_YOUTUBE_CHANNELTARGETING_TYPE_YOUTUBE_VIDEO
La compatibilidad de TARGETING_TYPE_GEO_REGION, TARGETING_TYPE_POI y
TARGETING_TYPE_LANGUAGE depende de la configuración del
demandGenSettings.geoLanguageTargetingEnabled campo
en el recurso LineItem superior. Si el campo es verdadero, la segmentación geográfica y por idioma solo se puede asignar a la línea de pedido superior. Si el campo es falso, esta segmentación solo se puede asignar a grupos de anuncios individuales.
Busca las opciones de segmentación disponibles
La segmentación se identifica según su tipo. Identifica las opciones de segmentación de una de las siguientes maneras:
- Usa un valor de enumeración pertinente, como con los tipos de enumeración
AgeRangeoExchange. - Recupera entidades segmentables, como canales o listas de ubicaciones, con el servicio relacionado.
- Recupera los IDs de las opciones de segmentación para un tipo de segmentación con los métodos
listysearch.
Recupera la segmentación existente
La segmentación existente restringe qué segmentación se puede agregar a una línea de pedido o a un grupo de anuncios.
Las líneas de pedido y los grupos de anuncios de generación de demanda solo muestran la segmentación TARGETING_TYPE_KEYWORD heredada. Esto significa que debes recuperar la segmentación del anunciante, la línea de pedido y el grupo de anuncios para tener un registro completo de toda la segmentación que afecta la publicación de anuncios.
Recupera la segmentación existente en todos los tipos de segmentación con solicitudes de lista masivas.
Recupera la segmentación existente del socio y del anunciante
A continuación, te mostramos cómo obtener la segmentación existente de un anunciante, incluida la segmentación heredada del socio:
Python
# Provide the ID of the advertiser. advertiser_id = advertiser-id # Create the page token variable. next_page_token = "" while True: # Execute the list request. response = ( service.advertisers() .listAssignedTargetingOptions( advertiserId=advertiser_id, pageToken=next_page_token, ) .execute() ) # If response is not empty, display the retrieved assigned targeting # options. if response: for assigned_targeting_option in response.get( "assignedTargetingOptions", [] ): ato_name = assigned_targeting_option.get( "name", None ) if ato_name: print(f"Assigned Targeting Option {ato_name}.") else: print(f"No targeting is currently assigned to {advertiser_id}.") sys.exit(1) # Update the next page token. # Break out of loop if there is no next page. if "nextPageToken" in response: next_page_token = response["nextPageToken"] else: break
Recupera la segmentación existente de la línea de pedido
A continuación, te mostramos cómo obtener la segmentación existente asignada directamente a una línea de pedido:
Python
# Provide the ID of the parent advertiser. advertiser_id = advertiser-id # Provide the ID of the Demand Gen line item. line_item_id = line-item-id # Create the page token variable. next_page_token = "" while True: # Execute the list request. response = ( service.advertisers() .lineItems() .bulkListAssignedTargetingOptions( advertiserId=advertiser_id, lineItemIds=[line_item_id], pageToken=next_page_token, ) .execute() ) # If response is not empty, display the retrieved assigned targeting # options line items. if response: for assigned_option in response.get( "lineItemAssignedTargetingOptions", [] ): ato_name = assigned_option.get("assignedTargetingOption", {}).get( "name", None ) if ato_name: print(f"Assigned Targeting Option {ato_name} found.") else: print(f"No targeting is currently assigned to {line_item_id}.") sys.exit(1) # Update the next page token. # Break out of loop if there is no next page. if "nextPageToken" in response: next_page_token = response["nextPageToken"] else: break
Recupera la segmentación existente del grupo de anuncios
A continuación, te mostramos cómo obtener la segmentación existente asignada directamente a un grupo de anuncios:
Python
# Provide the ID of the parent advertiser. advertiser_id = advertiser-id # Provide the ID of the ad group. ad_group_id = ad-group-id # Create the page token variable. next_page_token = "" while True: # Execute the list request. response = ( service.advertisers() .adGroups() .bulkListAssignedTargetingOptions( advertiserId=advertiser_id, adGroupIds=[ad_group_id], pageToken=next_page_token, ) .execute() ) # If response is not empty, display the retrieved assigned targeting # options line items. if response: for assigned_option in response.get( "adGroupAssignedTargetingOptions", [] ): ato_name = assigned_option.get("assignedTargetingOption", {}).get( "name", None ) if ato_name: print(f"Assigned Targeting Option {ato_name} found.") else: print(f"No targeting is currently assigned to {ad_group_id}.") sys.exit(1) # Update the next page token. # Break out of loop if there is no next page. if "nextPageToken" in response: next_page_token = response["nextPageToken"] else: break
Asigna segmentación a los recursos
Debes realizar solicitudes independientes para actualizar la segmentación de la línea de pedido y del grupo de anuncios.
Asigna la segmentación de la línea de pedido
A continuación, te mostramos cómo agregar la siguiente lógica de segmentación a una línea de pedido:
- Solo se publican anuncios en computadoras.
No se realizan ofertas por el inventario que se publica junto con el contenido que coincide con la palabra clave "helado".
Python
# Provide the ID of the parent advertiser. advertiser_id = advertiser-id # Provide the ID of the line item. line_item_id = line-item-id # Build the "ice cream" negative keyword assigned targeting option. keyword_assigned_targeting_option = { "keywordDetails": {"keyword": "ice cream", "negative": True} } # Build the delete request for device type targeting to remove all device # types to only target computers. device_type_delete_request = { "targetingType": "TARGETING_TYPE_DEVICE_TYPE", "assignedTargetingOptionIds": [ "DEVICE_TYPE_SMART_PHONE", "DEVICE_TYPE_CONNECTED_TV", "DEVICE_TYPE_TABLET" ], } # Create a bulk edit request. bulk_edit_targeting_request = { "lineItemIds": [line_item_id], "createRequests": [ { "targetingType": "TARGETING_TYPE_KEYWORD", "assignedTargetingOptions": [ keyword_assigned_targeting_option ], } ], "deleteRequests": [ device_type_delete_request ] } # Build and execute request. response = ( service.advertisers() .lineItems() .bulkEditAssignedTargetingOptions( advertiserId=advertiser_id, body=bulk_edit_targeting_request ) .execute() ) # Print the request results. if ( "updatedLineItemIds" in response and len(response["updatedLineItemIds"]) != 0 ): print( f'Targeting configurations for {response["updatedLineItemIds"][0]} ' "were successfully updated." ) elif ( "failedLineItemIds" in response and len(response["failedLineItemIds"]) != 0 ): print( f'Targeting configurations for {response["failedLineItemIds"][0]} ' "failed to update." ) if "errors" in response and len(response["errors"]) != 0: print("The failed updates were caused by the following errors:") for error in response["errors"]: print(f'Code {error["code"]}: {error["message"]}') else: print("No successful or failed updates were reported.")
Asigna la segmentación del grupo de anuncios
A continuación, te mostramos cómo agregar la siguiente lógica de segmentación a un grupo de anuncios:
- Solo se publica para padres.
No se publica en el canal de YouTube proporcionado.
Python
# Provide the ID of the parent advertiser. advertiser_id = advertiser-id # Provide the ID of the ad group. ad_group_id = ad-group-id # Provide the YouTube channel ID to negatively target. yt_channel_id = youtube-channel-id # Build the assigned targeting option to negatively target the given YouTube # channel. youtube_channel_assigned_targeting_options = [ { "youtubeChannelDetails": { "channelId": yt_channel_id, "negative": True } }, ] # Build the assigned targeting options to target only parents. parental_status_assigned_targeting_options = [ { "parentalStatusDetails": { "parentalStatus": "PARENTAL_STATUS_PARENT" } }, ] # Create a bulk edit request. bulk_edit_targeting_request = { "adGroupIds": [ad_group_id], "createRequests": [ { "targetingType": "TARGETING_TYPE_YOUTUBE_CHANNEL", "assignedTargetingOptions": ( youtube_channel_assigned_targeting_options ) }, { "targetingType": "TARGETING_TYPE_PARENTAL_STATUS", "assignedTargetingOptions": ( parental_status_assigned_targeting_options ), } ] } # Build and execute request. response = ( service.advertisers() .adGroups() .bulkEditAssignedTargetingOptions( advertiserId=advertiser_id, body=bulk_edit_targeting_request ) .execute() ) # Print the request results. if ( "updatedAdGroupIds" in response and len(response["updatedAdGroupIds"]) != 0 ): print( f'Targeting configurations for {response["updatedAdGroupIds"][0]} ' "were successfully updated." ) elif ( "failedAdGroupIds" in response and len(response["failedAdGroupIds"]) != 0 ): print( f'Targeting configurations for {response["failedAdGroupIds"][0]} ' "failed to update." ) if "errors" in response and len(response["errors"]) != 0: print("The failed updates were caused by the following errors:") for error in response["errors"]: print(f'Code {error["code"]}: {error["message"]}') else: print("No successful or failed updates were reported.")