/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the ConversionTrackerService. ConversionTrackerService conversionTrackerService = (ConversionTrackerService)user.GetService(AdWordsService.v201502. ConversionTrackerService); // Create Adwords conversion tracker. AdWordsConversionTracker conversionTracker = new AdWordsConversionTracker(); conversionTracker.name = "Earth to Mars Cruises Conversion #" + ExampleUtilities.GetRandomString(); conversionTracker.category = ConversionTrackerCategory.DEFAULT; conversionTracker.markupLanguage = AdWordsConversionTrackerMarkupLanguage.HTML; conversionTracker.textFormat = AdWordsConversionTrackerTextFormat.HIDDEN; // Set optional fields. conversionTracker.status = ConversionTrackerStatus.ENABLED; conversionTracker.viewthroughLookbackWindow = 15; conversionTracker.isProductAdsChargeable = true; conversionTracker.productAdsChargeableConversionWindow = 15; conversionTracker.conversionPageLanguage = "en"; conversionTracker.backgroundColor = "#0000FF"; conversionTracker.defaultRevenueValue = 23.41; conversionTracker.alwaysUseDefaultRevenueValue = true; // Create the operation. ConversionTrackerOperation operation = new ConversionTrackerOperation(); operation.@operator = Operator.ADD; operation.operand = conversionTracker; try { // Add conversion tracker. ConversionTrackerReturnValue retval = conversionTrackerService.mutate( new ConversionTrackerOperation[] { operation }); // Display the results. if (retval != null && retval.value != null && retval.value.Length > 0) { ConversionTracker newConversionTracker = retval.value[0]; Console.WriteLine("Conversion tracker with id '{0}', name '{1}', status '{2}', " + "category '{3}' was added.", newConversionTracker.id, newConversionTracker.name, newConversionTracker.status, newConversionTracker.category); } else { Console.WriteLine("No conversion trackers were added."); } } catch (Exception ex) { throw new System.ApplicationException("Failed to add conversion tracker.", ex); } }
/// <summary> /// Runs the specified user. /// </summary> /// <param name="user">The user.</param> /// <param name="conversionName">The name of the upload conversion to be /// created.</param> /// <param name="gClid">The Google Click ID of the click for which offline /// conversions are uploaded.</param> /// <param name="conversionValue">The conversion value to be uploaded. /// </param> /// <param name="conversionTime">The conversion time, in yyyymmdd hhmmss /// format.</param> public void Run(AdWordsUser user, String conversionName, String gClid, String conversionTime, double conversionValue) { // Get the ConversionTrackerService. ConversionTrackerService conversionTrackerService = (ConversionTrackerService)user.GetService( AdWordsService.v201509.ConversionTrackerService); // Get the OfflineConversionFeedService. OfflineConversionFeedService offlineConversionFeedService = (OfflineConversionFeedService)user.GetService( AdWordsService.v201509.OfflineConversionFeedService); const int VIEWTHROUGH_LOOKBACK_WINDOW = 30; const int CTC_LOOKBACK_WINDOW = 90; try { // Create an upload conversion. Once created, this entry will be visible // under Tools and Analysis->Conversion and will have "Source = Import". UploadConversion uploadConversion = new UploadConversion(); uploadConversion.category = ConversionTrackerCategory.PAGE_VIEW; uploadConversion.name = conversionName; uploadConversion.viewthroughLookbackWindow = VIEWTHROUGH_LOOKBACK_WINDOW; uploadConversion.ctcLookbackWindow = CTC_LOOKBACK_WINDOW; ConversionTrackerOperation uploadConversionOperation = new ConversionTrackerOperation(); uploadConversionOperation.@operator = Operator.ADD; uploadConversionOperation.operand = uploadConversion; ConversionTrackerReturnValue conversionTrackerRetval = conversionTrackerService.mutate( new ConversionTrackerOperation[] { uploadConversionOperation }); UploadConversion newUploadConversion = (UploadConversion)conversionTrackerRetval.value[0]; Console.WriteLine("New upload conversion type with name = '{0}' and id = {1} was created.", newUploadConversion.name, newUploadConversion.id); // Associate offline conversions with the upload conversion we created. OfflineConversionFeed feed = new OfflineConversionFeed(); feed.conversionName = conversionName; feed.conversionTime = conversionTime; feed.conversionValue = conversionValue; feed.googleClickId = gClid; OfflineConversionFeedOperation offlineConversionOperation = new OfflineConversionFeedOperation(); offlineConversionOperation.@operator = Operator.ADD; offlineConversionOperation.operand = feed; OfflineConversionFeedReturnValue offlineConversionRetval = offlineConversionFeedService.mutate( new OfflineConversionFeedOperation[] { offlineConversionOperation }); OfflineConversionFeed newFeed = offlineConversionRetval.value[0]; Console.WriteLine("Uploaded offline conversion value of {0} for Google Click ID = " + "'{1}' to '{2}'.", newFeed.conversionValue, newFeed.googleClickId, newFeed.conversionName); } catch (Exception e) { throw new System.ApplicationException("Failed upload offline conversions.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { using (ConversionTrackerService conversionTrackerService = (ConversionTrackerService)user.GetService(AdWordsService.v201802. ConversionTrackerService)) { List <ConversionTracker> conversionTrackers = new List <ConversionTracker>(); // Create an Adwords conversion tracker. AdWordsConversionTracker adWordsConversionTracker = 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. UploadConversion uploadConversion = 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.50; // 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. List <ConversionTrackerOperation> operations = new List <ConversionTrackerOperation>(); foreach (ConversionTracker conversionTracker in conversionTrackers) { operations.Add(new ConversionTrackerOperation() { @operator = Operator.ADD, operand = conversionTracker }); } // Add conversion tracker. ConversionTrackerReturnValue retval = conversionTrackerService.mutate( operations.ToArray()); // Display the results. if (retval != null && retval.value != null) { foreach (ConversionTracker 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 (conversionTracker is AdWordsConversionTracker) { AdWordsConversionTracker newAdWordsConversionTracker = (AdWordsConversionTracker)conversionTracker; Console.WriteLine("Google global site tag:\n{0}\nGoogle event snippet:\n{1}", newAdWordsConversionTracker.googleGlobalSiteTag, newAdWordsConversionTracker.googleEventSnippet ); } } } else { Console.WriteLine("No conversion trackers were added."); } } catch (Exception e) { throw new System.ApplicationException("Failed to add conversion trackers.", e); } } }
public static void CreateConversionTracker() { var user = new AdWordsUser(); using (ConversionTrackerService conversionTrackerService = (ConversionTrackerService)user.GetService(AdWordsService.v201710.ConversionTrackerService)) { List <ConversionTracker> conversionTrackers = new List <ConversionTracker>(); AdWordsConversionTracker adWordsConversionTracker = new AdWordsConversionTracker(); adWordsConversionTracker.name = "Earth to Mars Cruises Conversion"; adWordsConversionTracker.category = ConversionTrackerCategory.DEFAULT; // Set optional fields. adWordsConversionTracker.status = ConversionTrackerStatus.ENABLED; adWordsConversionTracker.viewthroughLookbackWindow = 15; adWordsConversionTracker.defaultRevenueValue = 23.41; adWordsConversionTracker.alwaysUseDefaultRevenueValue = true; conversionTrackers.Add(adWordsConversionTracker); try { // Create operations. List <ConversionTrackerOperation> operations = new List <ConversionTrackerOperation>(); foreach (ConversionTracker conversionTracker in conversionTrackers) { operations.Add(new ConversionTrackerOperation() { @operator = Operator.ADD, operand = conversionTracker }); } // Add conversion tracker. ConversionTrackerReturnValue retval = conversionTrackerService.mutate( operations.ToArray()); if (retval != null && retval.value != null) { foreach (ConversionTracker conversionTracker in retval.value) { if (conversionTracker is AdWordsConversionTracker) { AdWordsConversionTracker newAdWordsConversionTracker = (AdWordsConversionTracker)conversionTracker; Console.WriteLine("Conversion with ID {0}, name '{1}', status '{2}', category " + "'{3}' and snippet '{4}' was added.", newAdWordsConversionTracker.id, newAdWordsConversionTracker.name, newAdWordsConversionTracker.status, newAdWordsConversionTracker.category, newAdWordsConversionTracker.snippet); } else { Console.WriteLine("Conversion with ID {0}, name '{1}', status '{2}' and " + "category '{3}' was added.", conversionTracker.id, conversionTracker.name, conversionTracker.status, conversionTracker.category); } } } else { Console.WriteLine("No conversion trackers were added."); } } catch (Exception e) { throw new System.ApplicationException("Failed to add conversion trackers.", e); } } }