Exemple #1
0
        private void ShowAd(
            AdAgent agent,
            string decisionPoint,
            JSONObject parameters)
        {
            if (!string.IsNullOrEmpty(decisionPoint) && parameters == null)
            {
                DidFailToShowAd(agent, "Invalid engagement");
                return;
            }
            else if (string.IsNullOrEmpty(decisionPoint) && parameters == null)
            {
                Logger.LogWarning("Prefer showing ads with Engagements");
            }

            agent.SetAdPoint(decisionPoint);

            switch (Result(agent, decisionPoint, parameters))
            {
            case ShowResult.AD_SHOW_POINT:
                DidFailToShowAd(agent, "Engage disallowed the ad");
                return;

            case ShowResult.SESSION_LIMIT_REACHED:
                DidFailToShowAd(agent, "Session limit for environment reached");
                return;

            case ShowResult.SESSION_DECISION_POINT_LIMIT_REACHED:
                DidFailToShowAd(agent, "Session limit for decision point reached");
                return;

            case ShowResult.DAILY_DECISION_POINT_LIMIT_REACHED:
                DidFailToShowAd(agent, "Daily limit for decision point reached");
                return;

            case ShowResult.MIN_TIME_NOT_ELAPSED:
                DidFailToShowAd(agent, "Minimum environment time between ads not elapsed");
                return;

            case ShowResult.MIN_TIME_DECISION_POINT_NOT_ELAPSED:
                DidFailToShowAd(agent, "Minimum decision point time between ads not elapsed");
                return;
            }

            if (!agent.IsAdLoaded())
            {
                DidFailToShowAd(agent, "Ad not loaded");
                return;
            }

            agent.ShowAd(decisionPoint);
        }
Exemple #2
0
        private ShowResult Result(AdAgent agent, string decisionPoint, JSONObject parameters)
        {
            if (parameters != null &&
                !(parameters["adShowPoint"] as bool? ?? DEFAULT_AD_SHOW_POINT))
            {
                return(ShowResult.AD_SHOW_POINT);
            }

            if (adMaxPerSession != -1 && agent.shownCount >= adMaxPerSession)
            {
                return(ShowResult.SESSION_LIMIT_REACHED);
            }

            if (!string.IsNullOrEmpty(decisionPoint) &&
                parameters != null &&
                parameters.ContainsKey("ddnaAdSessionCount"))
            {
                var value = parameters["ddnaAdSessionCount"] as long? ?? 0;
                if (metrics.SessionCount(decisionPoint) >= value)
                {
                    return(ShowResult.SESSION_DECISION_POINT_LIMIT_REACHED);
                }
            }

            if (!string.IsNullOrEmpty(decisionPoint) &&
                parameters != null &&
                parameters.ContainsKey("ddnaAdDailyCount"))
            {
                var value = parameters["ddnaAdDailyCount"] as long? ?? 0;
                if (metrics.DailyCount(decisionPoint) >= value)
                {
                    return(ShowResult.DAILY_DECISION_POINT_LIMIT_REACHED);
                }
            }

            var now = DateTime.UtcNow;

            if (now.Subtract(agent.lastShowTime).Seconds < adMinimumInterval)
            {
                return(ShowResult.MIN_TIME_NOT_ELAPSED);
            }

            if (!string.IsNullOrEmpty(decisionPoint) &&
                parameters != null &&
                parameters.ContainsKey("ddnaAdShowWaitSecs"))
            {
                var wait      = parameters["ddnaAdShowWaitSecs"] as long? ?? 0;
                var lastShown = metrics.LastShown(decisionPoint);
                if (lastShown.HasValue &&
                    now.Subtract(lastShown.Value).Seconds < wait)
                {
                    return(ShowResult.MIN_TIME_DECISION_POINT_NOT_ELAPSED);
                }
            }

            if (!agent.IsAdLoaded())
            {
                return(ShowResult.NO_AD_AVAILABLE);
            }

            return(ShowResult.FULFILLED);
        }
Exemple #3
0
 public bool HasLoadedRewardedAd()
 {
     return(rewardedAgent != null && rewardedAgent.IsAdLoaded());
 }
Exemple #4
0
 public bool HasLoadedInterstitialAd()
 {
     return(interstitialAgent != null && interstitialAgent.IsAdLoaded());
 }