Search in sources :

Example 91 with Operation

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

the class AddSiteLinksUsingFeeds method restrictFeedItemToGeoTarget.

/**
 * Restricts the first feed item in {@code siteLinksData} to only serve with ads for the specified
 * location ID.
 */
private static void restrictFeedItemToGeoTarget(AdWordsServicesInterface adWordsServices, AdWordsSession session, FeedItem feedItem, Long locationId) throws RemoteException {
    FeedItemTargetServiceInterface feedItemTargetService = adWordsServices.get(session, FeedItemTargetServiceInterface.class);
    // Optional: Restrict the feed item to only serve with ads for the specified geo target.
    FeedItemCriterionTarget feedItemCriterionTarget = new FeedItemCriterionTarget();
    feedItemCriterionTarget.setFeedId(feedItem.getFeedId());
    feedItemCriterionTarget.setFeedItemId(feedItem.getFeedItemId());
    Location location = new Location();
    // The IDs can be found in the documentation or retrieved with the LocationCriterionService.
    location.setId(locationId);
    feedItemCriterionTarget.setCriterion(location);
    FeedItemTargetOperation operation = new FeedItemTargetOperation();
    operation.setOperand(feedItemCriterionTarget);
    operation.setOperator(Operator.ADD);
    feedItemCriterionTarget = (FeedItemCriterionTarget) feedItemTargetService.mutate(new FeedItemTargetOperation[] { operation }).getValue(0);
    System.out.printf("Feed item target for feed ID %d and feed item ID %d was created to restrict serving to " + "location ID %d'.%n", feedItemCriterionTarget.getFeedId(), feedItemCriterionTarget.getFeedItemId(), feedItemCriterionTarget.getCriterion().getId());
}
Also used : FeedItemTargetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedItemTargetServiceInterface) FeedItemCriterionTarget(com.google.api.ads.adwords.axis.v201809.cm.FeedItemCriterionTarget) FeedItemTargetOperation(com.google.api.ads.adwords.axis.v201809.cm.FeedItemTargetOperation) Location(com.google.api.ads.adwords.axis.v201809.cm.Location)

Example 92 with Operation

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

the class AddSiteLinksUsingFeeds method createSiteLinksFeed.

private static void createSiteLinksFeed(AdWordsServicesInterface adWordsServices, AdWordsSession session, SiteLinksDataHolder siteLinksData, String feedName) throws RemoteException {
    // Get the FeedService.
    FeedServiceInterface feedService = adWordsServices.get(session, FeedServiceInterface.class);
    // Create attributes.
    FeedAttribute textAttribute = new FeedAttribute();
    textAttribute.setType(FeedAttributeType.STRING);
    textAttribute.setName("Link Text");
    FeedAttribute finalUrlAttribute = new FeedAttribute();
    finalUrlAttribute.setType(FeedAttributeType.URL_LIST);
    finalUrlAttribute.setName("Link Final URLs");
    FeedAttribute line2Attribute = new FeedAttribute();
    line2Attribute.setType(FeedAttributeType.STRING);
    line2Attribute.setName("Line 2");
    FeedAttribute line3Attribute = new FeedAttribute();
    line3Attribute.setType(FeedAttributeType.STRING);
    line3Attribute.setName("Line 3");
    // Create the feed.
    Feed siteLinksFeed = new Feed();
    siteLinksFeed.setName(feedName);
    siteLinksFeed.setAttributes(new FeedAttribute[] { textAttribute, finalUrlAttribute, line2Attribute, line3Attribute });
    siteLinksFeed.setOrigin(FeedOrigin.USER);
    // Create operation.
    FeedOperation operation = new FeedOperation();
    operation.setOperand(siteLinksFeed);
    operation.setOperator(Operator.ADD);
    // Add the feed.
    FeedReturnValue result = feedService.mutate(new FeedOperation[] { operation });
    Feed savedFeed = result.getValue()[0];
    siteLinksData.siteLinksFeedId = savedFeed.getId();
    FeedAttribute[] savedAttributes = savedFeed.getAttributes();
    siteLinksData.linkTextFeedAttributeId = savedAttributes[0].getId();
    siteLinksData.linkFinalUrlFeedAttributeId = savedAttributes[1].getId();
    siteLinksData.line2FeedAttributeId = savedAttributes[2].getId();
    siteLinksData.line3FeedAttributeId = savedAttributes[3].getId();
    System.out.printf("Feed with name '%s' and ID %d with linkTextAttributeId %d" + " and linkFinalUrlAttributeId %d and line2AttributeId %d" + " and line3AttributeId %d was created.%n", savedFeed.getName(), savedFeed.getId(), savedAttributes[0].getId(), savedAttributes[1].getId(), savedAttributes[2].getId(), savedAttributes[3].getId());
}
Also used : FeedAttribute(com.google.api.ads.adwords.axis.v201809.cm.FeedAttribute) FeedReturnValue(com.google.api.ads.adwords.axis.v201809.cm.FeedReturnValue) CampaignFeedReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedReturnValue) CampaignFeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedServiceInterface) FeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedServiceInterface) FeedOperation(com.google.api.ads.adwords.axis.v201809.cm.FeedOperation) CampaignFeedOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedOperation) CampaignFeed(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeed) Feed(com.google.api.ads.adwords.axis.v201809.cm.Feed)

