บริการแคมเปญ DoubleClick

บริการแคมเปญ DoubleClick ช่วยให้คุณใช้ DCM/DFA Reporting and Trafficking API ใน Apps Script ได้ API นี้ช่วยให้เข้าถึงการรายงานของ DoubleClick Campaign Manager (DCM) และ DoubleClick Digital Marketing (DDM) แบบเป็นโปรแกรมได้

ข้อมูลอ้างอิง

ดูข้อมูลโดยละเอียดเกี่ยวกับบริการนี้ได้ที่เอกสารอ้างอิงสำหรับ DCM/DFA Reporting and Trafficking API เช่นเดียวกับบริการขั้นสูงทั้งหมดใน Apps Script บริการแคมเปญ DoubleClick จะใช้ออบเจ็กต์ เมธอด และ พารามิเตอร์เดียวกันกับ API สาธารณะ ดูข้อมูลเพิ่มเติมได้ที่วิธีกำหนดลายเซ็นของเมธอด

หากต้องการรายงานปัญหาและรับการสนับสนุนอื่นๆ โปรดดูคู่มือการสนับสนุนด้านการรายงานและการดูแลการแสดงโฆษณาของ DCM/DFA

โค้ดตัวอย่าง

โค้ดตัวอย่างด้านล่างใช้ 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);
  }
}

รับรายการแคมเปญที่ใช้งานอยู่

ตัวอย่างนี้จะบันทึกชื่อและรหัสของแคมเปญที่ใช้งานอยู่ทั้งหมด โปรดทราบว่ามีการใช้โทเค็นการแบ่งหน้า เพื่อดึงข้อมูลรายการทั้งหมด

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