/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">Id of the ad group for which keyword bid /// simulations are retrieved.</param> /// <param name="keywordId">Id of the keyword for which bid simulations are /// retrieved.</param> public void Run(AdWordsUser user, long adGroupId, long keywordId) { using (DataService dataService = (DataService)user.GetService( AdWordsService.v201802.DataService)) { // Create the query. SelectQuery query = new SelectQueryBuilder().Select( CriterionBidLandscape.Fields.AdGroupId, CriterionBidLandscape.Fields.CriterionId, CriterionBidLandscape.Fields.StartDate, CriterionBidLandscape.Fields.EndDate, BidLandscapeLandscapePoint.Fields.Bid, BidLandscapeLandscapePoint.Fields.LocalClicks, BidLandscapeLandscapePoint.Fields.LocalCost, BidLandscapeLandscapePoint.Fields.LocalImpressions, BidLandscapeLandscapePoint.Fields.BiddableConversions, BidLandscapeLandscapePoint.Fields.BiddableConversionsValue ) .Where(CriterionBidLandscape.Fields.AdGroupId).Equals(adGroupId) .Where(CriterionBidLandscape.Fields.CriterionId).Equals(keywordId) .DefaultLimit() .Build(); CriterionBidLandscapePage page = new CriterionBidLandscapePage(); int landscapePointsFound = 0; try { do { // Get bid landscape for keywords. page = dataService.queryCriterionBidLandscape(query); // Display bid landscapes. if (page != null && page.entries != null) { foreach (CriterionBidLandscape bidLandscape in page.entries) { Console.WriteLine("Found criterion bid landscape with ad group id '{0}', " + "keyword id '{1}', start date '{2}', end date '{3}', and landscape points:", bidLandscape.adGroupId, bidLandscape.criterionId, bidLandscape.startDate, bidLandscape.endDate); foreach (BidLandscapeLandscapePoint bidLandscapePoint in bidLandscape.landscapePoints) { Console.WriteLine("- bid: {0} => clicks: {1}, cost: {2}, impressions: {3}, " + "biddable conversions: {4:0.00}, biddable conversions value:{5:0.00}", bidLandscapePoint.bid.microAmount, bidLandscapePoint.clicks, bidLandscapePoint.cost.microAmount, bidLandscapePoint.impressions, bidLandscapePoint.biddableConversions, bidLandscapePoint.biddableConversionsValue); landscapePointsFound++; } } } query.NextPage(page); } while (query.HasNextPage(page)); Console.WriteLine("Number of keyword bid landscape points found: {0}", landscapePointsFound); } catch (Exception e) { throw new System.ApplicationException("Failed to retrieve keyword bid landscapes.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">Id of the ad group for which keyword bid /// simulations are retrieved.</param> /// <param name="keywordId">Id of the keyword for which bid simulations are /// retrieved.</param> public void Run(AdWordsUser user, long adGroupId, long keywordId) { // Get the DataService. DataService dataService = (DataService) user.GetService(AdWordsService.v201509.DataService); // Create the selector. Selector selector = new Selector() { fields = new string[] { CriterionBidLandscape.Fields.AdGroupId, CriterionBidLandscape.Fields.CriterionId, CriterionBidLandscape.Fields.StartDate, CriterionBidLandscape.Fields.EndDate, BidLandscapeLandscapePoint.Fields.Bid, BidLandscapeLandscapePoint.Fields.LocalClicks, BidLandscapeLandscapePoint.Fields.LocalCost, BidLandscapeLandscapePoint.Fields.LocalImpressions }, predicates = new Predicate[] { Predicate.Equals(CriterionBidLandscape.Fields.AdGroupId, adGroupId), Predicate.Equals(CriterionBidLandscape.Fields.CriterionId, keywordId) }, paging = Paging.Default }; CriterionBidLandscapePage page = new CriterionBidLandscapePage(); int bidLandscapeCount = 0; int landscapePointsInLastResponse = 0; try { do { // Get bid landscape for keywords. page = dataService.getCriterionBidLandscape(selector); landscapePointsInLastResponse = 0; // Display bid landscapes. if (page != null && page.entries != null) { foreach (CriterionBidLandscape bidLandscape in page.entries) { Console.WriteLine("{0}) Found criterion bid landscape with ad group id '{1}', " + "keyword id '{2}', start date '{3}', end date '{4}', and landscape points:", bidLandscapeCount + 1, bidLandscape.adGroupId, bidLandscape.criterionId, bidLandscape.startDate, bidLandscape.endDate); foreach (BidLandscapeLandscapePoint bidLandscapePoint in bidLandscape.landscapePoints) { Console.WriteLine("- bid: {0} => clicks: {1}, cost: {2}, impressions: {3}\n", bidLandscapePoint.bid.microAmount, bidLandscapePoint.clicks, bidLandscapePoint.cost.microAmount, bidLandscapePoint.impressions); landscapePointsInLastResponse++; } bidLandscapeCount++; } } // Offset by the number of landscape points, NOT the number // of entries (bid landscapes) in the last response. selector.paging.IncreaseOffsetBy(landscapePointsInLastResponse); } while (landscapePointsInLastResponse > 0 && landscapePointsInLastResponse < selector.paging.numberResults); Console.WriteLine("Number of keyword bid landscapes found: {0}", bidLandscapeCount); } catch (Exception e) { throw new System.ApplicationException("Failed to retrieve keyword bid landscapes.", e); } }
/// <summary> /// Gets the total landscape points in the criterion bid landscape page. If the page has a null /// <code>entries</code> array, returns <code>0</code>. /// </summary> /// <param name="page">The criterion bid landscape page.</param> /// <returns>The total landscape points.</returns> private int GetTotalLandscapePointsInPage(CriterionBidLandscapePage page) { if (page.entries == null) { return(0); } int totalLandscapePointsInPage = 0; foreach (CriterionBidLandscape criterionBidLandscape in page.entries) { totalLandscapePointsInPage += criterionBidLandscape.landscapePoints.Length; } return(totalLandscapePointsInPage); }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">Id of the ad group for which keyword bid /// simulations are retrieved.</param> /// <param name="keywordId">Id of the keyword for which bid simulations are /// retrieved.</param> public void Run(AdWordsUser user, long adGroupId, long keywordId) { using (DataService dataService = (DataService)user.GetService( AdWordsService.v201705.DataService)) { // Create the selector. Selector selector = new Selector() { fields = new string[] { CriterionBidLandscape.Fields.AdGroupId, CriterionBidLandscape.Fields.CriterionId, CriterionBidLandscape.Fields.StartDate, CriterionBidLandscape.Fields.EndDate, BidLandscapeLandscapePoint.Fields.Bid, BidLandscapeLandscapePoint.Fields.LocalClicks, BidLandscapeLandscapePoint.Fields.LocalCost, BidLandscapeLandscapePoint.Fields.LocalImpressions }, predicates = new Predicate[] { Predicate.Equals(CriterionBidLandscape.Fields.AdGroupId, adGroupId), Predicate.Equals(CriterionBidLandscape.Fields.CriterionId, keywordId) }, paging = Paging.Default }; CriterionBidLandscapePage page = new CriterionBidLandscapePage(); int landscapePointsFound = 0; int landscapePointsInLastResponse = 0; try { do { // Get bid landscape for keywords. page = dataService.getCriterionBidLandscape(selector); landscapePointsInLastResponse = 0; // Display bid landscapes. if (page != null && page.entries != null) { foreach (CriterionBidLandscape bidLandscape in page.entries) { Console.WriteLine("Found criterion bid landscape with ad group id '{0}', " + "keyword id '{1}', start date '{2}', end date '{3}', and landscape points:", bidLandscape.adGroupId, bidLandscape.criterionId, bidLandscape.startDate, bidLandscape.endDate); foreach (BidLandscapeLandscapePoint bidLandscapePoint in bidLandscape.landscapePoints) { Console.WriteLine("- bid: {0} => clicks: {1}, cost: {2}, impressions: {3}\n", bidLandscapePoint.bid.microAmount, bidLandscapePoint.clicks, bidLandscapePoint.cost.microAmount, bidLandscapePoint.impressions); landscapePointsInLastResponse++; landscapePointsFound++; } } } // Offset by the number of landscape points, NOT the number // of entries (bid landscapes) in the last response. selector.paging.IncreaseOffsetBy(landscapePointsInLastResponse); } while (landscapePointsInLastResponse > 0); Console.WriteLine("Number of keyword bid landscape points found: {0}", landscapePointsFound); } catch (Exception e) { throw new System.ApplicationException("Failed to retrieve keyword bid landscapes.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="campaignId">Id of the campaign for which bid simulations are /// retrieved.</param> public void Run(AdWordsUser user, long campaignId) { using (DataService dataService = (DataService)user.GetService( AdWordsService.v201806.DataService)) { // Create selector. Selector selector = new Selector() { fields = new string[] { CriterionBidLandscape.Fields.CampaignId, CriterionBidLandscape.Fields.CriterionId, CriterionBidLandscape.Fields.StartDate, CriterionBidLandscape.Fields.EndDate, BidLandscapeLandscapePoint.Fields.LocalClicks, BidLandscapeLandscapePoint.Fields.LocalCost, BidLandscapeLandscapePoint.Fields.LocalImpressions, BidLandscapeLandscapePoint.Fields.TotalLocalClicks, BidLandscapeLandscapePoint.Fields.TotalLocalCost, BidLandscapeLandscapePoint.Fields.TotalLocalImpressions, BidLandscapeLandscapePoint.Fields.RequiredBudget, BidLandscapeLandscapePoint.Fields.BidModifier, }, predicates = new Predicate[] { Predicate.Equals(CriterionBidLandscape.Fields.CampaignId, campaignId) }, paging = Paging.Default }; int landscapePointsInLastResponse = 0; int landscapePointsFound = 0; try { CriterionBidLandscapePage page = null; do { // When retrieving bid landscape, page.totalNumEntities cannot be used to determine // if there are more entries, since it shows only the total number of bid landscapes // and not the number of bid landscape points. So you need to iterate until you no // longer get back any bid landscapes. // Get bid landscape for campaign. page = dataService.getCampaignCriterionBidLandscape(selector); landscapePointsInLastResponse = 0; if (page != null && page.entries != null) { foreach (CriterionBidLandscape bidLandscape in page.entries) { Console.WriteLine("Found campaign-level criterion bid modifier landscapes for" + " criterion with ID {0}, start date '{1}', end date '{2}', and" + " landscape points:", bidLandscape.criterionId, bidLandscape.startDate, bidLandscape.endDate ); foreach (BidLandscapeLandscapePoint point in bidLandscape.landscapePoints) { Console.WriteLine("- bid modifier: {0:0.00} => clicks: {1}, cost: {2}, " + "impressions: {3}, total clicks: {4}, total cost: {5}, " + "total impressions: {6}, and required budget: {7}", point.bidModifier, point.clicks, point.cost.microAmount, point.impressions, point.totalLocalClicks, point.totalLocalCost.microAmount, point.totalLocalImpressions, point.requiredBudget.microAmount); landscapePointsInLastResponse++; landscapePointsFound++; } } } // Offset by the number of landscape points, NOT the number // of entries (bid landscapes) in the last response. selector.paging.IncreaseOffsetBy(landscapePointsInLastResponse); } while (landscapePointsInLastResponse > 0); Console.WriteLine("Number of bid landscape points found: {0}", landscapePointsFound); } catch (Exception e) { throw new System.ApplicationException("Failed to get campaign bid landscapes.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> /// <param name="adGroupId">Id of the ad group for which keyword bid /// simulations are retrieved.</param> /// <param name="keywordId">Id of the keyword for which bid simulations are /// retrieved.</param> public void Run(AdWordsUser user, long adGroupId, long keywordId) { // Get the DataService. DataService dataService = (DataService)user.GetService(AdWordsService.v201409.DataService); // Create the selector. Selector selector = new Selector(); selector.fields = new string[] { "AdGroupId", "CriterionId", "StartDate", "EndDate", "Bid", "LocalClicks", "LocalCost", "MarginalCpc", "LocalImpressions" }; // Create the filters. Predicate adGroupPredicate = new Predicate(); adGroupPredicate.field = "AdGroupId"; adGroupPredicate.@operator = PredicateOperator.IN; adGroupPredicate.values = new string[] { adGroupId.ToString() }; Predicate keywordPredicate = new Predicate(); keywordPredicate.field = "CriterionId"; keywordPredicate.@operator = PredicateOperator.IN; keywordPredicate.values = new string[] { keywordId.ToString() }; selector.predicates = new Predicate[] { adGroupPredicate, keywordPredicate }; // Set selector paging. selector.paging = new Paging(); int offset = 0; int pageSize = 500; CriterionBidLandscapePage page = new CriterionBidLandscapePage(); try { do { selector.paging.startIndex = offset; selector.paging.numberResults = pageSize; // Get bid landscape for keywords. page = dataService.getCriterionBidLandscape(selector); // Display bid landscapes. if (page != null && page.entries != null) { int i = offset; foreach (CriterionBidLandscape bidLandscape in page.entries) { Console.WriteLine("{0}) Found criterion bid landscape with ad group id '{1}', " + "keyword id '{2}', start date '{3}', end date '{4}', and landscape points:", i, bidLandscape.adGroupId, bidLandscape.criterionId, bidLandscape.startDate, bidLandscape.endDate); foreach (BidLandscapeLandscapePoint bidLandscapePoint in bidLandscape.landscapePoints) { Console.WriteLine("- bid: {0} => clicks: {1}, cost: {2}, marginalCpc: {3}, " + "impressions: {4}\n", bidLandscapePoint.bid.microAmount, bidLandscapePoint.clicks, bidLandscapePoint.cost.microAmount, bidLandscapePoint.marginalCpc.microAmount, bidLandscapePoint.impressions); } i++; } } offset += pageSize; } while (offset < page.totalNumEntries); Console.WriteLine("Number of keyword bid landscapes found: {0}", page.totalNumEntries); } catch (Exception ex) { throw new System.ApplicationException("Failed to retrieve keyword bid landscapes.", ex); } }
public void TestHasNextPage() { SelectQueryBuilder queryBuilder = null; SelectQuery query = null; queryBuilder = new SelectQueryBuilder(); query = queryBuilder .Select("CampaignId", "Status", "Clicks", "Impressions") .Where("Clicks").Equals(20) .OrderByAscending("CampaignId") .OrderByDescending("Status") .Build(); // Tests for regular pages. CampaignPage campaignPage = new CampaignPage(); // Start index is less than total number of entries. query.Limit(1, 20); campaignPage.totalNumEntries = 15; Assert.IsTrue(query.HasNextPage(campaignPage)); // Start index is greater than total number of entries. query.Limit(18, 20); campaignPage.totalNumEntries = 15; Assert.IsFalse(query.HasNextPage(campaignPage)); // Tests for AdGroupBidLandscapePage. AdGroupBidLandscapePage adGroupBidLandscapePage = new AdGroupBidLandscapePage(); adGroupBidLandscapePage.entries = new AdGroupBidLandscape[] { new AdGroupBidLandscape() { campaignId = 123, adGroupId = 456, landscapePoints = new BidLandscapeLandscapePoint[] { new BidLandscapeLandscapePoint() { clicks = 10, impressions = 200 }, new BidLandscapeLandscapePoint() { clicks = 12, impressions = 232 }, } }, new AdGroupBidLandscape() { campaignId = 125, adGroupId = 454, landscapePoints = new BidLandscapeLandscapePoint[] { new BidLandscapeLandscapePoint() { clicks = 10, impressions = 200 }, new BidLandscapeLandscapePoint() { clicks = 5, impressions = 232 }, new BidLandscapeLandscapePoint() { clicks = 66, impressions = 550 }, } } }; // Start index is less than total number of landscape points (5). query.Limit(1, 20); Assert.IsTrue(query.HasNextPage(adGroupBidLandscapePage)); adGroupBidLandscapePage.entries = new AdGroupBidLandscape[] { new AdGroupBidLandscape() { campaignId = 123, adGroupId = 456, landscapePoints = new BidLandscapeLandscapePoint[] {} }, new AdGroupBidLandscape() { campaignId = 125, adGroupId = 454, landscapePoints = null } }; // Start index is less than total number of landscape points (0). query.Limit(1, 20); Assert.IsFalse(query.HasNextPage(adGroupBidLandscapePage)); // Tests for CriterionBidLandscapePage. CriterionBidLandscapePage criterionBidLandscapePage = new CriterionBidLandscapePage() { entries = new CriterionBidLandscape[] { new CriterionBidLandscape() { campaignId = 125, adGroupId = 454, landscapePoints = new BidLandscapeLandscapePoint[] { new BidLandscapeLandscapePoint() { clicks = 10, impressions = 200 }, new BidLandscapeLandscapePoint() { clicks = 5, impressions = 232 }, new BidLandscapeLandscapePoint() { clicks = 66, impressions = 550 }, } }, new CriterionBidLandscape() { campaignId = 125, adGroupId = 454, landscapePoints = new BidLandscapeLandscapePoint[] { new BidLandscapeLandscapePoint() { clicks = 10, impressions = 200 }, new BidLandscapeLandscapePoint() { clicks = 5, impressions = 232 }, new BidLandscapeLandscapePoint() { clicks = 66, impressions = 550 }, } } } }; // Start index is less than total number of landscape points (5). query.Limit(1, 20); Assert.IsTrue(query.HasNextPage(criterionBidLandscapePage)); // Start index is less than total number of landscape points (0). criterionBidLandscapePage.entries = new CriterionBidLandscape[] { new CriterionBidLandscape() { campaignId = 123, adGroupId = 456, landscapePoints = new BidLandscapeLandscapePoint[] {} }, new CriterionBidLandscape() { campaignId = 125, adGroupId = 454, landscapePoints = null } }; query.Limit(1, 20); Assert.IsFalse(query.HasNextPage(criterionBidLandscapePage)); }
public void TestNextPage() { SelectQueryBuilder queryBuilder = null; SelectQuery query = null; queryBuilder = new SelectQueryBuilder(); query = queryBuilder .Select("CampaignId", "Status", "Clicks", "Impressions") .Where("Clicks").Equals(20) .OrderByAscending("CampaignId") .OrderByDescending("Status") .Build(); // Test for regular pages. CampaignPage campaignPage = new CampaignPage(); // Query limits should increment by numberResults (20). query.Limit(1, 20); query.NextPage(campaignPage); Assert.IsTrue(query.ToString().Contains("LIMIT 21, 20")); // Test for AdGroupBidLandscapePage. AdGroupBidLandscapePage adGroupBidLandscapePage = new AdGroupBidLandscapePage(); adGroupBidLandscapePage.entries = new AdGroupBidLandscape[] { new AdGroupBidLandscape() { campaignId = 123, adGroupId = 456, landscapePoints = new BidLandscapeLandscapePoint[] { new BidLandscapeLandscapePoint() { clicks = 10, impressions = 200 }, new BidLandscapeLandscapePoint() { clicks = 12, impressions = 232 }, } }, new AdGroupBidLandscape() { campaignId = 125, adGroupId = 454, landscapePoints = new BidLandscapeLandscapePoint[] { new BidLandscapeLandscapePoint() { clicks = 10, impressions = 200 }, new BidLandscapeLandscapePoint() { clicks = 5, impressions = 232 }, new BidLandscapeLandscapePoint() { clicks = 66, impressions = 550 }, } } }; // Query limits should increment by total landscapePoints (5). query.Limit(1, 20); query.NextPage(adGroupBidLandscapePage); Assert.IsTrue(query.ToString().Contains("LIMIT 6, 20")); // Query limits should increment by total landscapePoints (0). adGroupBidLandscapePage.entries = new AdGroupBidLandscape[] { new AdGroupBidLandscape() { campaignId = 123, adGroupId = 456, landscapePoints = new BidLandscapeLandscapePoint[] {} }, new AdGroupBidLandscape() { campaignId = 125, adGroupId = 454, landscapePoints = null } }; query.Limit(1, 20); query.NextPage(adGroupBidLandscapePage); Assert.IsTrue(query.ToString().Contains("LIMIT 1, 20")); CriterionBidLandscapePage criterionBidLandscapePage = new CriterionBidLandscapePage() { entries = new CriterionBidLandscape[] { new CriterionBidLandscape() { campaignId = 125, adGroupId = 454, landscapePoints = new BidLandscapeLandscapePoint[] { new BidLandscapeLandscapePoint() { clicks = 10, impressions = 200 }, new BidLandscapeLandscapePoint() { clicks = 5, impressions = 232 }, new BidLandscapeLandscapePoint() { clicks = 66, impressions = 550 }, } }, new CriterionBidLandscape() { campaignId = 125, adGroupId = 454, landscapePoints = new BidLandscapeLandscapePoint[] { new BidLandscapeLandscapePoint() { clicks = 10, impressions = 200 }, new BidLandscapeLandscapePoint() { clicks = 5, impressions = 232 }, new BidLandscapeLandscapePoint() { clicks = 66, impressions = 550 }, } } } }; // Query limits should increment by total landscapePoints (6). query.Limit(1, 20); query.NextPage(criterionBidLandscapePage); Assert.IsTrue(query.ToString().Contains("LIMIT 7, 20")); // Query limits should increment by total landscapePoints (0). criterionBidLandscapePage.entries = new CriterionBidLandscape[] { new CriterionBidLandscape() { campaignId = 123, adGroupId = 456, landscapePoints = new BidLandscapeLandscapePoint[] {} }, new CriterionBidLandscape() { campaignId = 125, adGroupId = 454, landscapePoints = null } }; query.Limit(1, 20); query.NextPage(criterionBidLandscapePage); Assert.IsTrue(query.ToString().Contains("LIMIT 1, 20")); }