DoubleClick キャンペーン サービス

DoubleClick Campaigns サービスを使用すると、Apps Script で DCM/DFA Reporting and Trafficking API を使用できます。この API を使用すると、DoubleClick Campaign Manager(DCM)と DoubleClick Digital Marketing(DDM)のレポートにプログラムからアクセスできます。

リファレンス

このサービスの詳細については、DCM/DFA Reporting and Trafficking API のリファレンス ドキュメントをご覧ください。Apps Script のすべての高度なサービスと同様に、DoubleClick Campaigns サービスでは、公開 API と同じオブジェクト、メソッド、パラメータを使用します。詳細については、メソッド シグネチャの決定方法をご覧ください。

問題を報告したり、その他のサポートを見つけたりするには、DCM/DFA Reporting and Trafficking のサポートガイドをご覧ください。

サンプルコード

次のサンプルコードでは、API のバージョン 4 を使用しています。

ユーザー プロフィールのリストを取得する

このサンプルでは、アカウントで利用可能なすべてのユーザー プロファイルがログに記録されます。

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

新しい広告主とキャンペーンを作成する

このサンプルでは、新しい広告主を作成し、その広告主で新しいキャンペーンを作成します。キャンペーンは 1 か月間実施される予定です。

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