Search in sources :

Example 21 with Feed

use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.

the class AddAdCustomizer method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupIds IDs of the ad groups for which ad customizers will be created.
 * @param feedName the name of the ad customizer feed to create.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, List<Long> adGroupIds, String feedName) throws RemoteException {
    // Create a customizer feed. One feed per account can be used for all ads.
    AdCustomizerFeed adCustomizerFeed = createCustomizerFeed(adWordsServices, session, feedName);
    // Add feed items containing the values we'd like to place in ads.
    createCustomizerFeedItems(adWordsServices, session, adGroupIds, adCustomizerFeed);
    // All set! We can now create ads with customizations.
    createAdsWithCustomizations(adWordsServices, session, adGroupIds, feedName);
}
Also used : AdCustomizerFeed(com.google.api.ads.adwords.axis.v201809.cm.AdCustomizerFeed)

Example 22 with Feed

use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.

the class AddCampaignTargetingCriteria method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the campaign where targeting criteria will be added.
 * @param locationFeedId optional ID of a location targeting feed.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long campaignId, @Nullable Long locationFeedId) throws RemoteException {
    // Get the CampaignService.
    CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
    // Create locations. The IDs can be found in the documentation or
    // retrieved with the LocationCriterionService.
    Location california = new Location();
    california.setId(21137L);
    Location mexico = new Location();
    mexico.setId(2484L);
    // Create languages. The IDs can be found in the documentation or
    // retrieved with the ConstantDataService.
    Language english = new Language();
    english.setId(1000L);
    Language spanish = new Language();
    spanish.setId(1003L);
    List<Criterion> criteria = new ArrayList<>(Arrays.asList(california, mexico, english, spanish));
    // Distance targeting. Area of 10 miles around the locations in the location feed.
    if (locationFeedId != null) {
        LocationGroups radiusLocationGroup = new LocationGroups();
        radiusLocationGroup.setFeedId(locationFeedId);
        ConstantOperand radius = new ConstantOperand();
        radius.setType(ConstantOperandConstantType.DOUBLE);
        radius.setUnit(ConstantOperandUnit.MILES);
        radius.setDoubleValue(10d);
        LocationExtensionOperand distance = new LocationExtensionOperand();
        distance.setRadius(radius);
        Function radiusMatchingFunction = new Function();
        radiusMatchingFunction.setOperator(FunctionOperator.IDENTITY);
        radiusMatchingFunction.setLhsOperand(new FunctionArgumentOperand[] { distance });
        radiusLocationGroup.setMatchingFunction(radiusMatchingFunction);
        criteria.add(radiusLocationGroup);
    }
    // Create operations to add each of the criteria above.
    List<CampaignCriterionOperation> operations = new ArrayList<>();
    for (Criterion criterion : criteria) {
        CampaignCriterionOperation operation = new CampaignCriterionOperation();
        CampaignCriterion campaignCriterion = new CampaignCriterion();
        campaignCriterion.setCampaignId(campaignId);
        campaignCriterion.setCriterion(criterion);
        operation.setOperand(campaignCriterion);
        operation.setOperator(Operator.ADD);
        operations.add(operation);
    }
    // Add a negative campaign criterion.
    Keyword negativeKeyword = new Keyword();
    negativeKeyword.setText("jupiter cruise");
    negativeKeyword.setMatchType(KeywordMatchType.BROAD);
    CampaignCriterion negativeCriterion = new NegativeCampaignCriterion();
    negativeCriterion.setCampaignId(campaignId);
    negativeCriterion.setCriterion(negativeKeyword);
    CampaignCriterionOperation operation = new CampaignCriterionOperation();
    operation.setOperand(negativeCriterion);
    operation.setOperator(Operator.ADD);
    operations.add(operation);
    CampaignCriterionReturnValue result = campaignCriterionService.mutate(operations.toArray(new CampaignCriterionOperation[operations.size()]));
    // Display campaigns.
    for (CampaignCriterion campaignCriterion : result.getValue()) {
        System.out.printf("Campaign criterion with campaign ID %d, criterion ID %d, " + "and type '%s' was added.%n", campaignCriterion.getCampaignId(), campaignCriterion.getCriterion().getId(), campaignCriterion.getCriterion().getCriterionType());
    }
}
Also used : ConstantOperand(com.google.api.ads.adwords.axis.v201809.cm.ConstantOperand) CampaignCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation) LocationGroups(com.google.api.ads.adwords.axis.v201809.cm.LocationGroups) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) NegativeCampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeCampaignCriterion) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) ArrayList(java.util.ArrayList) NegativeCampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeCampaignCriterion) CampaignCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue) Function(com.google.api.ads.adwords.axis.v201809.cm.Function) Language(com.google.api.ads.adwords.axis.v201809.cm.Language) NegativeCampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeCampaignCriterion) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) Criterion(com.google.api.ads.adwords.axis.v201809.cm.Criterion) CampaignCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface) LocationExtensionOperand(com.google.api.ads.adwords.axis.v201809.cm.LocationExtensionOperand) Location(com.google.api.ads.adwords.axis.v201809.cm.Location)

