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);
}
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());
}
}
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());
}
}
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());
}
}
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;
}
Aggregations