forked from googleworkspace/apps-script-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doubleclick.gs
101 lines (94 loc) · 3.27 KB
/
doubleclick.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* Copyright Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// [START apps_script_doubleclick_list_user_profiles]
/**
* 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);
}
}
}
// [END apps_script_doubleclick_list_user_profiles]
// [START apps_script_doubleclick_list_active_campaigns]
/**
* 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;
var 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);
}
// [END apps_script_doubleclick_list_active_campaigns]
// [START apps_script_doubleclick_create_advertiser_and_campaign]
/**
* 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 landingPage = {
advertiserId: advertiserId,
archived: false,
name: 'Example landing page',
url: 'https://www.google.com'
};
var landingPageId = DoubleClickCampaigns.AdvertiserLandingPages
.insert(landingPage, profileId).id;
var campaignStart = new Date();
// End campaign after 1 month.
var campaignEnd = new Date();
campaignEnd.setMonth(campaignEnd.getMonth() + 1);
var 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);
}
// [END apps_script_doubleclick_create_advertiser_and_campaign]