Example 23 with Feed

use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.

the class UploadConversionAdjustment method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param conversionName the name of the conversion tracker.
 * @param gclId the GCLID for the conversion.
 * @param adjustmentType the type of adjustment.
 * @param adjustmentTime the date and time of the adjustment.
 * @param conversionTime the date and time of the conversion.
 * @param adjustedValue the adjusted value.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, String conversionName, String gclId, OfflineConversionAdjustmentType adjustmentType, String conversionTime, String adjustmentTime, @Nullable Double adjustedValue) throws RemoteException {
    // Get the OfflineConversionAdjustmentFeedService.
    OfflineConversionAdjustmentFeedServiceInterface offlineConversionFeedService = adWordsServices.get(session, OfflineConversionAdjustmentFeedServiceInterface.class);
    // Associate conversion adjustments with the existing named conversion tracker. The GCLID should
    // have been uploaded before with a conversion.
    GclidOfflineConversionAdjustmentFeed feed = new GclidOfflineConversionAdjustmentFeed();
    feed.setConversionName(conversionName);
    feed.setAdjustmentType(adjustmentType);
    feed.setConversionTime(conversionTime);
    feed.setAdjustmentTime(adjustmentTime);
    feed.setAdjustedValue(adjustedValue);
    feed.setGoogleClickId(gclId);
    OfflineConversionAdjustmentFeedOperation offlineConversionOperation = new OfflineConversionAdjustmentFeedOperation();
    offlineConversionOperation.setOperator(Operator.ADD);
    offlineConversionOperation.setOperand(feed);
    OfflineConversionAdjustmentFeedReturnValue offlineConversionReturnValue = offlineConversionFeedService.mutate(new OfflineConversionAdjustmentFeedOperation[] { offlineConversionOperation });
    for (OfflineConversionAdjustmentFeed newFeed : offlineConversionReturnValue.getValue()) {
        System.out.printf("Uploaded conversion adjusted value of %.4f for Google Click ID '%s'.%n", newFeed.getAdjustedValue(), ((GclidOfflineConversionAdjustmentFeed) newFeed).getGoogleClickId());
    }
}
Also used : OfflineConversionAdjustmentFeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentFeedServiceInterface) OfflineConversionAdjustmentFeedOperation(com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentFeedOperation) OfflineConversionAdjustmentFeedReturnValue(com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentFeedReturnValue) GclidOfflineConversionAdjustmentFeed(com.google.api.ads.adwords.axis.v201809.cm.GclidOfflineConversionAdjustmentFeed) OfflineConversionAdjustmentFeed(com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentFeed) GclidOfflineConversionAdjustmentFeed(com.google.api.ads.adwords.axis.v201809.cm.GclidOfflineConversionAdjustmentFeed)

Example 24 with Feed

use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.

the class UploadOfflineCallConversions method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param callerId the caller ID of the call.
 * @param callStartTime the call start time of the call.
 * @param conversionName the name of the conversion tracker.
 * @param conversionTime the date and time of the conversion.
 * @param conversionValue the value of the conversion.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, String callerId, String callStartTime, String conversionName, String conversionTime, double conversionValue) throws RemoteException {
    // Get the OfflineCallConversionFeedService.
    OfflineCallConversionFeedServiceInterface offlineCallConversionFeedService = adWordsServices.get(session, OfflineCallConversionFeedServiceInterface.class);
    // Associate offline call conversions with the existing named conversion tracker. If this
    // tracker was newly created, it may be a few hours before it can accept conversions.
    OfflineCallConversionFeed feed = new OfflineCallConversionFeed();
    feed.setCallerId(callerId);
    feed.setCallStartTime(callStartTime);
    feed.setConversionName(conversionName);
    feed.setConversionTime(conversionTime);
    feed.setConversionValue(conversionValue);
    OfflineCallConversionFeedOperation offlineCallConversionOperation = new OfflineCallConversionFeedOperation();
    offlineCallConversionOperation.setOperator(Operator.ADD);
    offlineCallConversionOperation.setOperand(feed);
    // This example uploads only one call conversion, but you can upload multiple call conversions
    // by passing additional operations.
    OfflineCallConversionFeedReturnValue offlineCallConversionReturnValue = offlineCallConversionFeedService.mutate(new OfflineCallConversionFeedOperation[] { offlineCallConversionOperation });
    // Display results.
    for (OfflineCallConversionFeed feedResult : offlineCallConversionReturnValue.getValue()) {
        System.out.printf("Uploaded offline conversion value of %.4f for caller ID '%s'.%n", feedResult.getConversionValue(), feedResult.getCallerId());
    }
}
Also used : OfflineCallConversionFeedReturnValue(com.google.api.ads.adwords.axis.v201809.cm.OfflineCallConversionFeedReturnValue) OfflineCallConversionFeed(com.google.api.ads.adwords.axis.v201809.cm.OfflineCallConversionFeed) OfflineCallConversionFeedOperation(com.google.api.ads.adwords.axis.v201809.cm.OfflineCallConversionFeedOperation) OfflineCallConversionFeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.OfflineCallConversionFeedServiceInterface)

