您可以在 Apps Script 中使用 DoubleClick Campaigns 服務的 DCM/DFA Reporting and Trafficking API。這個 API 可讓您透過程式輔助的方式,存取 DoubleClick Campaign Manager (DCM) 和 DoubleClick Digital Marketing (DDM) 報表。
參考資料
如要進一步瞭解這項服務,請參閱 DCM/DFA Reporting and Trafficking API 的參考說明文件。與 Apps Script 中的所有進階服務一樣,DoubleClick Campaigns 服務使用的物件、方法和參數,都與公開 API 相同。詳情請參閱「如何判斷方法簽章」。
/** * Logs all of the user profiles available in the account. */functionlistUserProfiles(){// Retrieve the list of available user profilestry{constprofiles=DoubleClickCampaigns.UserProfiles.list();if(profiles.items){// Print out the user ID and name of eachfor(leti=0;i < profiles.items.length;i++){constprofile=profiles.items[i];console.log('Found profile with ID %s and name "%s".',profile.profileId,profile.userName);}}}catch(e){// TODO (Developer) - Handle exceptionconsole.log('Failed with error: %s',e.error);}}
/** * Logs names and ID's of all active campaigns. * Note the use of paging tokens to retrieve the whole list. */functionlistActiveCampaigns(){constprofileId='1234567';// Replace with your profile ID.constfields='nextPageToken,campaigns(id,name)';letresult;letpageToken;try{do{result=DoubleClickCampaigns.Campaigns.list(profileId,{'archived':false,'fields':fields,'pageToken':pageToken});if(result.campaigns){for(leti=0;i < result.campaigns.length;i++){constcampaign=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 exceptionconsole.log('Failed with error: %s',e.error);}}
/** * Creates a new advertiser, and creates a new campaign with that advertiser. * The campaign is set to last for one month. */functioncreateAdvertiserAndCampaign(){constprofileId='1234567';// Replace with your profile ID.constadvertiser={name:'Example Advertiser',status:'APPROVED'};try{constadvertiserId=DoubleClickCampaigns.Advertisers.insert(advertiser,profileId).id;constlandingPage={advertiserId:advertiserId,archived:false,name:'Example landing page',url:'https://www.google.com'};constlandingPageId=DoubleClickCampaigns.AdvertiserLandingPages.insert(landingPage,profileId).id;constcampaignStart=newDate();// End campaign after 1 month.constcampaignEnd=newDate();campaignEnd.setMonth(campaignEnd.getMonth()+1);constcampaign={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 exceptionconsole.log('Failed with error: %s',e.error);}}