กลุ่มเป้าหมาย

การกำหนดเป้าหมายแบบรวมของประเภทการกำหนดเป้าหมายส่วนใหญ่เกิดจากทรัพยากร AssignedTargetingOption หลายรายการ ภายในประเภทการกำหนดเป้าหมาย ตัวเลือกการกำหนดเป้าหมายที่กำหนดแต่ละรายการอาจระบุค่าที่แตกต่างกัน เช่น แต่ละเบราว์เซอร์สำหรับ TARGETING_TYPE_BROWSER หากต้องการให้ทรัพยากรกำหนดเป้าหมายเบราว์เซอร์เพิ่มเติม ก็ทำได้โดยสร้างตัวเลือกการกำหนดเป้าหมายใหม่ที่มอบหมาย TARGETING_TYPE_BROWSER ใต้ทรัพยากรดังกล่าว ในทำนองเดียวกัน หากไม่ต้องการกำหนดเป้าหมายเบราว์เซอร์ที่เจาะจงอีกต่อไป คุณสามารถลบตัวเลือกการกำหนดเป้าหมายที่กำหนดที่เกี่ยวข้องได้

การกำหนดกลุ่มเป้าหมายไม่เป็นไปตามรูปแบบโมดูลนี้ แต่ระบบจะกำหนดรหัสกลุ่มเป้าหมายทั้งหมดที่เกี่ยวข้องกับการกำหนดเป้าหมายของทรัพยากรให้กับทรัพยากรนั้นผ่าน AssignedTargetingOption ประเภท TARGETING_TYPE_AUDIENCE_GROUP รายการเดียว ระบบจะแสดงข้อผิดพลาดหากคุณพยายามกำหนดตัวเลือกการกำหนดเป้าหมายที่กำหนดให้กับกลุ่มเป้าหมายหลายกลุ่มให้กับทรัพยากร หน้านี้จะอธิบายรายละเอียดตรรกะที่บอกถึงตัวเลือกการกำหนดเป้าหมายที่กำหนดนี้ และอธิบายวิธีอัปเดตการกำหนดเป้าหมายกลุ่มเป้าหมายที่มีอยู่ให้ถูกต้อง

ตรรกะการกำหนดกลุ่มเป้าหมาย

ตัวเลือกการกําหนดเป้าหมายที่กำหนดกลุ่มเป้าหมายเดียวจะมีออบเจ็กต์ AudienceGroupAssignedTargetingOptionsDetails ชุดหนึ่งซึ่งประกอบด้วยรายการรหัสกลุ่มเป้าหมายหรือที่เรียกว่ากลุ่มเป้าหมาย เพื่อรวมและยกเว้นเมื่อแสดงโฆษณา การกำหนดเป้าหมายรวมของตัวเลือกการกำหนดเป้าหมายที่กำหนดเป็นผลจากการดำเนินการเชิงตรรกะต่อไปนี้

  • ออบเจ็กต์กลุ่มเป้าหมายเดี่ยวทุกประเภทจะรวมกลุ่มเป้าหมายที่รวมอยู่ตาม UNION
  • ช่อง includedFirstAndThirdAudienceGroups ซึ่งมีรายการออบเจ็กต์ FirstAndThirdPartyAudienceGroup จะรวมกลุ่มเป้าหมายตาม INTERSECTION
  • ช่องกลุ่มเป้าหมายทั้งหมดที่มีคำนำหน้าว่า "รวม" ซึ่งแสดงถึงรายชื่อผู้ใช้หรือกลุ่มรายการผู้ใช้ที่จะกำหนดเป้าหมายในเชิงบวกจะรวมเข้าด้วยกันโดย UNION
  • ช่องกลุ่มเป้าหมายที่ยกเว้นทั้งหมดจะรวมโดย UNION และส่วน "COMPLEMENT" ของผลลัพธ์จะรวมเข้ากับการกำหนดเป้าหมายเชิงบวกตาม INTERSECTION

