/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords 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) { using (OfflineConversionFeedService offlineConversionFeedService = (OfflineConversionFeedService)user.GetService( AdWordsService.v201705.OfflineConversionFeedService)) { try { // Associate offline conversions with the existing named conversion tracker. If // this tracker was newly created, it may be a few hours before it can accept // conversions. 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> /// <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) { using (OfflineConversionFeedService offlineConversionFeedService = (OfflineConversionFeedService)user.GetService(AdWordsService.v201809 .OfflineConversionFeedService)) { try { // Associate offline conversions with the existing named conversion tracker. If // this tracker was newly created, it may be a few hours before it can accept // conversions. OfflineConversionFeed feed = new OfflineConversionFeed { conversionName = conversionName, conversionTime = conversionTime, conversionValue = conversionValue, googleClickId = gClid }; // Optional: To upload fractional conversion credits, set the external // attribution model and credit. To use this feature, your conversion tracker // should be marked 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. // feed.externalAttributionModel = "Linear"; // feed.externalAttributionCredit = 0.3; OfflineConversionFeedOperation offlineConversionOperation = new OfflineConversionFeedOperation { @operator = Operator.ADD, 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 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); } }