Пример #1
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(AdManagerUser user)
        {
            using (AdjustmentService adjustmentService = user.GetService <AdjustmentService>())
            {
                // Set the ID of the adjustment to update.
                long adjustmentId = long.Parse(_T("INSERT_ADJUSTMENT_ID_HERE"));

                // Create a statement to select adjustments.
                StatementBuilder statementBuilder =
                    new StatementBuilder()
                    .Where("id = :id")
                    .OrderBy("id ASC")
                    .Limit(1)
                    .AddValue("id", adjustmentId);

                TrafficForecastAdjustmentPage page = adjustmentService
                                                     .getTrafficAdjustmentsByStatement(statementBuilder.ToStatement());

                TrafficForecastAdjustment adjustment = page.results[0];

                // Create a new historical adjustment segment for New Years Day.
                TrafficForecastAdjustmentSegment segment = new TrafficForecastAdjustmentSegment()
                {
                    basisType            = BasisType.HISTORICAL,
                    historicalAdjustment = new HistoricalAdjustment()
                    {
                        referenceDateRange = new DateRange()
                        {
                            startDate = new Date()
                            {
                                year  = System.DateTime.Now.Year,
                                month = 1,
                                day   = 1
                            },
                            endDate = new Date()
                            {
                                year  = System.DateTime.Now.Year,
                                month = 1,
                                day   = 1
                            }
                        },
                        targetDateRange = new DateRange()
                        {
                            startDate = new Date()
                            {
                                year  = System.DateTime.Now.Year + 1,
                                month = 1,
                                day   = 1
                            },
                            endDate = new Date()
                            {
                                year  = System.DateTime.Now.Year + 1,
                                month = 1,
                                day   = 1
                            }
                        },
                        milliPercentMultiplier = 110_000L
                    }
                };

                // Add the new historical segment to the adjustment.
                adjustment.forecastAdjustmentSegments = adjustment.forecastAdjustmentSegments
                                                        .Concat(new TrafficForecastAdjustmentSegment[] { segment }).ToArray();

                TrafficForecastAdjustment[] adjustments =
                    adjustmentService.updateTrafficAdjustments(
                        new TrafficForecastAdjustment[] { adjustment });

                foreach (TrafficForecastAdjustment updatedAdjustment in adjustments)
                {
                    Console.WriteLine("Adjustment with ID {0} and {1} segments was found.",
                                      updatedAdjustment.id,
                                      updatedAdjustment.forecastAdjustmentSegments.Length);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        public void Run(AdManagerUser user)
        {
            using (AdjustmentService adjustmentService = user.GetService <AdjustmentService>())
                using (NetworkService networkService = user.GetService <NetworkService>())
                {
                    String rootAdUnitId = networkService.getCurrentNetwork().effectiveRootAdUnitId;

                    TrafficTimeSeriesFilterCriteria criteria = new TrafficTimeSeriesFilterCriteria()
                    {
                        // Target all USA traffic.
                        targeting = new Targeting()
                        {
                            inventoryTargeting = new InventoryTargeting()
                            {
                                targetedAdUnits = new AdUnitTargeting[] {
                                    new AdUnitTargeting()
                                    {
                                        adUnitId           = rootAdUnitId,
                                        includeDescendants = true
                                    }
                                }
                            },
                            geoTargeting = new GeoTargeting()
                            {
                                targetedLocations = new Location[] {
                                    new Location()
                                    {
                                        id = 2840 // United States
                                    }
                                }
                            }
                        },
                        // Adjust only 1920x1080 video traffic.
                        adUnitSizes = new AdUnitSize[] {
                            new AdUnitSize()
                            {
                                size = new Size()
                                {
                                    width  = 1920,
                                    height = 1080
                                },
                                environmentType = EnvironmentType.VIDEO_PLAYER
                            }
                        }
                    };

                    // Create a new historical adjustment targeting next year's January with
                    // 105% of this year's January.
                    var januarySegment = new TrafficForecastAdjustmentSegment()
                    {
                        basisType            = BasisType.HISTORICAL,
                        historicalAdjustment = new HistoricalAdjustment()
                        {
                            referenceDateRange = new DateRange()
                            {
                                startDate = new Date()
                                {
                                    year  = System.DateTime.Now.Year,
                                    month = 1,
                                    day   = 1
                                },
                                endDate = new Date()
                                {
                                    year  = System.DateTime.Now.Year,
                                    month = 1,
                                    day   = 30
                                }
                            },
                            targetDateRange = new DateRange()
                            {
                                startDate = new Date()
                                {
                                    year  = System.DateTime.Now.Year + 1,
                                    month = 1,
                                    day   = 30
                                },
                                endDate = new Date()
                                {
                                    year  = new System.DateTime().Year + 1,
                                    month = 1,
                                    day   = 30
                                }
                            },
                            milliPercentMultiplier = 105_000L
                        }
                    };

                    // Create a new absolute adjustment of 500,000 ad opportunities for Christmas
                    // and 1M ad opportunities for boxing day.
                    var holidaySegment = new TrafficForecastAdjustmentSegment()
                    {
                        basisType            = BasisType.ABSOLUTE,
                        adjustmentTimeSeries = new TimeSeries()
                        {
                            timeSeriesDateRange = new DateRange()
                            {
                                startDate = new Date()
                                {
                                    year  = System.DateTime.Now.Year,
                                    month = 12,
                                    day   = 24
                                },
                                endDate = new Date()
                                {
                                    year  = System.DateTime.Now.Year,
                                    month = 12,
                                    day   = 25
                                }
                            },
                            valuePeriodType  = PeriodType.DAILY,
                            timeSeriesValues = new long[] { 500_000, 1_000_000 }
                        }
                    };

                    // Create a new absolute adjustment of 900,000 ad opportunities for the first
                    // week in September.
                    var septemberSegment = new TrafficForecastAdjustmentSegment()
                    {
                        basisType            = BasisType.ABSOLUTE,
                        adjustmentTimeSeries = new TimeSeries()
                        {
                            timeSeriesDateRange = new DateRange()
                            {
                                startDate = new Date()
                                {
                                    year  = System.DateTime.Now.Year + 1,
                                    month = 9,
                                    day   = 1
                                },
                                endDate = new Date()
                                {
                                    year  = System.DateTime.Now.Year + 1,
                                    month = 9,
                                    day   = 7
                                }
                            },
                            valuePeriodType  = PeriodType.CUSTOM,
                            timeSeriesValues = new long[] { 900_000 }
                        }
                    };


                    TrafficForecastAdjustment adjustment = new TrafficForecastAdjustment()
                    {
                        filterCriteria             = criteria,
                        forecastAdjustmentSegments = new TrafficForecastAdjustmentSegment[] {
                            januarySegment, holidaySegment, septemberSegment
                        }
                    };

                    TrafficForecastAdjustment[] adjustments =
                        adjustmentService.updateTrafficAdjustments(
                            new TrafficForecastAdjustment[] { adjustment });

                    foreach (TrafficForecastAdjustment updatedAdjustment in adjustments)
                    {
                        Console.WriteLine("Adjustment with ID {0} and {1} segments was "
                                          + "created or updated.",
                                          updatedAdjustment.id,
                                          updatedAdjustment.forecastAdjustmentSegments.Length);
                    }
                }
        }