ในทางปฏิบัติจะหมายความว่า AudienceGroupAssignedTargetingOptionsDetails ที่ได้จะกำหนดเป้าหมายผู้ใช้หากเป็นไปตามเงื่อนไขทั้ง 2 ข้อต่อไปนี้

  1. ผู้ใช้จัดเป็นกลุ่มเป้าหมายทุกกลุ่มในรายการ includedFirstAndThirdPartyAudienceGroups หรือจัดอยู่ในกลุ่มอย่างน้อย 1 กลุ่ม includedGoogleAudienceGroup, includedCustomListGroup หรือ includedCombinedAudienceGroup
  2. ผู้ใช้ไม่อยู่ใน excludedFirstAndThirdPartyAudienceGroup หรือ excludedGoogleAudienceGroup

อัปเดตการกำหนดกลุ่มเป้าหมาย

หากต้องการอัปเดตการกำหนดเป้าหมายกลุ่มเป้าหมายของรายการโฆษณา คุณต้องลบตัวเลือกการกำหนดเป้าหมายที่กำหนดให้ปัจจุบัน หากมี แล้วต้องสร้างตัวเลือกการกำหนดเป้าหมายใหม่ให้พร้อมกับการเปลี่ยนแปลงที่ต้องการ ซึ่งทำได้ในคำขอเดียวโดยใช้ advertisers.lineItems.bulkEditAssignedTargetingOptions

เสมอ

ด้านล่างคือตัวอย่างวิธีอัปเดตการกำหนดกลุ่มเป้าหมายที่มีอยู่ของรายการโฆษณาโดยการดึงข้อมูลการกำหนดเป้าหมายกลุ่มเป้าหมายที่มีอยู่ จากนั้นจึงส่งคำขอแก้ไขเป็นกลุ่ม

Java

long advertiserId = advertiser-id;
long lineItemId = line-item-id
List<Long> addedGoogleAudienceIds =
    Arrays.asList(google-audience-id-to-add,...);

// Build Google Audience targeting settings objects to add to audience
// targeting.
ArrayList<GoogleAudienceTargetingSetting> newGoogleAudienceSettings =
    new ArrayList<GoogleAudienceTargetingSetting>();

// Convert list of Google Audience IDs into list of settings.
for (Long googleAudienceId : addedGoogleAudienceIds) {
  newGoogleAudienceSettings.add(new GoogleAudienceTargetingSetting()
      .setGoogleAudienceId(googleAudienceId));
}

// Create relevant bulk edit request objects.
BulkEditAssignedTargetingOptionsRequest requestContent =
    new BulkEditAssignedTargetingOptionsRequest();
requestContent.setLineItemIds(Arrays.asList(lineItemId));

AudienceGroupAssignedTargetingOptionDetails updatedAudienceGroupDetails;
ArrayList<DeleteAssignedTargetingOptionsRequest> audienceGroupDeleteRequests =
    new ArrayList<DeleteAssignedTargetingOptionsRequest>();

try {
  // Retrieve existing audience group targeting.
  AssignedTargetingOption existingAudienceGroupTargetingOption =
      service
          .advertisers()
          .lineItems()
          .targetingTypes()
          .assignedTargetingOptions()
          .get(
               advertiserId,
               lineItemId,
               "TARGETING_TYPE_AUDIENCE_GROUP",
               "audienceGroup"
          ).execute();

  // Extract existing audience group targeting details.
  updatedAudienceGroupDetails =
      existingAudienceGroupTargetingOption.getAudienceGroupDetails();

  // Build and add delete request for existing audience group targeting.
  ArrayList<String> deleteAudienceGroupAssignedTargetingIds =
      new ArrayList<String>();
  deleteAudienceGroupAssignedTargetingIds.add("audienceGroup");

  audienceGroupDeleteRequests
      .add(new DeleteAssignedTargetingOptionsRequest()
      .setTargetingType("TARGETING_TYPE_AUDIENCE_GROUP")
      .setAssignedTargetingOptionIds(
          deleteAudienceGroupAssignedTargetingIds
      )
  );
} catch (Exception e) {
  updatedAudienceGroupDetails =
      new AudienceGroupAssignedTargetingOptionDetails();
}

// Set delete requests in edit request.
requestContent.setDeleteRequests(audienceGroupDeleteRequests);

