/// <summary>
    /// Run the code example.
    /// </summary>
    /// <param name="service">An initialized Dfa Reporting service object
    /// </param>
    public override void Run(DfareportingService service) {
      long campaignId = long.Parse(_T("INSERT_CAMPAIGN_ID_HERE"));
      long dfaSiteId = long.Parse(_T("INSERT_SITE_ID_HERE"));
      long profileId = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

      string placementGroupName = _T("INSERT_PLACEMENT_GROUP_NAME_HERE");

      // Retrieve the campaign.
      Campaign campaign = service.Campaigns.Get(profileId, campaignId).Execute();

      // Create a pricing schedule.
      PricingSchedule pricingSchedule = new PricingSchedule();
      pricingSchedule.EndDate = campaign.EndDate;
      pricingSchedule.PricingType = "PRICING_TYPE_CPM";
      pricingSchedule.StartDate = campaign.StartDate;

      // Create the placement group.
      PlacementGroup placementGroup = new PlacementGroup();
      placementGroup.CampaignId = campaignId;
      placementGroup.Name = placementGroupName;
      placementGroup.PlacementGroupType = "PLACEMENT_PACKAGE";
      placementGroup.PricingSchedule = pricingSchedule;
      placementGroup.SiteId = dfaSiteId;

      // Insert the placement.
      PlacementGroup result =
          service.PlacementGroups.Insert(placementGroup, profileId).Execute();

      // Display the new placement ID.
      Console.WriteLine("Placement group with ID {0} was created.", result.Id);
    }
Пример #2
0
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="service">An initialized Dfa Reporting service object
        /// </param>
        public override void Run(DfareportingService service)
        {
            long campaignId = long.Parse(_T("INSERT_CAMPAIGN_ID_HERE"));
            long dfaSiteId  = long.Parse(_T("INSERT_SITE_ID_HERE"));
            long profileId  = long.Parse(_T("INSERT_USER_PROFILE_ID_HERE"));

            string placementGroupName = _T("INSERT_PLACEMENT_GROUP_NAME_HERE");

            // Retrieve the campaign.
            Campaign campaign = service.Campaigns.Get(profileId, campaignId).Execute();

            // Create a pricing schedule.
            PricingSchedule pricingSchedule = new PricingSchedule();

            pricingSchedule.EndDate     = campaign.EndDate;
            pricingSchedule.PricingType = "PRICING_TYPE_CPM";
            pricingSchedule.StartDate   = campaign.StartDate;

            // Create the placement group.
            PlacementGroup placementGroup = new PlacementGroup();

            placementGroup.CampaignId         = campaignId;
            placementGroup.Name               = placementGroupName;
            placementGroup.PlacementGroupType = "PLACEMENT_PACKAGE";
            placementGroup.PricingSchedule    = pricingSchedule;
            placementGroup.SiteId             = dfaSiteId;

            // Insert the placement.
            PlacementGroup result =
                service.PlacementGroups.Insert(placementGroup, profileId).Execute();

            // Display the new placement ID.
            Console.WriteLine("Placement group with ID {0} was created.", result.Id);
        }
Пример #3
0
    // With rewarded ads, opportunity should be realized (this method should be called) when the ad is proposed. With interstitials - when it is shown.
    // Developer needs to call the event that this method is called upon, when it is appropriate
    public void CallBalancerEvent(string event_id)
    {
        // Get Stuff about the event
        BalancerEvent balancer_event = GetBalancerEvent(event_id);

        // Get the placement group that will be affected by this event
        PlacementGroup affected_placement_group = GetPlacementGroupById(balancer_event.placement_group_id);

        // Change by delta
        affected_placement_group.balance.v += balancer_event.delta;

        if (affected_placement_group.balance.v < affected_placement_group.balance_min)
        {
            affected_placement_group.balance.v = affected_placement_group.balance_min;
        }
        if (affected_placement_group.balance.v > affected_placement_group.balance_max)
        {
            affected_placement_group.balance.v = affected_placement_group.balance_max;
        }

        // Debug.Log("Event. id: " + event_id + " group: " + affected_placement_group.id + " bal: " + affected_placement_group.balance.v);
    }
Пример #4
0
    private OpportunityBalancer GetCurrOpportunityBalancer(PlacementGroup placement_group, int opportunities)
    {
        int test_opportunities = 0;

        for (int i = 0; i < placement_group.opportunity_balancers.Count; i++)
        {
            OpportunityBalancer opportunity_balancer = placement_group.opportunity_balancers[i];
            test_opportunities += opportunity_balancer.opportunities;

            if (opportunities <= test_opportunities)
            {
                return(opportunity_balancer);
            }

            if (i == placement_group.opportunity_balancers.Count - 1)
            {
                return(opportunity_balancer);
            }
        }

        throw new System.Exception("Appropriate Opportunity Balancer is not found! " + name);
    }
