DoubleClick 广告系列服务

借助 DoubleClick 广告系列服务,您可以在 Apps Script 中使用 DCM/DFA Reporting and Trafficking API。此 API 可让您以编程方式访问 DoubleClick Campaign Manager (DCM) 和 DoubleClick Digital Marketing (DDM) 报告。

参考

如需详细了解此服务,请参阅 DCM/DFA Reporting and Trafficking API 的参考文档。与 Apps 脚本中的所有高级服务一样,DoubleClick 广告系列服务使用的对象、方法和参数均与公共 API 相同。如需了解详情,请参阅如何确定方法签名

如需报告问题和查找其他支持,请参阅 DCM/DFA Reporting and Trafficking 支持指南

示例代码

以下示例代码使用了该 API 的 3.3 版

获取用户个人资料列表

此示例会记录账号中可用的所有用户个人资料。

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);
  }
}

获取有效广告系列的列表

此示例会记录所有有效广告系列的名称和 ID。请注意,使用分页令牌检索整个列表。

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);
  }
}

创建新的广告客户和广告系列

此示例会创建新的广告客户,并使用该广告客户创建新的广告系列。该广告系列的设置为投放一个月。

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);
  }
}