Dịch vụ chiến dịch DoubleClick

Dịch vụ Chiến dịch DoubleClick cho phép bạn sử dụng API quản lý quảng cáo và báo cáo DCM/IDFA trong Apps Script. API này cung cấp quyền truy cập có lập trình vào Báo cáo Trình quản lý chiến dịch DoubleClick (DCM) và Báo cáo Tiếp thị kỹ thuật số của DoubleClick (DDM).

Tài liệu tham khảo

Để biết thông tin chi tiết về dịch vụ này, hãy xem tài liệu tham khảo cho API báo cáo và quản lý quảng cáo DCM/IDFA. Giống như tất cả các dịch vụ nâng cao trong Apps Script, dịch vụ Chiến dịch DoubleClick sử dụng cùng đối tượng, phương thức và thông số như API công khai. Để biết thêm thông tin, hãy xem phần Cách xác định chữ ký phương thức.

Để báo cáo vấn đề và tìm thông tin hỗ trợ khác, hãy xem Hướng dẫn hỗ trợ về báo cáo và quản lý quảng cáo DCM/IDFA.

Mã mẫu

Mã mẫu bên dưới sử dụng phiên bản 3.3 của API.

Lấy danh sách hồ sơ người dùng

Mẫu này sẽ ghi lại tất cả hồ sơ người dùng có trong tài khoản.

advanced/doubleclick.gs
/**
 * Logs all of the user profiles available in the account.
 */
function listUserProfiles() {
  // Retrieve the list of available user profiles
  try {
    const profiles = DoubleClickCampaigns.UserProfiles.list();

    if (profiles.items) {
      // Print out the user ID and name of each
      for (let i = 0; i < profiles.items.length; i++) {
        const profile = profiles.items[i];
        console.log('Found profile with ID %s and name "%s".',
            profile.profileId, profile.userName);
      }
    }
  } catch (e) {
    // TODO (Developer) - Handle exception
    console.log('Failed with error: %s', e.error);
  }
}

Nhận danh sách các chiến dịch đang hoạt động

Mẫu này ghi nhật ký tên và mã nhận dạng của tất cả chiến dịch đang hoạt động. Hãy lưu ý việc sử dụng mã phân trang để truy xuất toàn bộ danh sách.

advanced/doubleclick.gs
/**
 * Logs names and ID's of all active campaigns.
 * Note the use of paging tokens to retrieve the whole list.
 */
function listActiveCampaigns() {
  const profileId = '1234567'; // Replace with your profile ID.
  const fields = 'nextPageToken,campaigns(id,name)';
  let result;
  let pageToken;
  try {
    do {
      result = DoubleClickCampaigns.Campaigns.list(profileId, {
        'archived': false,
        'fields': fields,
        'pageToken': pageToken
      });
      if (result.campaigns) {
        for (let i = 0; i < result.campaigns.length; i++) {
          const campaign = result.campaigns[i];
          console.log('Found campaign with ID %s and name "%s".',
              campaign.id, campaign.name);
        }
      }
      pageToken = result.nextPageToken;
    } while (pageToken);
  } catch (e) {
    // TODO (Developer) - Handle exception
    console.log('Failed with error: %s', e.error);
  }
}

Tạo nhà quảng cáo và chiến dịch mới

Mẫu này sẽ tạo một nhà quảng cáo mới và tạo một chiến dịch mới với nhà quảng cáo đó. Chiến dịch được đặt để kéo dài trong một tháng.

advanced/doubleclick.gs
/**
 * Creates a new advertiser, and creates a new campaign with that advertiser.
 * The campaign is set to last for one month.
 */
function createAdvertiserAndCampaign() {
  const profileId = '1234567'; // Replace with your profile ID.

  const advertiser = {
    name: 'Example Advertiser',
    status: 'APPROVED'
  };

  try {
    const advertiserId = DoubleClickCampaigns.Advertisers
        .insert(advertiser, profileId).id;

    const landingPage = {
      advertiserId: advertiserId,
      archived: false,
      name: 'Example landing page',
      url: 'https://www.google.com'
    };
    const landingPageId = DoubleClickCampaigns.AdvertiserLandingPages
        .insert(landingPage, profileId).id;

    const campaignStart = new Date();
    // End campaign after 1 month.
    const campaignEnd = new Date();
    campaignEnd.setMonth(campaignEnd.getMonth() + 1);

    const campaign = {
      advertiserId: advertiserId,
      defaultLandingPageId: landingPageId,
      name: 'Example campaign',
      startDate: Utilities.formatDate(campaignStart, 'GMT', 'yyyy-MM-dd'),
      endDate: Utilities.formatDate(campaignEnd, 'GMT', 'yyyy-MM-dd')
    };
    DoubleClickCampaigns.Campaigns.insert(campaign, profileId);
  } catch (e) {
    // TODO (Developer) - Handle exception
    console.log('Failed with error: %s', e.error);
  }
}