// Construct new group of Google Audiences to include in targeting.
GoogleAudienceGroup updatedIncludedGoogleAudienceGroup =
    updatedAudienceGroupDetails.getIncludedGoogleAudienceGroup();
if (updatedIncludedGoogleAudienceGroup != null) {
  List<GoogleAudienceTargetingSetting> updatedGoogleAudienceSettings =
      updatedIncludedGoogleAudienceGroup.getSettings();
  updatedGoogleAudienceSettings.addAll(newGoogleAudienceSettings);
  updatedIncludedGoogleAudienceGroup
      .setSettings(updatedGoogleAudienceSettings);
} else {
  updatedIncludedGoogleAudienceGroup = new GoogleAudienceGroup();
  updatedIncludedGoogleAudienceGroup.setSettings(newGoogleAudienceSettings);
}

// Add new Google Audience group to audience group targeting details.
updatedAudienceGroupDetails
    .setIncludedGoogleAudienceGroup(updatedIncludedGoogleAudienceGroup);

// Create new targeting option to assign.
AssignedTargetingOption newAudienceGroupTargeting =
    new AssignedTargetingOption();
newAudienceGroupTargeting
    .setAudienceGroupDetails(updatedAudienceGroupDetails);

// Build audience group targeting create request and add to list of create
// requests.
ArrayList<AssignedTargetingOption> createAudienceGroupAssignedTargetingOptions =
    new ArrayList<AssignedTargetingOption>();
createAudienceGroupAssignedTargetingOptions.add(newAudienceGroupTargeting);
ArrayList<CreateAssignedTargetingOptionsRequest> targetingCreateRequests =
    new ArrayList<CreateAssignedTargetingOptionsRequest>();
targetingCreateRequests.add(new CreateAssignedTargetingOptionsRequest()
    .setTargetingType("TARGETING_TYPE_AUDIENCE_GROUP")
    .setAssignedTargetingOptions(
        createAudienceGroupAssignedTargetingOptions
    )
);

// Set create requests in edit request.
requestContent.setCreateRequests(targetingCreateRequests);

// Configure and execute the bulk list request.
BulkEditAssignedTargetingOptionsResponse response =
    service.advertisers().lineItems()
        .bulkEditAssignedTargetingOptions(
            advertiserId,
            requestContent).execute();

// Print the line item IDs that successfully updated.
if (response.getUpdatedLineItemIds() != null && !response.getUpdatedLineItemIds().isEmpty()) {
  System.out.printf(
      "Targeting configurations for the following line item IDs were updated: %s.\n",
      Arrays.toString(response.getUpdatedLineItemIds().toArray()));
}

// Print the line item IDs the failed to update.
if (response.getFailedLineItemIds() != null && !response.getFailedLineItemIds().isEmpty()) {
  System.out.printf(
      "Targeting configurations for the following line item IDs failed to update: %s.\n",
      Arrays.toString(response.getFailedLineItemIds().toArray()));

  // Print errors thrown for failed updates.
  System.out.println("The failed updates were caused by the following errors:");
  for (Status error : response.getErrors()) {
    System.out.printf("Error Code: %s, Message: %s\n", error.getCode(), error.getMessage());
  }
}

Python

advertiser_id = advertiser-id
line_item_id = line-item-id
added_google_audiences = [google-audience-id-to-add,...]

# Build Google Audience targeting settings objects to create.
new_google_audience_targeting_settings = []
for google_audience_id in added_google_audiences:
  new_google_audience_targeting_settings.append(
      {'googleAudienceId': google_audience_id}
  )

try:
  # Retrieve any existing line item audience targeting.
  retrieved_audience_targeting = service.advertisers().lineItems(
  ).targetingTypes().assignedTargetingOptions().get(
      advertiserId=advertiser_id,
      lineItemId=line_item_id,
      targetingType="TARGETING_TYPE_AUDIENCE_GROUP",
      assignedTargetingOptionId="audienceGroup"
  ).execute()
except Exception:
  print("Error retrieving existing audience targeting. Assuming no "
        "existing audience targeting.")
  retrieved_audience_targeting = {}
