コード例 #1
0
    /// <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.v201409.
              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);
      }
    }
コード例 #2
0
    /// <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.v201409.ConversionTrackerService);

       // Get the OfflineConversionFeedService.
      OfflineConversionFeedService offlineConversionFeedService =
          (OfflineConversionFeedService) user.GetService(
              AdWordsService.v201409.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 ex) {
        throw new System.ApplicationException("Failed upload offline conversions.", ex);
      }
    }