Criar público-alvo

Depois de preparar os dados dos clientes, use uma solicitação create para criar um público-alvo.

Saiba como criar um público-alvo segmentado por lista de clientes usando números de telefone do usuário com hash:

Java

// Provide the membership duration of the audience in days.
long membershipDurationDays = membership-duration-days;

// Provide the signals of consent for the customers.
String adUserDataConsent = ad-user-data-consent;
String adPersonalizationConsent = ad-personalization-consent;

// Provide the list of hashed phone numbers to use to populate the audience.
List<String> hashedPhoneNumbers = hashed-phone-numbers;

// Build list of ContactInfo objects.
List<ContactInfo> contactInfos = new ArrayList<>();
for (String hashedNumber : hashedPhoneNumbers) {
  contactInfos.add(
      new ContactInfo()
          .setHashedPhoneNumbers(Arrays.asList(hashedNumber)));
}

// Build the customer match FirstPartyAndPartnerAudience object.
FirstPartyAndPartnerAudience audience =
    new FirstPartyAndPartnerAudience()
        .setDisplayName(display-name)
        .setFirstPartyAndPartnerAudienceType("TYPE_FIRST_PARTY")
        .setAudienceType("CUSTOMER_MATCH_CONTACT_INFO")
        .setMembershipDurationDays(membershipDurationDays)
        .setContactInfoList(
            new ContactInfoList()
                .setContactInfos(contactInfos)
                .setConsent(
                    new Consent()
                        .setAdUserData(adUserDataConsent)
                        .setAdPersonalization(adPersonalizationConsent)));

// Call the API to create the audience.
FirstPartyAndPartnerAudience response =
    service
        .firstPartyAndPartnerAudiences()
        .create(audience)
        .setAdvertiserId(advertiser-id)
        .execute();

// Display the new audience ID.
System.out.printf(
    "Customer Match audience was created with ID %s.",
    response.getFirstPartyAndPartnerAudienceId());

Python

# Provide the parent advertiser ID to create the audience under.
advertiser_id = advertiser-id

# Provide the display name of the audience.
display_name = display-name

# Provide the membership duration of the audience in days.
membership_duration_days = membership-duration-days

# Provide the signals of consent for the customers.
ad_user_data_consent = ad-user-data-consent
ad_personalization_consent = ad-personalization-consent

# Provide the list of hashed phone numbers to use to populate the audience.
hashed_phone_numbers = hashed-phone-numbers

# Build list of ContactInfo objects.
contact_infos = []
for hashed_phone_number in hashed_phone_numbers:
  contact_infos.append({"hashedPhoneNumbers": [hashed_phone_number]})

# Create the customer match FirstPartyAndPartnerAudience object.
audience_obj = {
    "displayName": display_name,
    "firstPartyAndPartnerAudienceType": "TYPE_FIRST_PARTY",
    "audienceType": "CUSTOMER_MATCH_CONTACT_INFO",
    "membershipDurationDays": membership_duration_days,
    "contactInfoList": {
        "contactInfos": contact_infos,
        "consent": {
            "adUserData": ad_user_data_consent,
            "adPersonalization": ad_personalization_consent,
        },
    },
}

# Build and execute request.
audience_response = (
    service.firstPartyAndPartnerAudiences()
    .create(advertiserId=advertiser_id, body=audience_obj)
    .execute()
)

# Print ID of new audience.
print(
    "Customer Match audience was created with ID "
    f'{audience_response["firstPartyAndPartnerAudienceId"]}.'
)

PHP

// Provide the parent advertiser ID to create the audience under.
$advertiserId = advertiser-id;

// Provide the display name of the audience.
$displayName = display-name;

// Provide the membership duration of the audience in days.
$membershipDurationDays = membership-duration-days;

// Provide the signals of consent for the customers.
$adUserDataConsent = ad-user-data-consent;
$adPersonalizationConsent = ad-personalization-consent;

// Provide the list of hashed phone numbers to use to populate the audience.
$hashedPhoneNumbers = hashed-phone-numbers;

// Build list of ContactInfo objects.
$contactInfos = array();
foreach ($hashedPhoneNumbers as $hashedPhoneNumber) {
    $contactInfo = new Google_Service_DisplayVideo_ContactInfo();
    $contactInfo->setHashedPhoneNumbers(array($hashedPhoneNumber));
    $contactInfos[] = $contactInfo;
}

// Create the customer match FirstPartyAndPartnerAudience object.
$audience = new Google_Service_DisplayVideo_FirstPartyAndPartnerAudience();
$audience->setDisplayName($displayName);
$audience->setFirstPartyAndPartnerAudienceType('TYPE_FIRST_PARTY');
$audience->setAudienceType('CUSTOMER_MATCH_CONTACT_INFO');
$audience->setMembershipDurationDays($membershipDurationDays);

$contactInfoList = new Google_Service_DisplayVideo_ContactInfoList();
$contactInfoList->setContactInfos($contactInfos);
$consent = new Google_Service_DisplayVideo_Consent();
$consent->setAdUserData($adUserDataConsent);
$consent->setAdPersonalization($adPersonalizationConsent);
$contactInfoList->setConsent($consent);
$audience->setContactInfoList($contactInfoList);

$createAudienceOptParams = array(
    'advertiserId' => $advertiserId
);

// Call the API, creating the audience.
try {
    $result = $this->service->firstPartyAndPartnerAudiences->create($audience, $createAudienceOptParams);
} catch (\Exception $e) {
    $this->renderError($e);
    return;
}

// Print ID of new audience.
printf(
    '<p>Customer Match audience was created with ID %s.</p>',
    $result['firstPartyAndPartnerAudienceId']
);