com.google.api.ads.adwords.axis.v201809.cm.Money Java Examples
The following examples show how to use
com.google.api.ads.adwords.axis.v201809.cm.Money.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeywordOptimizerUtil.java From keyword-optimizer with Apache License 2.0 | 6 votes |
/** * Returns the mean of the two {@link Money} values if neither is null, else returns null. * * @param value1 first value * @param value2 second value * @return the mean of the two {@link Money} values */ private static Money calculateMean(Money value1, Money value2) { if (value1 == null || value2 == null) { return null; } Double meanAmount = calculateMean(value1.getMicroAmount(), value2.getMicroAmount()); if (meanAmount == null) { return null; } Money mean = new Money(); mean.setMicroAmount(meanAmount.longValue()); return mean; }
Example #2
Source File: ProductPartitionTreeImpl.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** * Returns the criterion-level bid, or null if no such bid exists. */ private static Money getBid(BiddableAdGroupCriterion biddableCriterion) { BiddingStrategyConfiguration biddingConfig = biddableCriterion.getBiddingStrategyConfiguration(); Money cpcBidAmount = null; if (biddingConfig.getBids() != null) { for (Bids bid : biddingConfig.getBids()) { if (bid instanceof CpcBid) { CpcBid cpcBid = (CpcBid) bid; if (BidSource.CRITERION.equals(cpcBid.getCpcBidSource())) { cpcBidAmount = cpcBid.getBid(); break; } } } } return cpcBidAmount; }
Example #3
Source File: AxisBatchJobUploadBodyProviderTest.java From googleads-java-lib with Apache License 2.0 | 6 votes |
@Override protected void addBudgetOperation( BatchJobMutateRequest request, long budgetId, String budgetName, long budgetAmountInMicros, String deliveryMethod) { Budget budget = new Budget(); budget.setBudgetId(budgetId); budget.setName(budgetName); Money budgetAmount = new Money(); budgetAmount.setMicroAmount(budgetAmountInMicros); budget.setAmount(budgetAmount); budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.fromString(deliveryMethod)); BudgetOperation budgetOperation = new BudgetOperation(); budgetOperation.setOperand(budget); budgetOperation.setOperator(Operator.ADD); request.addOperation(budgetOperation); }
Example #4
Source File: AddDynamicSearchAdsCampaign.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** Creates the budget. */ private static Budget createBudget( AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException, ApiException { // Get the BudgetService. BudgetServiceInterface budgetService = adWordsServices.get(session, BudgetServiceInterface.class); // Create a budget, which can be shared by multiple campaigns. Budget sharedBudget = new Budget(); sharedBudget.setName("Interplanetary Cruise #" + System.currentTimeMillis()); Money budgetAmount = new Money(); budgetAmount.setMicroAmount(50000000L); sharedBudget.setAmount(budgetAmount); sharedBudget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD); BudgetOperation budgetOperation = new BudgetOperation(); budgetOperation.setOperand(sharedBudget); budgetOperation.setOperator(Operator.ADD); // Add the budget Budget budget = budgetService.mutate(new BudgetOperation[] {budgetOperation}).getValue(0); return budget; }
Example #5
Source File: ProductPartitionTreeImpl.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** * Using the criteria in {@code parentIdMap}, recursively adds all children under the partition ID * of {@code parentNode} to {@code parentNode}. * * @param parentNode required * @param parentIdMap the multimap from parent partition ID to list of child criteria */ private static void addChildNodes(ProductPartitionNode parentNode, ListMultimap<Long, AdGroupCriterion> parentIdMap) { if (parentIdMap.containsKey(parentNode.getProductPartitionId())) { parentNode = parentNode.asSubdivision(); } for (AdGroupCriterion adGroupCriterion : parentIdMap.get(parentNode.getProductPartitionId())) { ProductPartition partition = (ProductPartition) adGroupCriterion.getCriterion(); ProductPartitionNode childNode = parentNode.addChild(partition.getCaseValue()); childNode = childNode.setProductPartitionId(partition.getId()); if (ProductPartitionType.SUBDIVISION.equals(partition.getPartitionType())) { childNode = childNode.asSubdivision(); } else { if (adGroupCriterion instanceof BiddableAdGroupCriterion) { childNode = childNode.asBiddableUnit(); BiddableAdGroupCriterion biddableAdGroupCriterion = (BiddableAdGroupCriterion) adGroupCriterion; Money cpcBidAmount = getBid(biddableAdGroupCriterion); if (cpcBidAmount != null) { childNode = childNode.setBid(cpcBidAmount.getMicroAmount()); } childNode = childNode.setTrackingUrlTemplate(biddableAdGroupCriterion.getTrackingUrlTemplate()); childNode = copyCustomParametersToNode(biddableAdGroupCriterion, childNode); } else { childNode = childNode.asExcludedUnit(); } } addChildNodes(childNode, parentIdMap); } }
Example #6
Source File: ProductPartitionNodeAdapter.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** * Returns a new AdGroupCriterion configured for a SET operation that will set the criterion's * bid, tracking template, and custom parameters. * * @param node the node whose criterion should be updated * @param adGroupId the ad group ID of the criterion * @param biddingConfig the bidding strategy configuration of the criterion */ static AdGroupCriterion createCriterionForSetBiddableUnit( ProductPartitionNode node, long adGroupId, BiddingStrategyConfiguration biddingConfig) { Preconditions.checkNotNull(node, "Null node"); Preconditions.checkNotNull(biddingConfig, "Null bidding configuration"); Preconditions.checkArgument(node.isBiddableUnit(), "Node is not a biddable unit"); BiddableAdGroupCriterion biddableCriterion = new BiddableAdGroupCriterion(); biddableCriterion.setAdGroupId(adGroupId); ProductPartition partition = new ProductPartition(); partition.setId(node.getProductPartitionId()); if (node.getParent() != null) { partition.setParentCriterionId(node.getParent().getProductPartitionId()); } partition.setCaseValue(node.getDimension()); partition.setPartitionType(ProductPartitionType.UNIT); biddableCriterion.setCriterion(partition); // Set the bidding attributes on the new ad group criterion. if (node.getBid() != null) { Money bidMoney = new Money(); bidMoney.setMicroAmount(node.getBid()); CpcBid cpcBid = new CpcBid(); cpcBid.setBid(bidMoney); biddingConfig.setBids(new Bids[] {cpcBid}); } else { biddingConfig.setBids(new Bids[0]); } biddableCriterion.setBiddingStrategyConfiguration(biddingConfig); // Set the upgraded URL attributes on the new ad group criterion. if (node.getTrackingUrlTemplate() != null) { biddableCriterion.setTrackingUrlTemplate( node.getTrackingUrlTemplate()); } biddableCriterion.setUrlCustomParameters(createCustomParameters(node)); return biddableCriterion; }
Example #7
Source File: KeywordOptimizerUtil.java From keyword-optimizer with Apache License 2.0 | 5 votes |
/** * Calculates the mean estimated statistics based on minimum and maximum values. * * @param min the minimum estimated statistics * @param max the maximum estimated statistics * @return the mean value for all given stats */ public static StatsEstimate calculateMean(StatsEstimate min, StatsEstimate max) { Money meanAverageCpc = calculateMean(min.getAverageCpc(), max.getAverageCpc()); Double meanAveragePosition = calculateMean(min.getAveragePosition(), max.getAveragePosition()); Double meanClicks = calculateMean(min.getClicksPerDay(), max.getClicksPerDay()); Double meanImpressions = calculateMean(min.getImpressionsPerDay(), max.getImpressionsPerDay()); Double meanCtr = calculateMean(min.getClickThroughRate(), max.getClickThroughRate()); Money meanTotalCost = calculateMean(min.getTotalCost(), max.getTotalCost()); StatsEstimate mean = new StatsEstimate(); if (meanAverageCpc != null) { mean.setAverageCpc(meanAverageCpc); } if (meanAveragePosition != null) { mean.setAveragePosition(meanAveragePosition); } if (meanClicks != null) { mean.setClicksPerDay(meanClicks.floatValue()); } if (meanImpressions != null) { mean.setImpressionsPerDay(meanImpressions.floatValue()); } if (meanCtr != null) { mean.setClickThroughRate(meanCtr); } if (meanTotalCost != null) { mean.setTotalCost(meanTotalCost); } return mean; }
Example #8
Source File: AdWordsAxisSoapIntegrationTest.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** * Submits a BudgetService.mutate call to the test server and asserts that the response contains * expected values. */ private void testBudgetServiceMutateRequest(AdWordsSession session) throws RemoteException, ApiException, IOException, SAXException { BudgetServiceInterface companyService = new AdWordsServices().get(session, BudgetServiceInterface.class); Budget budget = new Budget(); budget.setName("Test Budget Name"); Money money = new Money(); money.setMicroAmount(50000000L); budget.setAmount(money); budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD); BudgetOperation operation = new BudgetOperation(); operation.setOperand(budget); operation.setOperator(Operator.ADD); Budget responseBudget = companyService.mutate(new BudgetOperation[] {operation}).getValue(0); assertEquals("Budget ID does not match", 251877074L, responseBudget.getBudgetId().longValue()); assertEquals("Budget name does not match", budget.getName(), responseBudget.getName()); assertEquals("Budget amount does not match", budget.getAmount().getMicroAmount(), responseBudget.getAmount().getMicroAmount()); assertEquals("Budget delivery method does not match", budget.getDeliveryMethod(), responseBudget.getDeliveryMethod()); assertFalse("Did not request compression but request was compressed", testHttpServer.wasLastRequestBodyCompressed()); XMLAssert.assertXMLEqual(SoapRequestXmlProvider.getOAuth2SoapRequest(API_VERSION), testHttpServer.getLastRequestBody()); }
Example #9
Source File: AddCompleteCampaignsUsingBatchJob.java From googleads-java-lib with Apache License 2.0 | 5 votes |
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; }
Example #10
Source File: AddCompleteCampaignsUsingBatchJob.java From googleads-java-lib with Apache License 2.0 | 5 votes |
private static BudgetOperation buildBudgetOperation(Iterator<Long> tempIdGenerator, String namePrefix) { Budget budget = new Budget(); budget.setBudgetId(tempIdGenerator.next()); budget.setName(String.format("Interplanetary Cruise %s", namePrefix)); Money budgetAmount = new Money(); budgetAmount.setMicroAmount(50000000L); budget.setAmount(budgetAmount); budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD); BudgetOperation budgetOperation = new BudgetOperation(); budgetOperation.setOperand(budget); budgetOperation.setOperator(Operator.ADD); return budgetOperation; }
Example #11
Source File: UsePortfolioBiddingStrategy.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** * Creates the bidding strategy object. * * @param adWordsServices the user to run the example with * @param session the AdWordsSession * @throws ApiException if the API request failed with one or more service errors. * @throws RemoteException if the API request failed due to other errors. */ private static SharedBiddingStrategy createBiddingStrategy( AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException { // Get the BiddingStrategyService, which loads the required classes. BiddingStrategyServiceInterface biddingStrategyService = adWordsServices.get(session, BiddingStrategyServiceInterface.class); // Create a portfolio bidding strategy. SharedBiddingStrategy portfolioBiddingStrategy = new SharedBiddingStrategy(); portfolioBiddingStrategy.setName("Maximize Clicks" + System.currentTimeMillis()); TargetSpendBiddingScheme biddingScheme = new TargetSpendBiddingScheme(); // Optionally set additional bidding scheme parameters. biddingScheme.setBidCeiling(new Money(null, 2000000L)); biddingScheme.setSpendTarget(new Money(null, 20000000L)); portfolioBiddingStrategy.setBiddingScheme(biddingScheme); // Create operation. BiddingStrategyOperation operation = new BiddingStrategyOperation(); operation.setOperand(portfolioBiddingStrategy); operation.setOperator(Operator.ADD); BiddingStrategyOperation[] operations = new BiddingStrategyOperation[] {operation}; BiddingStrategyReturnValue result = biddingStrategyService.mutate(operations); SharedBiddingStrategy newBiddingStrategy = result.getValue(0); System.out.printf( "Portfolio bidding strategy with name '%s' and ID %d of type '%s' was created.%n", newBiddingStrategy.getName(), newBiddingStrategy.getId(), newBiddingStrategy.getBiddingScheme().getBiddingSchemeType()); return newBiddingStrategy; }
Example #12
Source File: UsePortfolioBiddingStrategy.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** * Creates an explicit budget to be used only to create the Campaign. * * @param adWordsServices the user to run the example with * @param session the AdWordsSession * @throws ApiException if the API request failed with one or more service errors. * @throws RemoteException if the API request failed due to other errors. */ private static Budget createSharedBudget( AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException { // Get the BudgetService, which loads the required classes. BudgetServiceInterface budgetService = adWordsServices.get(session, BudgetServiceInterface.class); // Create a shared budget. Budget budget = new Budget(); budget.setName("Shared Interplanetary Budget #" + System.currentTimeMillis()); budget.setAmount(new Money(null, 50000000L)); budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD); budget.setIsExplicitlyShared(true); BudgetOperation operation = new BudgetOperation(); operation.setOperand(budget); operation.setOperator(Operator.ADD); BudgetOperation[] operations = new BudgetOperation[] {operation}; // Make the mutate request. BudgetReturnValue result = budgetService.mutate(operations); Budget newBudget = result.getValue(0); System.out.printf("Budget with name '%s', ID %d was created.%n", newBudget.getName(), newBudget.getBudgetId()); return newBudget; }
Example #13
Source File: AddUniversalAppCampaign.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** * Creates the budget for the campaign. * * @return the new budget. */ private static Long createBudget(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException, ApiException { // Get the BudgetService. BudgetServiceInterface budgetService = adWordsServices.get(session, BudgetServiceInterface.class); // Create the campaign budget. Budget budget = new Budget(); budget.setName("Interplanetary Cruise App Budget #" + System.currentTimeMillis()); Money budgetAmount = new Money(); budgetAmount.setMicroAmount(50000000L); budget.setAmount(budgetAmount); budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD); // Universal app campaigns don't support shared budgets. budget.setIsExplicitlyShared(false); BudgetOperation budgetOperation = new BudgetOperation(); budgetOperation.setOperand(budget); budgetOperation.setOperator(Operator.ADD); // Add the budget Budget addedBudget = budgetService.mutate(new BudgetOperation[] {budgetOperation}).getValue(0); System.out.printf( "Budget with name '%s' and ID %d was created.%n", addedBudget.getName(), addedBudget.getBudgetId()); return addedBudget.getBudgetId(); }
Example #14
Source File: UploadOfflineData.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** Returns a new offline data object with the specified values. */ private static OfflineData createOfflineData( DateTime transactionTime, long transactionMicroAmount, String transactionCurrency, String conversionName, List<UserIdentifier> userIdentifiers) { StoreSalesTransaction storeSalesTransaction = new StoreSalesTransaction(); // For times use the format yyyyMMdd HHmmss [tz]. // For details, see // https://developers.google.com/adwords/api/docs/appendix/codes-formats#date-and-time-formats storeSalesTransaction.setTransactionTime(transactionTime.toString("yyyyMMdd HHmmss ZZZ")); storeSalesTransaction.setConversionName(conversionName); storeSalesTransaction.setUserIdentifiers( userIdentifiers.toArray(new UserIdentifier[userIdentifiers.size()])); Money money = new Money(); money.setMicroAmount(transactionMicroAmount); MoneyWithCurrency moneyWithCurrency = new MoneyWithCurrency(); moneyWithCurrency.setMoney(money); moneyWithCurrency.setCurrencyCode(transactionCurrency); storeSalesTransaction.setTransactionAmount(moneyWithCurrency); OfflineData offlineData = new OfflineData(); offlineData.setStoreSalesTransaction(storeSalesTransaction); return offlineData; }
Example #15
Source File: AddPrices.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** * Creates a new {@link PriceTableRow} with the specified attributes. * * @param header the header for the row * @param description the description for the row * @param finalUrl the final URL for the row * @param finalMobileUrl the final mobile URL for the row, or null if this field should not be set * @param priceInMicros the price for the row, in micros * @param currencyCode the currency for the row * @param priceUnit the price unit for the row * @return a new {@link PriceTableRow} */ private static PriceTableRow createPriceTableRow( String header, String description, String finalUrl, String finalMobileUrl, long priceInMicros, String currencyCode, PriceExtensionPriceUnit priceUnit) { PriceTableRow priceTableRow = new PriceTableRow(); priceTableRow.setHeader(header); priceTableRow.setDescription(description); UrlList finalUrls = new UrlList(); finalUrls.setUrls(new String[] {finalUrl}); priceTableRow.setFinalUrls(finalUrls); if (finalMobileUrl != null) { UrlList finalMobileUrls = new UrlList(); finalMobileUrls.setUrls(new String[] {finalMobileUrl}); priceTableRow.setFinalMobileUrls(finalMobileUrls); } MoneyWithCurrency price = new MoneyWithCurrency(); Money priceMoney = new Money(); price.setCurrencyCode(currencyCode); priceMoney.setMicroAmount(priceInMicros); price.setMoney(priceMoney); priceTableRow.setPrice(price); priceTableRow.setPriceUnit(priceUnit); return priceTableRow; }
Example #16
Source File: EstimateKeywordTraffic.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** * Returns the mean of the {@code microAmount} of the two Money values if neither is null, else * returns null. */ private static Double calculateMean(Money minMoney, Money maxMoney) { if (minMoney == null || maxMoney == null) { return null; } return calculateMean(minMoney.getMicroAmount(), maxMoney.getMicroAmount()); }
Example #17
Source File: AddShoppingCampaignForShowcaseAds.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** Creates an ad group in the Shopping campaign. */ private static AdGroup createAdGroup( AdWordsServicesInterface adWordsServices, AdWordsSession session, Campaign campaign) throws RemoteException { // Get the AdGroupService. AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class); // Create ad group. AdGroup adGroup = new AdGroup(); adGroup.setCampaignId(campaign.getId()); adGroup.setName("Ad Group #" + System.currentTimeMillis()); // Required: Set the ad group type to SHOPPING_SHOWCASE_ADS. adGroup.setAdGroupType(AdGroupType.SHOPPING_SHOWCASE_ADS); // Required: Set the ad group's bidding strategy configuration. // Note: Showcase ads require that the campaign has a ManualCpc BiddingStrategyConfiguration. BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration(); // Optional: Set the bids. Money bidAmount = new Money(); bidAmount.setMicroAmount(100000L); CpcBid cpcBid = new CpcBid(); cpcBid.setBid(bidAmount); biddingStrategyConfiguration.setBids(new Bids[] {cpcBid}); adGroup.setBiddingStrategyConfiguration(biddingStrategyConfiguration); // Create operation. AdGroupOperation adGroupOperation = new AdGroupOperation(); adGroupOperation.setOperand(adGroup); adGroupOperation.setOperator(Operator.ADD); // Make the mutate request. AdGroupReturnValue adGroupAddResult = adGroupService.mutate(new AdGroupOperation[] {adGroupOperation}); return adGroupAddResult.getValue(0); }
Example #18
Source File: EvaluatorTest.java From keyword-optimizer with Apache License 2.0 | 5 votes |
/** * Setup some sample keywords. */ @Before public void setUp() { plumbing = new Keyword(); plumbing.setText("plumbing"); plumbing.setMatchType(KeywordMatchType.EXACT); plumbingBroad = new Keyword(); plumbingBroad.setText("plumbing"); plumbingBroad.setMatchType(KeywordMatchType.BROAD); plumbingSpecialist = new Keyword(); plumbingSpecialist.setText("plumbing specialist"); plumbingSpecialist.setMatchType(KeywordMatchType.EXACT); maxCpc = new Money(); maxCpc.setMicroAmount(1000000L); // 1 usd CampaignConfiguration campaignSettings = CampaignConfiguration.builder() .withMaxCpc(maxCpc) .build(); keywords = new KeywordCollection(campaignSettings); keywords.add(new KeywordInfo(plumbing, IdeaEstimate.EMPTY_ESTIMATE, null, null)); keywords.add(new KeywordInfo(plumbingBroad, IdeaEstimate.EMPTY_ESTIMATE, null, null)); keywords.add(new KeywordInfo(plumbingSpecialist, IdeaEstimate.EMPTY_ESTIMATE, null, null)); minStats = new StatsEstimate(); minStats.setClicksPerDay(10F); minStats.setImpressionsPerDay(1000F); maxStats = new StatsEstimate(); maxStats.setClicksPerDay(20F); maxStats.setImpressionsPerDay(2000F); clicksEvaluator = new EstimatorBasedEvaluator(new MockTrafficEstimator(), new ClicksScoreCalculator()); impressionsEvaluator = new EstimatorBasedEvaluator(new MockTrafficEstimator(), new ImpressionsScoreCalculator()); }
Example #19
Source File: ProductPartitionTreeImpl.java From googleads-java-lib with Apache License 2.0 | 5 votes |
/** * Returns a new tree based on a non-empty collection of ad group criteria. All parameters * required. * * @param adGroupId the ID of the ad group * @param parentIdMap the multimap from parent product partition ID to child criteria * @return a new ProductPartitionTree */ private static ProductPartitionTreeImpl createNonEmptyAdGroupTree(Long adGroupId, ListMultimap<Long, AdGroupCriterion> parentIdMap) { Preconditions.checkNotNull(adGroupId, "Null ad group ID"); Preconditions.checkArgument(!parentIdMap.isEmpty(), "parentIdMap passed for ad group ID %s is empty", adGroupId); Preconditions.checkArgument(parentIdMap.containsKey(null), "No root criterion found in the list of ad group criteria for ad group ID %s", adGroupId); AdGroupCriterion rootCriterion = Iterables.getOnlyElement(parentIdMap.get(null)); Preconditions.checkState(rootCriterion instanceof BiddableAdGroupCriterion, "Root criterion for ad group ID %s is not a BiddableAdGroupCriterion", adGroupId); BiddableAdGroupCriterion biddableRootCriterion = (BiddableAdGroupCriterion) rootCriterion; BiddingStrategyConfiguration biddingStrategyConfig = biddableRootCriterion.getBiddingStrategyConfiguration(); Preconditions.checkState(biddingStrategyConfig != null, "Null bidding strategy config on the root node of ad group ID %s", adGroupId); ProductPartitionNode rootNode = new ProductPartitionNode(null, (ProductDimension) null, rootCriterion.getCriterion().getId(), new ProductDimensionComparator()); // Set the root's bid if a bid exists on the BiddableAdGroupCriterion. Money rootNodeBid = getBid(biddableRootCriterion); if (rootNodeBid != null) { rootNode = rootNode.asBiddableUnit().setBid(rootNodeBid.getMicroAmount()); } rootNode = rootNode.setTrackingUrlTemplate(biddableRootCriterion.getTrackingUrlTemplate()); rootNode = copyCustomParametersToNode(biddableRootCriterion, rootNode); addChildNodes(rootNode, parentIdMap); return new ProductPartitionTreeImpl(adGroupId, biddingStrategyConfig, rootNode); }
Example #20
Source File: TrafficEstimatorTest.java From keyword-optimizer with Apache License 2.0 | 5 votes |
/** * Setup some sample keywords. */ @Before public void setUp() { plumbing = new Keyword(); plumbing.setText("plumbing"); plumbing.setMatchType(KeywordMatchType.EXACT); plumbingBroad = new Keyword(); plumbingBroad.setText("plumbing"); plumbingBroad.setMatchType(KeywordMatchType.BROAD); plumbingSpecialist = new Keyword(); plumbingSpecialist.setText("plumbing specialist"); plumbingSpecialist.setMatchType(KeywordMatchType.EXACT); maxCpc = new Money(); maxCpc.setMicroAmount(1000000L); // 1 usd CampaignConfiguration campaignSettings = CampaignConfiguration.builder() .withMaxCpc(maxCpc) .build(); keywords = new KeywordCollection(campaignSettings); keywords.add(new KeywordInfo(plumbing, null, null, null)); keywords.add(new KeywordInfo(plumbingBroad, null, null, null)); keywords.add(new KeywordInfo(plumbingSpecialist, null, null, null)); minStats = new StatsEstimate(); minStats.setClicksPerDay(10F); minStats.setImpressionsPerDay(1000F); maxStats = new StatsEstimate(); maxStats.setClicksPerDay(20F); maxStats.setImpressionsPerDay(2000F); }
Example #21
Source File: KeywordCollectionTest.java From keyword-optimizer with Apache License 2.0 | 5 votes |
/** * Setup some sample keywords. */ @Before public void setUp() { plumbing = new Keyword(); plumbing.setText("plumbing"); plumbing.setMatchType(KeywordMatchType.EXACT); plumbingBroad = new Keyword(); plumbingBroad.setText("plumbing"); plumbingBroad.setMatchType(KeywordMatchType.BROAD); plumbingSpecialist = new Keyword(); plumbingSpecialist.setText("plumbing specialist"); plumbingSpecialist.setMatchType(KeywordMatchType.EXACT); newYork = new Location(); newYork.setId(1023191L); english = new Language(); english.setId(1000L); maxCpc = new Money(); maxCpc.setMicroAmount(1000000L); // 1 usd campaignSettings = CampaignConfiguration.builder() .withMaxCpc(maxCpc) .withCriterion(english) .withCriterion(newYork) .build(); keywords = new KeywordCollection(campaignSettings); keywords = new KeywordCollection(campaignSettings); keywords.add(new KeywordInfo(plumbing, null, null, null)); keywords.add(new KeywordInfo(plumbingBroad, null, null, null)); keywords.add(new KeywordInfo(plumbingSpecialist, null, null, null)); }
Example #22
Source File: KeywordCollectionScoreTest.java From keyword-optimizer with Apache License 2.0 | 5 votes |
/** * Setup some sample keywords. */ @Before public void setUp() { alpha = new Keyword(); alpha.setText("alpha"); alpha.setMatchType(KeywordMatchType.EXACT); alphaInfo = new KeywordInfo(alpha, null, null, 3d); beta = new Keyword(); beta.setText("beta"); beta.setMatchType(KeywordMatchType.EXACT); betaInfo = new KeywordInfo(beta, null, null, 1d); betaBroad = new Keyword(); betaBroad.setText("beta"); betaBroad.setMatchType(KeywordMatchType.BROAD); betaBroadInfo = new KeywordInfo(betaBroad, null, null, 2d); gamma = new Keyword(); gamma.setText("gamma"); gamma.setMatchType(KeywordMatchType.EXACT); gammaInfo = new KeywordInfo(gamma, null, null, 4d); maxCpc = new Money(); maxCpc.setMicroAmount(1000000L); // 1 usd CampaignConfiguration campaignSettings = CampaignConfiguration.builder() .withMaxCpc(maxCpc) .build(); keywords = new KeywordCollection(campaignSettings); keywords.add(gammaInfo); keywords.add(betaInfo); keywords.add(alphaInfo); keywords.add(betaBroadInfo); }
Example #23
Source File: KeywordOptimizerUtil.java From keyword-optimizer with Apache License 2.0 | 5 votes |
/** * Formats a given monetary value in a default format (2 decimals, padded left to 10 characters). * * @param money a monetary value * @return a string version of the monetary value */ public static String format(Money money) { long microAmount; if (money != null) { microAmount = money.getMicroAmount(); } else { return PLACEHOLDER_NULL; } double amount = (double) microAmount / MICRO_UNITS; return String.format(FORMAT_MONEY, amount); }
Example #24
Source File: KeywordOptimizerUtil.java From keyword-optimizer with Apache License 2.0 | 5 votes |
/** * Converts a given map of attribute data from the {@link TargetingIdeaService} to {@link * IdeaEstimate} object. * * @param attributeData map of attribute data as returned by the {@link TargetingIdeaService} * @return a {@link IdeaEstimate} object containing typed data */ public static IdeaEstimate toSearchEstimate(Map<AttributeType, Attribute> attributeData) { LongAttribute searchVolumeAttribute = (LongAttribute) attributeData.get(AttributeType.SEARCH_VOLUME); MoneyAttribute averageCpcAttribute = (MoneyAttribute) attributeData.get(AttributeType.AVERAGE_CPC); DoubleAttribute competitionAttribute = (DoubleAttribute) attributeData.get(AttributeType.COMPETITION); MonthlySearchVolumeAttribute targetedMonthlySearchesAttribute = (MonthlySearchVolumeAttribute) attributeData.get(AttributeType.TARGETED_MONTHLY_SEARCHES); double competition = 0D; if (competitionAttribute != null && competitionAttribute.getValue() != null) { competition = competitionAttribute.getValue(); } long searchVolume = 0L; if (searchVolumeAttribute != null && searchVolumeAttribute.getValue() != null) { searchVolume = searchVolumeAttribute.getValue(); } Money averageCpc = KeywordOptimizerUtil.createMoney(0L); if (averageCpcAttribute != null && averageCpcAttribute.getValue() != null) { averageCpc = averageCpcAttribute.getValue(); } MonthlySearchVolume[] targetedMonthlySearches = new MonthlySearchVolume[] {}; if (targetedMonthlySearchesAttribute != null && targetedMonthlySearchesAttribute.getValue() != null) { targetedMonthlySearches = targetedMonthlySearchesAttribute.getValue(); } return new IdeaEstimate(competition, searchVolume, averageCpc, targetedMonthlySearches); }
Example #25
Source File: IdeaEstimate.java From keyword-optimizer with Apache License 2.0 | 5 votes |
/** * Create a new estimate based on the given arguments. * * @param competition the value returned as COMPETITION by the {@link TargetingIdeaService} * @param searchVolume the value returned as SEARCH_VOLUME by the {@link TargetingIdeaService} * @param averageCpc the value returned as AVERAGE_CPC by the {@link TargetingIdeaService} * @param targetedMonthlySearches the value returned as TARGETED_MONTHLY_SEARCHES by the {@link * TargetingIdeaService} */ public IdeaEstimate( double competition, long searchVolume, Money averageCpc, MonthlySearchVolume[] targetedMonthlySearches) { this.competition = competition; this.searchVolume = searchVolume; this.averageCpc = averageCpc; this.targetedMonthlySearches = targetedMonthlySearches == null ? ImmutableList.<MonthlySearchVolume>of() : ImmutableList.copyOf(targetedMonthlySearches); }
Example #26
Source File: FormulaContext.java From keyword-optimizer with Apache License 2.0 | 5 votes |
/** * Converts a given {@link Money} object to a number (or NaN if null). */ private static double toDoubleOrNaN(Money value) { if (value == null || value.getMicroAmount() == null) { return Double.NaN; } return value.getMicroAmount().doubleValue() / 1000000; }
Example #27
Source File: KeywordOptimizer.java From keyword-optimizer with Apache License 2.0 | 5 votes |
/** * Read the campaign settings (max. Cpc, additional criteria) from the command line. * @param cmdLine the parsed command line parameters * @return {@link CampaignConfiguration} including the specified settings */ private static CampaignConfiguration getCampaignConfiguration(CommandLine cmdLine) { CampaignConfigurationBuilder builder = CampaignConfiguration.builder(); // Read the max. Cpc parameter. double cpc = Double.parseDouble(cmdLine.getOptionValue("cpc")); Money maxCpc = new Money(); maxCpc.setMicroAmount((long) (cpc * 1000000d)); builder.withMaxCpc(maxCpc); // Read the language parameter. if (cmdLine.hasOption("lang")) { for (String language : cmdLine.getOptionValues("lang")) { long languageId = Long.parseLong(language); log("Using language: " + languageId); builder.withLanguage(languageId); } } // Read the location parameter. if (cmdLine.hasOption("loc")) { for (String location : cmdLine.getOptionValues("loc")) { long loc = Long.parseLong(location); log("Using location: " + loc); builder.withLocation(loc); } } return builder.build(); }
Example #28
Source File: UpdateKeyword.java From googleads-java-lib with Apache License 2.0 | 4 votes |
/** * Runs the example. * * @param adWordsServices the services factory. * @param session the session. * @param adGroupId the ID of the ad group for the criterion. * @param keywordId the ID of the criterion to update. * @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 adGroupId, Long keywordId) throws RemoteException { // Get the AdGroupCriterionService. AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class); // Create ad group criterion with updated bid. Criterion criterion = new Criterion(); criterion.setId(keywordId); BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion(); biddableAdGroupCriterion.setAdGroupId(adGroupId); biddableAdGroupCriterion.setCriterion(criterion); // Create bids. BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration(); CpcBid bid = new CpcBid(); bid.setBid(new Money(null, 10000000L)); biddingStrategyConfiguration.setBids(new Bids[] {bid}); biddableAdGroupCriterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration); // Create operations. AdGroupCriterionOperation operation = new AdGroupCriterionOperation(); operation.setOperand(biddableAdGroupCriterion); operation.setOperator(Operator.SET); AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] {operation}; // Update ad group criteria. AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations); // Display ad group criteria. for (AdGroupCriterion adGroupCriterionResult : result.getValue()) { if (adGroupCriterionResult instanceof BiddableAdGroupCriterion) { biddableAdGroupCriterion = (BiddableAdGroupCriterion) adGroupCriterionResult; CpcBid criterionCpcBid = null; // Find the criterion-level CpcBid among the keyword's bids. for (Bids bids : biddableAdGroupCriterion.getBiddingStrategyConfiguration().getBids()) { if (bids instanceof CpcBid) { CpcBid cpcBid = (CpcBid) bids; if (BidSource.CRITERION.equals(cpcBid.getCpcBidSource())) { criterionCpcBid = cpcBid; } } } System.out.printf( "Ad group criterion with ad group ID %d, criterion ID %d, type " + "'%s', and bid %d was updated.%n", biddableAdGroupCriterion.getAdGroupId(), biddableAdGroupCriterion.getCriterion().getId(), biddableAdGroupCriterion.getCriterion().getCriterionType(), criterionCpcBid.getBid().getMicroAmount()); } } }
Example #29
Source File: AddKeywords.java From googleads-java-lib with Apache License 2.0 | 4 votes |
/** * Runs the example. * * @param adWordsServices the services factory. * @param session the session. * @param adGroupId the ID of the ad group where the keywords 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. * @throws UnsupportedEncodingException if encoding the final URL failed. */ public static void runExample( AdWordsServicesInterface adWordsServices, AdWordsSession session, long adGroupId) throws RemoteException, UnsupportedEncodingException { // Get the AdGroupCriterionService. AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class); // Create keywords. Keyword keyword1 = new Keyword(); keyword1.setText("mars cruise"); keyword1.setMatchType(KeywordMatchType.BROAD); Keyword keyword2 = new Keyword(); keyword2.setText("space hotel"); keyword2.setMatchType(KeywordMatchType.EXACT); // Create biddable ad group criterion. BiddableAdGroupCriterion keywordBiddableAdGroupCriterion1 = new BiddableAdGroupCriterion(); keywordBiddableAdGroupCriterion1.setAdGroupId(adGroupId); keywordBiddableAdGroupCriterion1.setCriterion(keyword1); // You can optionally provide these field(s). keywordBiddableAdGroupCriterion1.setUserStatus(UserStatus.PAUSED); String encodedFinalUrl = String.format("http://example.com/mars/cruise/?kw=%s", URLEncoder.encode(keyword1.getText(), UTF_8.name())); keywordBiddableAdGroupCriterion1.setFinalUrls(new UrlList(new String[] {encodedFinalUrl})); BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration(); CpcBid bid = new CpcBid(); bid.setBid(new Money(null, 10000000L)); biddingStrategyConfiguration.setBids(new Bids[] {bid}); keywordBiddableAdGroupCriterion1.setBiddingStrategyConfiguration(biddingStrategyConfiguration); NegativeAdGroupCriterion keywordNegativeAdGroupCriterion2 = new NegativeAdGroupCriterion(); keywordNegativeAdGroupCriterion2.setAdGroupId(adGroupId); keywordNegativeAdGroupCriterion2.setCriterion(keyword2); // Create operations. AdGroupCriterionOperation keywordAdGroupCriterionOperation1 = new AdGroupCriterionOperation(); keywordAdGroupCriterionOperation1.setOperand(keywordBiddableAdGroupCriterion1); keywordAdGroupCriterionOperation1.setOperator(Operator.ADD); AdGroupCriterionOperation keywordAdGroupCriterionOperation2 = new AdGroupCriterionOperation(); keywordAdGroupCriterionOperation2.setOperand(keywordNegativeAdGroupCriterion2); keywordAdGroupCriterionOperation2.setOperator(Operator.ADD); AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] {keywordAdGroupCriterionOperation1, keywordAdGroupCriterionOperation2}; // Add keywords. AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations); // Display results. for (AdGroupCriterion adGroupCriterionResult : result.getValue()) { System.out.printf("Keyword ad group criterion with ad group ID %d, criterion ID %d, " + "text '%s', and match type '%s' was added.%n", adGroupCriterionResult.getAdGroupId(), adGroupCriterionResult.getCriterion().getId(), ((Keyword) adGroupCriterionResult.getCriterion()).getText(), ((Keyword) adGroupCriterionResult.getCriterion()).getMatchType()); } }
Example #30
Source File: IdeaEstimate.java From keyword-optimizer with Apache License 2.0 | 4 votes |
/** * Returns the AVERAGE_CPC attribute from the {@link TargetingIdeaService}. */ public Money getAverageCpc() { return averageCpc; }