Example 93 with Operation

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

the class AddCompleteCampaignsUsingBatchJob method buildAdGroupOperations.

private static List<AdGroupOperation> buildAdGroupOperations(Iterator<Long> tempIdGenerator, String namePrefix, Iterable<CampaignOperation> campaignOperations) {
    List<AdGroupOperation> operations = new ArrayList<>();
    for (CampaignOperation campaignOperation : campaignOperations) {
        for (int i = 0; i < NUMBER_OF_ADGROUPS_TO_ADD; i++) {
            AdGroup adGroup = new AdGroup();
            adGroup.setCampaignId(campaignOperation.getOperand().getId());
            adGroup.setId(tempIdGenerator.next());
            adGroup.setName(String.format("Batch Ad Group %s.%s", namePrefix, i));
            BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
            CpcBid bid = new CpcBid();
            bid.setBid(new Money(null, 10000000L));
            biddingStrategyConfiguration.setBids(new Bids[] { bid });
            adGroup.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
            AdGroupOperation operation = new AdGroupOperation();
            operation.setOperand(adGroup);
            operation.setOperator(Operator.ADD);
            operations.add(operation);
        }
    }
    return operations;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) ArrayList(java.util.ArrayList) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)

Example 94 with Operation

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

the class AddAdGroups method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the campaign where the ad groups will be created.
 * @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) throws RemoteException {
    // Get the AdGroupService.
    AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
    // Create ad group.
    AdGroup adGroup = new AdGroup();
    adGroup.setName("Earth to Mars Cruises #" + System.currentTimeMillis());
    adGroup.setStatus(AdGroupStatus.ENABLED);
    adGroup.setCampaignId(campaignId);
    // Optional settings.
    // Targeting restriction settings. Depending on the criterionTypeGroup
    // value, most TargetingSettingDetail only affect Display campaigns.
    // However, the USER_INTEREST_AND_LIST value works for RLSA campaigns -
    // Search campaigns targeting using a remarketing list.
    TargetingSetting targeting = new TargetingSetting();
    // Restricting to serve ads that match your ad group placements.
    // This is equivalent to choosing "Target and bid" in the UI.
    TargetingSettingDetail placements = new TargetingSettingDetail();
    placements.setCriterionTypeGroup(CriterionTypeGroup.PLACEMENT);
    placements.setTargetAll(Boolean.FALSE);
    // Using your ad group verticals only for bidding. This is equivalent
    // to choosing "Bid only" in the UI.
    TargetingSettingDetail verticals = new TargetingSettingDetail();
    verticals.setCriterionTypeGroup(CriterionTypeGroup.VERTICAL);
    verticals.setTargetAll(Boolean.TRUE);
    targeting.setDetails(new TargetingSettingDetail[] { placements, verticals });
    adGroup.setSettings(new Setting[] { targeting });
    // Set the rotation mode.
    AdGroupAdRotationMode rotationMode = new AdGroupAdRotationMode(AdRotationMode.OPTIMIZE);
    adGroup.setAdGroupAdRotationMode(rotationMode);
    // Create ad group bid.
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    Money cpcBidMoney = new Money();
    cpcBidMoney.setMicroAmount(10_000_000L);
    CpcBid bid = new CpcBid();
    bid.setBid(cpcBidMoney);
    biddingStrategyConfiguration.setBids(new Bids[] { bid });
    adGroup.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    // Add as many additional ad groups as you need.
    AdGroup adGroup2 = new AdGroup();
    adGroup2.setName("Earth to Venus Cruises #" + System.currentTimeMillis());
    adGroup2.setStatus(AdGroupStatus.ENABLED);
    adGroup2.setCampaignId(campaignId);
    BiddingStrategyConfiguration biddingStrategyConfiguration2 = new BiddingStrategyConfiguration();
    Money cpcBidMoney2 = new Money();
    cpcBidMoney2.setMicroAmount(10_000_000L);
    CpcBid bid2 = new CpcBid();
    bid2.setBid(cpcBidMoney2);
    biddingStrategyConfiguration2.setBids(new Bids[] { bid2 });
    adGroup2.setBiddingStrategyConfiguration(biddingStrategyConfiguration2);
    // Create operations.
    AdGroupOperation operation = new AdGroupOperation();
    operation.setOperand(adGroup);
    operation.setOperator(Operator.ADD);
    AdGroupOperation operation2 = new AdGroupOperation();
    operation2.setOperand(adGroup2);
    operation2.setOperator(Operator.ADD);
    AdGroupOperation[] operations = new AdGroupOperation[] { operation, operation2 };
    // Add ad groups.
    AdGroupReturnValue result = adGroupService.mutate(operations);
    // Display new ad groups.
    for (AdGroup adGroupResult : result.getValue()) {
        System.out.printf("Ad group with name '%s' and ID %d was added.%n", adGroupResult.getName(), adGroupResult.getId());
    }
}
Also used : TargetingSettingDetail(com.google.api.ads.adwords.axis.v201809.cm.TargetingSettingDetail) Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface) TargetingSetting(com.google.api.ads.adwords.axis.v201809.cm.TargetingSetting) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) AdGroupReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupReturnValue) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) AdGroupAdRotationMode(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdRotationMode) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)

