DoubleClick Campaigns Service

The DoubleClick Campaigns service allows you to use the DCM/DFA Reporting and Trafficking API in Apps Script. This API provides programmatic access to DoubleClick Campaign Manager (DCM) and DoubleClick Digital Marketing (DDM) Reporting.

Reference

For detailed information on this service, see the reference documentation for the DCM/DFA Reporting and Trafficking API. Like all advanced services in Apps Script, the DoubleClick Campaigns service uses the same objects, methods, and parameters as the public API.

Sample code

The sample code below uses version 2.7 of the API.

Open code in new window

Get a list of user profiles

This sample logs all of the user profiles available in the account.

function listUserProfiles() {
  // Retrieve the list of available user profiles
  var profiles = DoubleClickCampaigns.UserProfiles.list();

  if (profiles.items) {
    // Print out the user ID and name of each
    for (var i = 0; i < profiles.items.length; i++) {
    var profile = profiles.items[i];
    Logger.log('Found profile with ID %s and name "%s".',
        profile.profileId, profile.userName);
    }
  }
}

Get a list of active campaigns

This sample logs names and ID's of all active campaigns. Note the use of paging tokens to retrieve the whole list.

function listActiveCampaigns() {
  var profileId = '1234567'; // Replace with your profile ID.
  var fields = 'nextPageToken,campaigns(id,name)';

  var result, pageToken;
  do {
    result = DoubleClickCampaigns.Campaigns.list(profileId, {
      'archived': false,
      'fields': fields,
      'pageToken': pageToken
    });
    if (result.campaigns) {
      for (var i = 0; i < result.campaigns.length; i++) {
        var campaign = result.campaigns[i];
        Logger.log('Found campaign with ID %s and name "%s".',
            campaign.id, campaign.name);
      }
    }
    pageToken = result.nextPageToken;
  } while (pageToken);
}

Create a new advertiser and campaign

This sample creates a new advertiser, and creates a new campaign with that advertiser. The campaign is set to last for one month.

function createAdvertiserAndCampaign() {
  var profileId = '1234567'; // Replace with your profile ID.
  var advertiser = {
    name: 'Example Advertiser',
    status: 'APPROVED'
  };
  var advertiserId = DoubleClickCampaigns.Advertisers
      .insert(advertiser, profileId).id;

  var campaignStart = new Date();
  // End campaign after 1 month.
  var campaignEnd = new Date();
  campaignEnd.setMonth(campaignEnd.getMonth() + 1);

  var campaign = {
    name: 'Example campaign',
    advertiserId: advertiserId,
    startDate: Utilities.formatDate(campaignStart, 'GMT', 'yyyy-MM-dd'),
    endDate: Utilities.formatDate(campaignEnd, 'GMT', 'yyyy-MM-dd')
  };
  DoubleClickCampaigns.Campaigns.insert(campaign, profileId,
      'Example Landing Page Name', 'http://www.example.com');
}

发送以下问题的反馈:

此网页
Apps Script
Apps Script