updated_audience_group_details = {}

# Copy over any existing audience targeting.
if 'audienceGroupDetails' in retrieved_audience_targeting:
  updated_audience_group_details = retrieved_audience_targeting[
      'audienceGroupDetails']

# Append the new Google Audience IDs to any existing positive Google
# audience targeting.
if 'includedGoogleAudienceGroup' in updated_audience_group_details:
  updated_audience_group_details[
      'includedGoogleAudienceGroup']['settings'].extend(
          new_google_audience_targeting_settings)
else:
  updated_audience_group_details['includedGoogleAudienceGroup'] = {
      'settings': new_google_audience_targeting_settings
  }

# Build bulk edit request.
bulk_edit_request = {
    'lineItemIds': [line_item_id],
    'deleteRequests': [
        {
            'targetingType': "TARGETING_TYPE_AUDIENCE_GROUP",
            'assignedTargetingOptionIds': [
                "audienceGroup"
            ]
        }
    ],
    'createRequests': [
        {
            'targetingType': "TARGETING_TYPE_AUDIENCE_GROUP",
            'assignedTargetingOptions': [
                {'audienceGroupDetails': updated_audience_group_details}
            ]
        }
    ]
}

# Update the audience targeting
response = service.advertisers().lineItems(
).bulkEditAssignedTargetingOptions(
    advertiserId=advertiser_id,
    body=bulk_edit_request
).execute()

# Print the line item IDs the successfully updated.
if 'updatedLineItemIds' in response:
  print("Targeting configurations for the following line item IDs were updated: %s"
        % response['updatedLineItemIds'])

# Print the line item IDs the failed to update.
if 'failedLineItemIds' in response:
  print("Targeting configurations for the following line item IDs failed to update: %s"
        % response['failedLineItemIds'])
  if 'errors' in response:
    print("The failed updates were caused by the following errors:")
    for error in response["errors"]:
      print("Error code: %s, Message: %s" % (error["code"], error["message"]))

PHP

$advertiserId = advertiser-id;
$lineItemId = line-item-id;
$addedGoogleAudienceIds = array(google-audience-id-to-add,...);

// Convert list of Google Audience IDs into list of Google Audience
// settings.
$newGoogleAudienceSettings = array();
foreach ($addedGoogleAudienceIds as $googleAudienceId) {
    $newSetting =
        new Google_Service_DisplayVideo_GoogleAudienceTargetingSetting();
    $newSetting->setGoogleAudienceId($googleAudienceId);
    $newGoogleAudienceSettings[] = $newSetting;
}

// Create a bulk edit request.
$requestBody =
    new Google_Service_DisplayVideo_BulkEditAssignedTargetingOptionsRequest();
$requestBody->setLineItemIds([$lineItemId]);

$audienceGroupDeleteRequests = array();

try {
    // Retrieve existing audience group targeting.
    $existingAudienceGroupTargetingOption = $service
        ->advertisers_lineItems_targetingTypes_assignedTargetingOptions
        ->get(
            $advertiserId,
            $lineItemId,
            'TARGETING_TYPE_AUDIENCE_GROUP',
            'audienceGroup'
        );

    // Extract existing audience group targeting details.
    $updatedAudienceGroupDetails =
        $existingAudienceGroupTargetingOption
            ->getAudienceGroupDetails();

    // Build and add delete request for existing audience group
    // targeting.
    $deleteAudienceGroupAssignedTargetingIds = array();
    $deleteAudienceGroupAssignedTargetingIds[] = "audienceGroup";

    $audienceGroupDeleteRequest =
        new Google_Service_DisplayVideo_DeleteAssignedTargetingOptionsRequest();
    $audienceGroupDeleteRequest
        ->setTargetingType('TARGETING_TYPE_AUDIENCE_GROUP');
    $audienceGroupDeleteRequest
        ->setAssignedTargetingOptionIds(
            $deleteAudienceGroupAssignedTargetingIds
        );
    $audienceGroupDeleteRequests[] = $audienceGroupDeleteRequest;
} catch (\Exception $e) {
    $updatedAudienceGroupDetails =
        new Google_Service_DisplayVideo_AudienceGroupAssignedTargetingOptionDetails();
}

