-
Notifications
You must be signed in to change notification settings - Fork 199
/
AddUniversalAppCampaign.vb
executable file
·278 lines (237 loc) · 12.9 KB
/
AddUniversalAppCampaign.vb
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
' Copyright 2018 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
'
' http:'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.
Imports Google.Api.Ads.AdWords.Lib
Imports Google.Api.Ads.AdWords.v201809
Namespace Google.Api.Ads.AdWords.Examples.VB.v201809
''' <summary>
''' This code example adds a universal app campaign. To get campaigns, run
''' GetCampaigns.vb. To upload image assets for this campaign, use
''' UploadImage.vb.
''' </summary>
Public Class AddUniversalAppCampaign
Inherits ExampleBase
''' <summary>
''' Main method, to run this code example as a standalone application.
''' </summary>
''' <param name="args">The command line arguments.</param>
Public Shared Sub Main(ByVal args As String())
Dim codeExample As New AddUniversalAppCampaign
Console.WriteLine(codeExample.Description)
Try
codeExample.Run(New AdWordsUser())
Catch e As Exception
Console.WriteLine("An exception occurred while running this code example. {0}",
ExampleUtilities.FormatException(e))
End Try
End Sub
''' <summary>
''' Returns a description about the code example.
''' </summary>
Public Overrides ReadOnly Property Description() As String
Get
Return "This code example adds a universal app campaign. To get campaigns, run" &
" GetCampaigns.vb. To upload image assets for this campaign, use " &
"UploadImage.vb."
End Get
End Property
''' <summary>
''' Runs the code example.
''' </summary>
''' <param name="user">The AdWords user.</param>
Public Sub Run(ByVal user As AdWordsUser)
' [START prepareUAC] MOE:strip_line
Using campaignService As CampaignService = CType(
user.GetService(
AdWordsService.v201809.CampaignService),
CampaignService)
' Create the campaign.
Dim campaign As New Campaign
campaign.name = "Interplanetary Cruise App #" + ExampleUtilities.GetRandomString
' Recommendation: Set the campaign to PAUSED when creating it to prevent
' the ads from immediately serving. Set to ENABLED once you've added
' targeting and the ads are ready to serve.
campaign.status = CampaignStatus.PAUSED
' Set the advertising channel and subchannel types for universal app campaigns.
campaign.advertisingChannelType = AdvertisingChannelType.MULTI_CHANNEL
campaign.advertisingChannelSubType =
AdvertisingChannelSubType.UNIVERSAL_APP_CAMPAIGN
' Set the campaign's bidding strategy. Universal app campaigns
' only support TARGET_CPA bidding strategy.
Dim biddingConfig As New BiddingStrategyConfiguration()
biddingConfig.biddingStrategyType = BiddingStrategyType.TARGET_CPA
' Set the target CPA to $1 / app install.
Dim biddingScheme As New TargetCpaBiddingScheme()
biddingScheme.targetCpa = New Money()
biddingScheme.targetCpa.microAmount = 1000000
biddingConfig.biddingScheme = biddingScheme
campaign.biddingStrategyConfiguration = biddingConfig
' Set the campaign's budget.
campaign.budget = New Budget()
campaign.budget.budgetId = CreateBudget(user).budgetId
' Optional: Set the start date.
campaign.startDate = DateTime.Now.AddDays(1).ToString("yyyyMMdd")
' Optional: Set the end date.
campaign.endDate = DateTime.Now.AddYears(1).ToString("yyyyMMdd")
' [END prepareUAC] MOE:strip_line
' [START setUACAssets] MOE:strip_line
' Set the campaign's assets and ad text ideas. These values will be used to
' generate ads.
Dim universalAppSetting As New UniversalAppCampaignSetting()
universalAppSetting.appId = "com.labpixies.colordrips"
universalAppSetting.appVendor = MobileApplicationVendor.VENDOR_GOOGLE_MARKET
universalAppSetting.description1 = "A cool puzzle game"
universalAppSetting.description2 = "Remove connected blocks"
universalAppSetting.description3 = "3 difficulty levels"
universalAppSetting.description4 = "4 colorful fun skins"
' Optional: You can set up to 20 image assets for your campaign.
' See UploadImage.cs for an example on how to upload images.
'
' universalAppSetting.imageMediaIds = new long[] { INSERT_IMAGE_MEDIA_ID_HERE };
' [END setUACAssets] MOE:strip_line
' [START optimizeUAC] MOE:strip_line
' Optimize this campaign for getting new users for your app.
universalAppSetting.universalAppBiddingStrategyGoalType =
UniversalAppBiddingStrategyGoalType.OPTIMIZE_FOR_INSTALL_CONVERSION_VOLUME
' Optional: If you select the OPTIMIZE_FOR_IN_APP_CONVERSION_VOLUME goal
' type, then also specify your in-app conversion types so AdWords can
' focus your campaign on people who are most likely to complete the
' corresponding in-app actions.
' Conversion type IDs can be retrieved using ConversionTrackerService.get.
'
' campaign.selectiveOptimization = new SelectiveOptimization();
' campaign.selectiveOptimization.conversionTypeIds =
' new long[] {
' INSERT_CONVERSION_TYPE_ID_1_HERE,
' INSERT_CONVERSION_TYPE_ID_2_HERE };
' Optional: Set the campaign settings for Advanced location options.
Dim geoSetting As New GeoTargetTypeSetting()
geoSetting.positiveGeoTargetType =
GeoTargetTypeSettingPositiveGeoTargetType.LOCATION_OF_PRESENCE
geoSetting.negativeGeoTargetType =
GeoTargetTypeSettingNegativeGeoTargetType.DONT_CARE
campaign.settings = New Setting() {universalAppSetting, geoSetting}
' [END optimizeUAC] MOE:strip_line
' [START createUAC] MOE:strip_line
' Create the operation.
Dim operation As New CampaignOperation()
operation.operator = [Operator].ADD
operation.operand = campaign
Try
' Add the campaign.
Dim retVal As CampaignReturnValue = campaignService.mutate(
New CampaignOperation() {operation})
' Display the results.
If Not (retVal Is Nothing) AndAlso Not (retVal.value Is Nothing) Then
For Each newCampaign As Campaign In retVal.value
Console.WriteLine(
"Universal app campaign with name = '{0}' and id = '{1}' " +
"was added.", newCampaign.name, newCampaign.id)
' Optional: Set the campaign's location and language targeting. No other
' targeting criteria can be used for universal app campaigns.
SetCampaignTargetingCriteria(user, newCampaign)
Next
Else
Console.WriteLine("No universal app campaigns were added.")
End If
Catch e As Exception
Throw _
New System.ApplicationException("Failed to add universal app campaigns.", e)
End Try
End Using
' [END createUAC] MOE:strip_line
End Sub
''' <summary>
''' Creates the budget for the campaign.
''' </summary>
''' <param name="user">The AdWords user.</param>
''' <returns>The budget.</returns>
Private Shared Function CreateBudget(ByVal user As AdWordsUser) As Budget
' [START createBudget] MOE:strip_line
Using budgetService As BudgetService = CType(
user.GetService(
AdWordsService.v201809.BudgetService),
BudgetService)
' Create the campaign budget.
Dim budget As New Budget()
budget.name = "Interplanetary Cruise App Budget #" &
ExampleUtilities.GetRandomString()
budget.deliveryMethod = BudgetBudgetDeliveryMethod.STANDARD
budget.amount = New Money()
budget.amount.microAmount = 5000000
' Universal app campaigns don't support shared budgets.
budget.isExplicitlyShared = False
Dim budgetOperation As New BudgetOperation()
budgetOperation.operator = [Operator].ADD
budgetOperation.operand = budget
Dim budgetRetval As BudgetReturnValue = budgetService.mutate(
New BudgetOperation() {budgetOperation})
' [END createBudget] MOE:strip_line
Dim newBudget As Budget = budgetRetval.value(0)
Console.WriteLine("Budget with ID = '{0}' and name = '{1}' was created.",
newBudget.budgetId, newBudget.name)
Return newBudget
End Using
End Function
''' <summary>
''' Sets the campaign's targeting criteria.
''' </summary>
''' <param name="user">The AdWords user.</param>
''' <param name="campaign">The campaign for which targeting criteria is
''' created.</param>
Private Shared Sub SetCampaignTargetingCriteria(ByVal user As AdWordsUser,
ByVal campaign As Campaign)
' [START setCampaignTargetingCriteria] MOE:strip_line
Using campaignCriterionService As CampaignCriterionService = CType(
user.GetService(
AdWordsService.v201809.CampaignCriterionService),
CampaignCriterionService)
' Create locations. The IDs can be found in the documentation or
' retrieved with the LocationCriterionService.
Dim california As New Location()
california.id = 21137L
Dim mexico As New Location()
mexico.id = 2484L
' Create languages. The IDs can be found in the documentation or
' retrieved with the ConstantDataService.
Dim english As New Language()
english.id = 1000L
Dim spanish As New Language()
spanish.id = 1003L
Dim criteria As Criterion() = {california, mexico, english, spanish}
' Create operations to add each of the criteria above.
Dim operations As New List(Of CampaignCriterionOperation)()
For Each criterion As Criterion In criteria
Dim campaignCriterion As New CampaignCriterion
campaignCriterion.campaignId = campaign.id
campaignCriterion.criterion = criterion
Dim operation As New CampaignCriterionOperation()
operation.operand = campaignCriterion
operation.operator = [Operator].ADD
operations.Add(operation)
Next
' Set the campaign targets.
Dim retVal As CampaignCriterionReturnValue = campaignCriterionService.mutate(
operations.ToArray())
If Not (retVal Is Nothing) AndAlso Not (retVal.value Is Nothing) Then
' Display the added campaign targets.
For Each criterion As CampaignCriterion In retVal.value
Console.WriteLine("Campaign criteria of type '{0}' and id '{1}' was added.",
criterion.criterion.CriterionType, criterion.criterion.id)
Next
End If
End Using
' [END setCampaignTargetingCriteria] MOE:strip_line
End Sub
End Class
End Namespace