Example 25 with Feed

use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.

the class AddAdCustomizer method createCustomizerFeed.

/**
 * Creates a new AdCustomizerFeed.
 *
 * @param feedName the name of the new AdCustomizerFeed
 * @return The new AdCustomizerFeed
 */
private static AdCustomizerFeed createCustomizerFeed(AdWordsServicesInterface adWordsServices, AdWordsSession session, String feedName) throws RemoteException {
    // Get the AdCustomizerFeedService.
    AdCustomizerFeedServiceInterface adCustomizerFeedService = adWordsServices.get(session, AdCustomizerFeedServiceInterface.class);
    AdCustomizerFeed customizerFeed = new AdCustomizerFeed();
    customizerFeed.setFeedName(feedName);
    AdCustomizerFeedAttribute nameAttribute = new AdCustomizerFeedAttribute();
    nameAttribute.setName("Name");
    nameAttribute.setType(AdCustomizerFeedAttributeType.STRING);
    AdCustomizerFeedAttribute priceAttribute = new AdCustomizerFeedAttribute();
    priceAttribute.setName("Price");
    priceAttribute.setType(AdCustomizerFeedAttributeType.STRING);
    AdCustomizerFeedAttribute dateAttribute = new AdCustomizerFeedAttribute();
    dateAttribute.setName("Date");
    dateAttribute.setType(AdCustomizerFeedAttributeType.DATE_TIME);
    customizerFeed.setFeedAttributes(new AdCustomizerFeedAttribute[] { nameAttribute, priceAttribute, dateAttribute });
    AdCustomizerFeedOperation feedOperation = new AdCustomizerFeedOperation();
    feedOperation.setOperand(customizerFeed);
    feedOperation.setOperator(Operator.ADD);
    AdCustomizerFeed addedFeed = adCustomizerFeedService.mutate(new AdCustomizerFeedOperation[] { feedOperation }).getValue()[0];
    System.out.printf("Created ad customizer feed with ID %d, name '%s' and attributes:%n", addedFeed.getFeedId(), addedFeed.getFeedName());
    for (AdCustomizerFeedAttribute feedAttribute : addedFeed.getFeedAttributes()) {
        System.out.printf("  ID: %d, name: '%s', type: %s%n", feedAttribute.getId(), feedAttribute.getName(), feedAttribute.getType());
    }
    return addedFeed;
}
Also used : AdCustomizerFeedAttribute(com.google.api.ads.adwords.axis.v201809.cm.AdCustomizerFeedAttribute) AdCustomizerFeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdCustomizerFeedServiceInterface) AdCustomizerFeed(com.google.api.ads.adwords.axis.v201809.cm.AdCustomizerFeed) AdCustomizerFeedOperation(com.google.api.ads.adwords.axis.v201809.cm.AdCustomizerFeedOperation)

Aggregations

ArrayList (java.util.ArrayList)11 FeedItem (com.google.api.ads.adwords.axis.v201809.cm.FeedItem)9 FeedItemOperation (com.google.api.ads.adwords.axis.v201809.cm.FeedItemOperation)7 CampaignFeed (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeed)6 CampaignFeedServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedServiceInterface)6 Feed (com.google.api.ads.adwords.axis.v201809.cm.Feed)6 ExtensionFeedItem (com.google.api.ads.adwords.axis.v201809.cm.ExtensionFeedItem)5 FeedItemAttributeValue (com.google.api.ads.adwords.axis.v201809.cm.FeedItemAttributeValue)5 FeedItemServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.FeedItemServiceInterface)5 SitelinkFeedItem (com.google.api.ads.adwords.axis.v201809.cm.SitelinkFeedItem)5 AttributeFieldMapping (com.google.api.ads.adwords.axis.v201809.cm.AttributeFieldMapping)4 CampaignFeedOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedOperation)4 FeedMapping (com.google.api.ads.adwords.axis.v201809.cm.FeedMapping)4 FeedMappingServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.FeedMappingServiceInterface)4 FeedServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.FeedServiceInterface)4 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)3 CampaignFeedPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedPage)3 ConstantOperand (com.google.api.ads.adwords.axis.v201809.cm.ConstantOperand)3 ExtensionSetting (com.google.api.ads.adwords.axis.v201809.cm.ExtensionSetting)3 Function (com.google.api.ads.adwords.axis.v201809.cm.Function)3