private void DidFailToShowAd(AdAgent agent, String reason) { if (agent == interstitialAgent) { SmartAds.Instance.DidFailToOpenInterstitialAd(reason); } else if (agent == rewardedAgent) { SmartAds.Instance.DidFailToOpenRewardedAd(reason); } }
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); }
private bool IsAdAllowed( AdAgent agent, string decisionPoint, JSONObject parameters, bool checkTime) { if (agent == null) { Logger.LogDebug("Ads disabled for this session"); return(false); } if (!string.IsNullOrEmpty(decisionPoint) && parameters == null) { Logger.LogDebug("Ad cannot be shown with an invalid Engagement"); return(false); } else if (string.IsNullOrEmpty(decisionPoint) && parameters == null) { Logger.LogWarning("Using an empty Engagement is deprecated"); return(true); } var allowed = false; switch (Result(agent, decisionPoint, parameters)) { case ShowResult.MIN_TIME_NOT_ELAPSED: case ShowResult.MIN_TIME_DECISION_POINT_NOT_ELAPSED: case ShowResult.NO_AD_AVAILABLE: allowed = !checkTime; break; case ShowResult.FULFILLED: allowed = true; break; } ; return(allowed); }
public void RegisterForAds(JSONObject response, bool userConsent, bool ageRestricted) { var config = response["parameters"] as IDictionary <string, object>; if (!config.ContainsKey("adShowSession") || !(config["adShowSession"] as bool? ?? false)) { SmartAds.Instance.DidFailToRegisterForInterstitialAds( "Ads disabled for this session"); SmartAds.Instance.DidFailToRegisterForRewardedAds( "Ads disabled for this session"); return; } if (!config.ContainsKey("adProviders") && !config.ContainsKey("adRewardedProviders")) { SmartAds.Instance.DidFailToRegisterForInterstitialAds( "Invalid Engage response, missing 'adProviders' key"); SmartAds.Instance.DidFailToRegisterForRewardedAds( "Invalid Engage response, missing 'adRewardedProviders' key"); return; } adMinimumInterval = config.GetOrDefault( "adMinimumInterval", DEFAULT_AD_MINIMUM_INTERVAL); adMaxPerSession = config.GetOrDefault( "adMaxPerSession", DEFAULT_AD_MAX_PER_SESSION); if (!config.ContainsKey("adProviders")) { SmartAds.Instance.DidFailToRegisterForInterstitialAds( "No interstitial ad providers defined"); } else if ((config["adProviders"] as IList <object>).Count == 0) { SmartAds.Instance.DidFailToRegisterForInterstitialAds( "No interstitial ad providers defined"); } else { interstitialAgent = new AdAgent( false, (config["adProviders"] as IList <object>).Count, adMaxPerSession); interstitialAgent.RecordAdShown += ((dp, time) => metrics.RecordAdShown(dp, time)); interstitialAgent.RequestAd(); SmartAds.Instance.DidRegisterForInterstitialAds(); } if (!config.ContainsKey("adRewardedProviders")) { SmartAds.Instance.DidFailToRegisterForRewardedAds( "No rewarded ad providers defined"); } else if ((config["adRewardedProviders"] as IList <object>).Count == 0) { SmartAds.Instance.DidFailToRegisterForRewardedAds( "No rewarded ad providers defined"); } else { rewardedAgent = new AdAgent( true, (config["adRewardedProviders"] as IList <object>).Count, adMaxPerSession); rewardedAgent.RecordAdShown += ((dp, time) => metrics.RecordAdShown(dp, time)); rewardedAgent.RequestAd(); SmartAds.Instance.DidRegisterForRewardedAds(); } }
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); }
public void RegisterForAds(string decisionPoint, bool userConsent, bool ageRestricted) { var engagement = new Engagement(decisionPoint); engagement.Flavour = "internal"; engagement.AddParam("adSdkVersion", Settings.SDK_VERSION); DDNA.Instance.RequestEngagement(engagement, (response) => { if (!response.ContainsKey("parameters")) { SmartAds.Instance.DidFailToRegisterForInterstitialAds( "Invalid Engage response, missing 'parameters' key"); SmartAds.Instance.DidFailToRegisterForRewardedAds( "Invalid Engage response, missing 'parameters' key"); return; } var config = response["parameters"] as IDictionary <string, object>; if (!config.ContainsKey("adShowSession") || !(config["adShowSession"] as bool? ?? false)) { SmartAds.Instance.DidFailToRegisterForInterstitialAds( "Ads disabled for this session"); SmartAds.Instance.DidFailToRegisterForRewardedAds( "Ads disabled for this session"); return; } if (!config.ContainsKey("adProviders") && !config.ContainsKey("adRewardedProviders")) { SmartAds.Instance.DidFailToRegisterForInterstitialAds( "Invalid Engage response, missing 'adProviders' key"); SmartAds.Instance.DidFailToRegisterForRewardedAds( "Invalid Engage response, missing 'adRewardedProviders' key"); return; } adMinimumInterval = (config.ContainsKey("adMinimumInterval")) ? config["adMinimumInterval"] as int? ?? DEFAULT_AD_MINIMUM_INTERVAL : DEFAULT_AD_MINIMUM_INTERVAL; adMaxPerSession = (config.ContainsKey("adMaxPerSession")) ? config["adMaxPerSession"] as int? ?? DEFAULT_AD_MAX_PER_SESSION : DEFAULT_AD_MAX_PER_SESSION; if (!config.ContainsKey("adProviders")) { SmartAds.Instance.DidFailToRegisterForInterstitialAds( "No interstitial ad providers defined"); } else if ((config["adProviders"] as IList <object>).Count == 0) { SmartAds.Instance.DidFailToRegisterForInterstitialAds( "No interstitial ad providers defined"); } else { interstitialAgent = new AdAgent( false, (config["adProviders"] as IList <object>).Count, adMaxPerSession); interstitialAgent.RecordAdShown += ((dp, time) => metrics.RecordAdShown(dp, time)); interstitialAgent.RequestAd(); SmartAds.Instance.DidRegisterForInterstitialAds(); } if (!config.ContainsKey("adRewardedProviders")) { SmartAds.Instance.DidFailToRegisterForRewardedAds( "No rewarded ad providers defined"); } else if ((config["adRewardedProviders"] as IList <object>).Count == 0) { SmartAds.Instance.DidFailToRegisterForRewardedAds( "No rewarded ad providers defined"); } else { rewardedAgent = new AdAgent( true, (config["adRewardedProviders"] as IList <object>).Count, adMaxPerSession); rewardedAgent.RecordAdShown += ((dp, time) => metrics.RecordAdShown(dp, time)); rewardedAgent.RequestAd(); SmartAds.Instance.DidRegisterForRewardedAds(); } }); }