DoubleClick 캠페인 서비스

DoubleClick 캠페인 서비스를 사용하면 Apps Script에서 DCM/DFA Reporting API 및 트래피킹 API를 사용할 수 있습니다. 이 API를 사용하면 DoubleClick Campaign Manager (DCM) 및 DoubleClick 디지털 마케팅 (DDM) 보고에 프로그래매틱 방식으로 액세스할 수 있습니다.

참조

이 서비스에 대한 자세한 내용은 DCM/DFA Reporting API 및 트래피킹 API의 참조 문서를 확인하세요. Apps Script의 모든 고급 서비스와 마찬가지로 DoubleClick 캠페인 서비스도 공개 API와 동일한 객체, 메서드, 매개변수를 사용합니다. 자세한 내용은 메서드 서명 확인 방법을 참조하세요.

문제를 신고하고 다른 지원을 받으려면 DCM/DFA 보고 및 트래피킹 지원 가이드를 참조하세요.

샘플 코드

아래 샘플 코드는 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);
  }
}

새 광고주 및 캠페인 만들기

이 샘플은 새 광고주를 만들고 해당 광고주로 새 캠페인을 만듭니다. 캠페인이 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);
  }
}