Layanan Kampanye DoubleClick

Layanan DoubleClick campaigns memungkinkan Anda menggunakan DCM/DFA Reporting and Trafficking API di Apps Script. API ini memberikan akses terprogram ke DoubleClick Campaign Manager (DCM) dan Pelaporan DoubleClick Digital Marketing (DDM).

Referensi

Untuk informasi selengkapnya tentang layanan ini, lihat dokumentasi referensi untuk Reporting and Trafficking API DCM/DFA. Seperti semua layanan lanjutan di Apps Script, layanan DoubleClick Campaigns menggunakan objek, metode, dan parameter yang sama seperti API publik. Untuk informasi selengkapnya, lihat Cara tanda tangan metode ditentukan.

Untuk melaporkan masalah dan menemukan dukungan lainnya, lihat panduan dukungan Pelaporan dan Proses Iklan DCM/DFA.

Kode contoh

Kode contoh di bawah ini menggunakan API versi 3.3.

Mendapatkan daftar profil pengguna

Contoh ini mencatat semua profil pengguna yang tersedia di akun ke dalam log.

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

Mendapatkan daftar kampanye yang aktif

Contoh ini mencatat nama dan ID semua kampanye aktif. Perhatikan penggunaan token paging untuk mengambil seluruh daftar.

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

Membuat pengiklan dan kampanye baru

Contoh ini akan membuat pengiklan baru dan membuat kampanye baru dengan pengiklan tersebut. Kampanye ditetapkan untuk berlangsung selama satu bulan.

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