public void EmitRewardedVideoReceivedRewardEvent(string argsJson) { var args = MoPubUtils.DecodeArgs(argsJson, min: 3); var adUnitId = args[0]; var label = args[1]; var amount = args[2]; float parsedAmount; var parseSucceeded = float.TryParse(amount, NumberStyles.Float, CultureInfo.InvariantCulture, out parsedAmount); MoPubLog.Log("EmitRewardedVideoReceivedRewardEvent", MoPubLog.AdLogEvent.ShouldReward, label, amount); if (!parseSucceeded) { EmitRewardedVideoFailedEvent(MoPubUtils.EncodeArgs(adUnitId, "Failed to parse RewardedVideoReceivedRewardEvent due to invalid rewarded amount: (" + amount + ")." + " Please ensure the reward info is configured properly on your advertising dashboard.")); return; } var evt = OnRewardedVideoReceivedRewardEvent; if (evt != null) { evt(adUnitId, label, parsedAmount); } }
private static void TestEmitRewardedVideoReceivedRewardEvent(string adUnitId, string label, object amount, bool shouldFail = false) { const string successMessage = "OnRewardedVideoReceivedRewardEvent triggered."; Action <string, string, float> successHandler = (_adUnitId, _label, _amount) => { Assert.That(_adUnitId, Is.EqualTo(adUnitId)); Assert.That(_label, Is.EqualTo(label)); Assert.That(_amount, Is.EqualTo(amount)); Debug.Log(successMessage); }; const string failureMessage = "OnRewardedVideoFailedEvent triggered."; Action <string, string> failureHandler = (_adUnitId, _error) => { Assert.That(_adUnitId, Is.EqualTo(adUnitId)); Debug.Log(failureMessage); }; MoPubManager.OnRewardedVideoReceivedRewardEvent += successHandler; MoPubManager.OnRewardedVideoFailedEvent += failureHandler; try { var mpm = new MoPubManager(); mpm.EmitRewardedVideoReceivedRewardEvent(MoPubUtils.EncodeArgs(adUnitId, label, amount.ToString())); LogAssert.Expect(LogType.Log, shouldFail ? failureMessage : successMessage); } finally { MoPubManager.OnRewardedVideoReceivedRewardEvent -= successHandler; MoPubManager.OnRewardedVideoFailedEvent -= failureHandler; } }
// Banner Listeners public void EmitAdLoadedEvent(string argsJson) { var args = MoPubUtils.DecodeArgs(argsJson, min: 3); var adUnitId = args[0]; var width = args[1]; var height = args[2]; float parsedHeight; var parseSucceeded = float.TryParse(height, NumberStyles.Float, CultureInfo.InvariantCulture, out parsedHeight); MoPubLog.Log("EmitAdLoadedEvent", MoPubLog.AdLogEvent.LoadSuccess); MoPubLog.Log("EmitAdLoadedEvent", "Size received: {0}x{1}", width, height); MoPubLog.Log("EmitAdLoadedEvent", MoPubLog.AdLogEvent.ShowSuccess); if (!parseSucceeded) { EmitAdFailedEvent(MoPubUtils.EncodeArgs(adUnitId, "Failed to parse AdLoadedEvent due to invalid ad " + "height: (" + height + ")")); return; } var evt = OnAdLoadedEvent; if (evt != null) { evt(adUnitId, parsedHeight); } }
private static void TestEmitAdLoadedEvent(string adUnitId, object width, object height, bool shouldFail = false) { const string successMessage = "OnAdLoadedEvent triggered."; Action <string, float> successHandler = (_adUnitId, _height) => { Assert.That(_adUnitId, Is.EqualTo(adUnitId)); Assert.That(_height, Is.EqualTo(height)); Debug.Log(successMessage); }; const string failureMessage = "OnAdFailedEvent triggered."; Action <string, string> failureHandler = (_adUnitId, _error) => { Assert.That(_adUnitId, Is.EqualTo(adUnitId)); Debug.Log(failureMessage); }; MoPubManager.OnAdLoadedEvent += successHandler; MoPubManager.OnAdFailedEvent += failureHandler; try { var mpm = new MoPubManager(); mpm.EmitAdLoadedEvent(MoPubUtils.EncodeArgs(adUnitId, width.ToString(), height.ToString())); LogAssert.Expect(LogType.Log, shouldFail ? failureMessage : successMessage); } finally { MoPubManager.OnAdLoadedEvent -= successHandler; MoPubManager.OnAdFailedEvent -= failureHandler; } }
/// <summary> /// Sends off an asynchronous network request to load the MoPub consent dialog. The two possible resulting events /// are <see cref="MoPubManager.OnConsentDialogLoadedEvent"/> and /// <see cref="MoPubManager.OnConsentDialogFailedEvent"/>. /// </summary> public static void LoadConsentDialog() { if (IsGdprApplicable ?? false) { MoPubLog.Log("LoadConsentDialog", MoPubLog.ConsentLogEvent.LoadAttempted); MoPubManager.MoPubPlatformApi.LoadConsentDialog(); } else { MoPubManager.Instance.EmitConsentDialogFailedEvent(MoPubUtils.EncodeArgs("GDPR does not apply.")); } }