خدمة حملات DoubleClick

تتيح لك خدمة "حملات DoubleClick" استخدام واجهة برمجة التطبيقات لإعداد التقارير وDCM/DFA في لغة "برمجة التطبيقات". وتوفر واجهة برمجة التطبيقات هذه إمكانية الوصول الآلي إلى تقارير DoubleClick Campaign Manager (DCM) وDDM لـ DoubleClick.

مَراجع

للحصول على معلومات تفصيلية عن هذه الخدمة، اطّلع على المستندات المرجعية بشأن واجهة برمجة التطبيقات DCM/DFA Reporting and Trafficking API. مثل جميع الخدمات المتقدمة في لغة برمجة التطبيقات، تستخدم خدمة حملات DoubleClick الكائنات والطرق والمعلمات نفسها مثل واجهة برمجة التطبيقات العامة. لمزيد من المعلومات، يُرجى الاطّلاع على كيفية تحديد توقيعات الطرق.

للإبلاغ عن المشاكل والعثور على وسائل دعم أخرى، اطّلع على دليل دعم إعداد التقارير والزيارات في DCM/DFA.

نموذج التعليمات البرمجية

يستخدم الرمز النموذجي أدناه الإصدار 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);
  }
}

الحصول على قائمة بالحملات النشطة

يسجّل هذا النموذج أسماء جميع الحملات النشطة وأرقام تعريفها. لاحظ استخدام الرموز المميزة للتقسيم لاسترداد القائمة بأكملها.

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