-
Notifications
You must be signed in to change notification settings - Fork 199
/
AddConversionTrackers.vb
executable file
·153 lines (134 loc) · 7.29 KB
/
AddConversionTrackers.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
' 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 an AdWords conversion tracker and an upload conversion tracker.
''' </summary>
Public Class AddConversionTrackers
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 AddConversionTrackers
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 an AdWords conversion tracker and an upload " &
"conversion tracker."
End Get
End Property
''' <summary>
''' Runs the code example.
''' </summary>
''' <param name="user">The AdWords user.</param>
Public Sub Run(ByVal user As AdWordsUser)
' Get the ConversionTrackerService.
Using conversionTrackerService As ConversionTrackerService = CType(
user.GetService(
AdWordsService.v201809.ConversionTrackerService),
ConversionTrackerService)
Dim conversionTrackers As New List(Of ConversionTracker)
' Create an Adwords conversion tracker.
Dim adWordsConversionTracker As New AdWordsConversionTracker()
adWordsConversionTracker.name = "Earth to Mars Cruises Conversion #" &
ExampleUtilities.GetRandomString()
adWordsConversionTracker.category = ConversionTrackerCategory.DEFAULT
' Set optional fields.
adWordsConversionTracker.status = ConversionTrackerStatus.ENABLED
adWordsConversionTracker.viewthroughLookbackWindow = 15
adWordsConversionTracker.defaultRevenueValue = 23.41
adWordsConversionTracker.alwaysUseDefaultRevenueValue = True
conversionTrackers.Add(adWordsConversionTracker)
' Create an upload conversion for offline conversion imports.
Dim uploadConversion As New UploadConversion()
' Set an appropriate category. This field is optional, and will be set to
' DEFAULT if not mentioned.
uploadConversion.category = ConversionTrackerCategory.LEAD
uploadConversion.name = "Upload Conversion #" + ExampleUtilities.GetRandomString()
uploadConversion.viewthroughLookbackWindow = 30
uploadConversion.ctcLookbackWindow = 90
' Optional: Set the default currency code to use for conversions
' that do not specify a conversion currency. This must be an ISO 4217
' 3-character currency code such as "EUR" or "USD".
' If this field is not set on this UploadConversion, AdWords will use
' the account's currency.
uploadConversion.defaultRevenueCurrencyCode = "EUR"
' Optional: Set the default revenue value to use for conversions
' that do not specify a conversion value. Note that this value
' should NOT be in micros.
uploadConversion.defaultRevenueValue = 2.5
' Optional: To upload fractional conversion credits, mark the upload conversion
' as externally attributed. See
' https://developers.google.com/adwords/api/docs/guides/conversion-tracking#importing_externally_attributed_conversions
' to learn more about importing externally attributed conversions.
' uploadConversion.isExternallyAttributed = True
conversionTrackers.Add(uploadConversion)
Try
' Create operations.
Dim operations As New List(Of ConversionTrackerOperation)
For Each conversionTracker As ConversionTracker In conversionTrackers
Dim operation As New ConversionTrackerOperation()
operation.operator = [Operator].ADD
operation.operand = conversionTracker
operations.Add(operation)
Next
' Add conversion tracker.
Dim retval As ConversionTrackerReturnValue = conversionTrackerService.mutate(
operations.ToArray())
' Display the results.
If (Not retval Is Nothing) AndAlso (Not retval.value Is Nothing) AndAlso
retval.value.Length > 0 Then
For Each conversionTracker As ConversionTracker In retval.value
Console.WriteLine(
"Conversion with ID {0}, name '{1}', status '{2}' and " &
"category '{3}' was added.", conversionTracker.id,
conversionTracker.name,
conversionTracker.status, conversionTracker.category)
If TypeOf conversionTracker Is AdWordsConversionTracker Then
Dim newAdWordsConversionTracker As AdWordsConversionTracker =
CType(conversionTracker, AdWordsConversionTracker)
Console.WriteLine(
"Google global site tag:\n{0}\nGoogle event snippet:\n{1}",
newAdWordsConversionTracker.googleGlobalSiteTag,
newAdWordsConversionTracker.googleEventSnippet
)
Else
End If
Next
Else
Console.WriteLine("No conversion trackers were added.")
End If
Catch e As Exception
Throw New System.ApplicationException("Failed to add conversion trackers.", e)
End Try
End Using
End Sub
End Class
End Namespace