Example 95 with Operation

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

the class ProductPartitionTreeTest method testCreateMultiNodeTreeFromScratch.

/**
 * Tests creating an empty tree and then adding several levels of nodes.
 */
@Test
public void testCreateMultiNodeTreeFromScratch() {
    ProductPartitionTree tree = ProductPartitionTree.createAdGroupTree(-1L, biddingStrategyConfig, Collections.<AdGroupCriterion>emptyList());
    ProductPartitionNode rootNode = tree.getRoot().asSubdivision();
    ProductPartitionNode brand1 = rootNode.addChild(ProductDimensions.createBrand("google")).asSubdivision();
    ProductPartitionNode brand1Offer1 = brand1.addChild(ProductDimensions.createOfferId("A")).asBiddableUnit().setBid(1000000L).putCustomParameter("param1", "value1").putCustomParameter("param2", "value2");
    ProductPartitionNode brand1Offer2 = brand1.addChild(ProductDimensions.createOfferId(null)).asExcludedUnit();
    ProductPartitionNode brand2 = rootNode.addChild(ProductDimensions.createBrand(null)).asExcludedUnit();
    int expectedOpCount = 5;
    List<AdGroupCriterionOperation> mutateOperations = tree.getMutateOperations();
    assertEquals("Number of operations is incorrect", expectedOpCount, mutateOperations.size());
    List<CriterionDescriptor> nodeDescriptors = Stream.of(rootNode, brand1, brand1Offer1, brand1Offer2, brand2).map(CriterionDescriptor::new).collect(Collectors.toList());
    int opNum = 0;
    List<CriterionDescriptor> opDescriptors = Lists.newArrayList();
    Map<Long, CriterionDescriptor> opDescriptorsById = Maps.newHashMap();
    for (AdGroupCriterionOperation op : mutateOperations) {
        CriterionDescriptor opDescriptor = new CriterionDescriptor(op.getOperand(), opNum++);
        opDescriptors.add(opDescriptor);
        opDescriptorsById.put(opDescriptor.partitionId, opDescriptor);
    }
    Map<Long, Map<Long, CriterionDescriptor>> opDescriptorMap = buildDescriptorMap(opDescriptors);
    for (CriterionDescriptor nodeDescriptor : nodeDescriptors) {
        CriterionDescriptor opDescriptor = opDescriptorMap.get(nodeDescriptor.parentPartitionId).get(nodeDescriptor.partitionId);
        nodeDescriptor.assertDescriptorEquals(opDescriptor);
        AdGroupCriterionOperation op = mutateOperations.get(opDescriptor.operationNumber);
        assertEquals("operator is incorrect", Operator.ADD, op.getOperator());
        if (nodeDescriptor.parentPartitionId != null) {
            CriterionDescriptor parentOpDescriptor = opDescriptorsById.get(nodeDescriptor.parentPartitionId);
            assertNotNull("no operation found for parent", parentOpDescriptor);
            assertThat("operation # for parent is > operation # for child", opDescriptor.operationNumber, Matchers.greaterThan(parentOpDescriptor.operationNumber));
        }
    }
    assertThat("Tree toString does not contain the root's detailed toString", tree.toString(), Matchers.containsString(tree.getRoot().toDetailedString()));
    assertThat("Tree toString does not contain the ad group ID", tree.toString(), Matchers.containsString(tree.getAdGroupId().toString()));
}
Also used : AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) Map(java.util.Map) HashMap(java.util.HashMap) MockHttpIntegrationTest(com.google.api.ads.common.lib.testing.MockHttpIntegrationTest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)24 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)18 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)17 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)16 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)15 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)14 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)14 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)13 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)13 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)12 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)12 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)11 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)11 AdGroupAdReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue)10 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)10 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)9 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)8 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)8 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)8 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)8