Пример #5
0
    private TimeBalancer GetCurrTimeBalancer(PlacementGroup placement_group, float time)
    {
        float test_seconds = 0.0f;

        for (int i = 0; i < placement_group.time_balancers.Count; i++)
        {
            TimeBalancer time_balancer = placement_group.time_balancers[i];
            test_seconds += time_balancer.minutes * 60;

            if (time <= test_seconds)
            {
                return(time_balancer);
            }

            if (i == placement_group.time_balancers.Count - 1)
            {
                return(time_balancer);
            }
        }

        throw new System.Exception("Appropriate Time Balancer is not found! " + name);
    }
Пример #6
0
        /// <summary>
        /// Inserts a new placement group.
        /// Documentation https://developers.google.com/dfareporting/v2.7/reference/placementGroups/insert
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Dfareporting service.</param>
        /// <param name="profileId">User profile ID associated with this request.</param>
        /// <param name="body">A valid Dfareporting v2.7 body.</param>
        /// <returns>PlacementGroupResponse</returns>
        public static PlacementGroup Insert(DfareportingService service, string profileId, PlacementGroup body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (profileId == null)
                {
                    throw new ArgumentNullException(profileId);
                }

                // Make the request.
                return(service.PlacementGroups.Insert(body, profileId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request PlacementGroups.Insert failed.", ex);
            }
        }
Пример #7
0
    public bool CheckOpportunity(string internal_id)
    {
        // Get Stuff about the ad by the internal_id
        AdIds          ad_ids          = GetAdIds(internal_id);
        PlacementGroup placement_group = GetPlacementGroup(internal_id);

        // If No Ads is bought and placement_group is excluded by this purchase
        if (no_ads.v && no_ads_excluded.Contains(placement_group.id))
        {
            return(false);
        }

        // If resurrection ad was already shown this level
        // Debug.Log("Check Opp: " + " internal_id: " + internal_id + " rd_resurrect_shown_count: " + rd_resurrect_shown_count.v + " rd_resurrect_name: " + rd_resurrect_name);
        if (internal_id.Contains(rd_resurrect_name) && rd_resurrect_shown_count.v >= 1)
        {
            return(false);
        }

        if (placement_group.balancer_type == balancer_type_enum.time_balancer)
        {
            // Get current time
            float curr_time = Time.time;

            TimeBalancer time_balancer = GetCurrTimeBalancer(placement_group, Time.time);

            float minutes_since_last_opportunity = (curr_time - placement_group.last_opportunity_timestamp.v) / 60;
            float ad_per_minutes = ((float)time_balancer.ads / (float)time_balancer.minutes);

            placement_group.balance.v += minutes_since_last_opportunity * ad_per_minutes;

            placement_group.last_opportunity_timestamp.v = curr_time;
        }
        else if (placement_group.balancer_type == balancer_type_enum.opportunity_balancer)
        {
            // This counts as an opportunity
            placement_group.opportunities.v++;

            OpportunityBalancer opportunity_balancer = GetCurrOpportunityBalancer(placement_group, placement_group.opportunities.v);
            float ad_per_opportunity = ((float)opportunity_balancer.ads / (float)opportunity_balancer.opportunities);

            // 1 symbolizes one opportunity that is provided with this method
            placement_group.balance.v += 1 * ad_per_opportunity;
        }
        else if (placement_group.balancer_type == balancer_type_enum.always_yes)
        {
            // Just set it to 1
            placement_group.balance.v = 1.0f;
        }
        else if (placement_group.balancer_type == balancer_type_enum.always_no)
        {
            // Just set it to 0
            placement_group.balance.v = 0.0f;
        }

        if (placement_group.balance.v < placement_group.balance_min)
        {
            placement_group.balance.v = placement_group.balance_min;
        }
        if (placement_group.balance.v > placement_group.balance_max)
        {
            placement_group.balance.v = placement_group.balance_max;
        }

        // Debug.Log("id: " + internal_id + " group: " + placement_group.id + " bal: " + placement_group.balance.v);

        if (placement_group.balance.v < 1)
        {
            return(false);
        }

#if UNITY_IOS
        string platform_ad_id = ad_ids.ios_id;
#elif UNITY_ANDROID || UNITY_EDITOR
        string platform_ad_id = ad_ids.android_id;
#endif

        if (!Advertisement.IsReady(platform_ad_id))
        {
            return(false);
        }

        return(true);
    }