// Set delete requests in edit request.
$requestBody->setDeleteRequests($audienceGroupDeleteRequests);

// Construct new group of Google Audiences to include in targeting.
$updatedIncludedGoogleAudienceGroup = $updatedAudienceGroupDetails
    ->getIncludedGoogleAudienceGroup();

if (!empty($updatedIncludedGoogleAudienceGroup)) {
    // Get existing settings.
    $updatedGoogleAudienceSettings =
    $updatedIncludedGoogleAudienceGroup->getSettings();

    // Add new Google Audiences to existing list.
    $updatedGoogleAudienceSettings = array_merge(
        $updatedGoogleAudienceSettings,
        $newGoogleAudienceSettings
    );

    // Set updated Google Audience list.
    $updatedIncludedGoogleAudienceGroup
        ->setSettings($updatedGoogleAudienceSettings);
} else {
    // Create new Google Audience group.
    $updatedIncludedGoogleAudienceGroup =
        new Google_Service_DisplayVideo_GoogleAudienceGroup();

    // Set list of new Google Audiences for targeting.
    $updatedIncludedGoogleAudienceGroup
        ->setSettings($newGoogleAudienceSettings);
}

// Add new Google Audience group to audience group targeting details.
$updatedAudienceGroupDetails
    ->setIncludedGoogleAudienceGroup(
        $updatedIncludedGoogleAudienceGroup
    );

// Create new targeting option to assign.
$newAudienceGroupTargeting =
    new Google_Service_DisplayVideo_AssignedTargetingOption();
$newAudienceGroupTargeting
    ->setAudienceGroupDetails($updatedAudienceGroupDetails);

// Build audience group targeting create request and add to list of
// create requests.
$createAudienceGroupAssignedTargetingOptions = array();
$createAudienceGroupAssignedTargetingOptions[] =
    $newAudienceGroupTargeting;
$createAudienceGroupTargetingRequest =
    new Google_Service_DisplayVideo_CreateAssignedTargetingOptionsRequest();
$createAudienceGroupTargetingRequest->setTargetingType(
    "TARGETING_TYPE_AUDIENCE_GROUP"
);
$createAudienceGroupTargetingRequest->setAssignedTargetingOptions(
    $createAudienceGroupAssignedTargetingOptions
);
$createRequests[] = $createAudienceGroupTargetingRequest;

// Set create requests in edit request.
$requestBody->setCreateRequests($createRequests);

// Call the API, editing the assigned targeting options for the
// identified line item.
$response = $service
    ->advertisers_lineItems
    ->bulkEditAssignedTargetingOptions(
        $advertiserId,
        $requestBody
    );

// Print the line item IDs the successfully updated.
if (!empty($response->getUpdatedLineItemIds())) {
    printf('Targeting configurations for the following line item IDs were updated:\n');
    foreach ($response->getUpdatedLineItemIds() as $id) {
        printf('%s\n', $id);
    }
}

// Print the line item IDs the failed to update.
if (!empty($response->getFailedLineItemIds())) {
    print('Targeting configurations for the following line item IDs failed to update:\n');
    foreach ($response->getFailedLineItemIds() as $id) {
        printf('%s\n', $id);
    }
    print('The failed updates were caused by the following errors:\n');
    foreach ($response->getErrors() as $error) {
        printf('Error Code: %s, Message: %s\n', $error->getCode(), $error->getMessage());
    }
}

เพิ่มประสิทธิภาพการกำหนดกลุ่มเป้าหมาย

Display & Video 360 มอบความสามารถในการขยายการเข้าถึงของกลุ่มเป้าหมายที่เลือกไปยังผู้ใช้ใหม่และผู้ใช้ที่เกี่ยวข้องผ่านฟีเจอร์การกําหนดเป้าหมายแบบเพิ่มประสิทธิภาพ

การกำหนดเป้าหมายแบบเพิ่มประสิทธิภาพจะตั้งค่าที่ระดับรายการโฆษณาและกำหนดค่าได้ผ่านช่อง targetingExpansion ในทรัพยากร LineItem