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); } }
// 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); } }
public void EmitSdkInitializedEvent(string argsJson) { var args = DecodeArgs(argsJson, min: 1); var adUnitId = args[0]; var logLevel = MoPub.LogLevel.MPLogLevelNone; if (args.Length > 1) { try { logLevel = (MoPub.LogLevel)Enum.Parse(typeof(MoPub.LogLevel), args[1]); } catch (ArgumentException) { Debug.LogWarning("Invalid LogLevel received: " + args[1]); } } else { Debug.LogWarning("No LogLevel received"); } MoPubLog.Log("EmitSdkInitializedEvent", MoPubLog.SdkLogEvent.InitFinished, logLevel); var evt = OnSdkInitializedEvent; if (evt != null) { evt(adUnitId); } }
/// <summary> /// Requests a banner ad and immediately shows it once loaded. /// <para> /// For platform-specific implementations, see /// MoPubAndroid.<see cref="MoPubAndroid.RequestBanner(string,MoPub.AdPosition,MoPub.MaxAdSize)"/> /// and MoPubiOS.<see cref="MoPubiOS.RequestBanner(string,MoPub.AdPosition,MoPub.MaxAdSize)"/>. /// </para> /// </summary> /// <param name="adUnitId">A string with the ad unit id.</param> /// <param name="position">Where in the screen to position the loaded ad. See <see cref="MoPub.AdPosition"/>. /// </param> /// <param name="maxAdSize">The maximum size of the banner to load. See <see cref="MoPub.MaxAdSize"/>.</param> public static void RequestBanner(string adUnitId, AdPosition position, MaxAdSize maxAdSize = MaxAdSize.Width320Height50) { MoPubLog.Log("RequestBanner", MoPubLog.AdLogEvent.LoadAttempted); MoPubLog.Log("RequestBanner", "Size requested: " + maxAdSize.Width() + "x" + maxAdSize.Height()); RequestAdUnit(adUnitId); ForceRefresh(adUnitId); }
/// <summary> /// If the interstitial ad has loaded, this will take over the screen and show the ad. /// <para> /// For platform-specific implementations, see /// MoPubAndroid.<see cref="MoPubAndroid.ShowInterstitialAd(string)"/> and /// MoPubiOS.<see cref="MoPubiOS.ShowInterstitialAd(string)"/>. /// </para> /// </summary> /// <param name="adUnitId">A string with the ad unit id.</param> /// <remarks><see cref="MoPubManager.OnInterstitialLoadedEvent"/> must have been triggered already.</remarks> public static void ShowInterstitialAd(string adUnitId) { MoPubLog.Log("ShowInterstitialAd", MoPubLog.AdLogEvent.ShowAttempted); if (CheckAdUnitRequested(adUnitId)) { WaitOneFrame(() => { MoPubManager.Instance.EmitInterstitialShownEvent(ArgsToJson(adUnitId)); }); } }
public static void InitializeSdk(MoPubBase.SdkConfiguration sdkConfiguration) { MoPubBase.logLevel = sdkConfiguration.LogLevel; MoPubLog.Log("InitializeSdk", "SDK initialization started", Array.Empty <object>()); MoPubBase.ValidateAdUnitForSdkInit(sdkConfiguration.AdUnitId); object[] args = new object[] { sdkConfiguration.AdUnitId, sdkConfiguration.AdditionalNetworksString, sdkConfiguration.MediationSettingsJson, sdkConfiguration.AllowLegitimateInterest, (int)sdkConfiguration.LogLevel, sdkConfiguration.NetworkConfigurationsJson, sdkConfiguration.MoPubRequestOptionsJson }; PluginClass.CallStatic("initializeSdk", args); }
/// <summary> /// If the rewarded video ad has loaded, this will take over the screen and show the ad. /// <para> /// For platform-specific implementations, see /// MoPubAndroid.<see cref="MoPubAndroid.ShowRewardedVideo(string,string)"/> and /// MoPubiOS.<see cref="MoPubiOS.ShowRewardedVideo(string,string)"/>. /// </para> /// </summary> /// <param name="adUnitId">A string with the ad unit id.</param> /// <param name="customData">An optional string with custom data for the ad.</param> /// <remarks><see cref="MoPubManager.OnRewardedVideoLoadedEvent"/> must have been triggered already.</remarks> public static void ShowRewardedVideo(string adUnitId, string customData = null) { MoPubLog.Log("ShowRewardedVideo", MoPubLog.AdLogEvent.ShowAttempted); if (CheckAdUnitRequested(adUnitId)) { WaitOneFrame(() => { MoPubManager.Instance.EmitRewardedVideoShownEvent(ArgsToJson(adUnitId)); }); } }
/// <summary> /// Shows or hides an already-loaded banner ad. /// </summary> /// <param name="adUnitId">A string with the ad unit id.</param> /// <param name="shouldShow">A bool with `true` to show the ad, or `false` to hide it.</param> /// <remarks>Banners are automatically shown after first loading.</remarks> public static void ShowBanner(string adUnitId, bool shouldShow) { if (shouldShow) { MoPubLog.Log("ShowBanner", MoPubLog.AdLogEvent.ShowAttempted); } AdUnitManager.GetAdUnit(adUnitId).ShowBanner(shouldShow); }
internal override void LoadConsentDialog() { MoPubLog.Log("LoadConsentDialog", MoPubLog.ConsentLogEvent.LoadAttempted); WaitOneFrame(() => { IsConsentDialogReady = true; MoPubManager.Instance.EmitConsentDialogLoadedEvent(); }); }
/// See MoPubUnityEditor.<see cref="MoPubUnityEditor.InitializeSdk(string)"/> public static void InitializeSdk(string anyAdUnitId) { MoPubLog.Log("InitializeSdk", MoPubLog.SdkLogEvent.InitStarted); ValidateAdUnitForSdkInit(anyAdUnitId); InitializeSdk(new SdkConfiguration { AdUnitId = anyAdUnitId }); }
/// <summary> /// Requests an rewarded video ad with the given (optional) configuration to be loaded. The two possible resulting /// events are <see cref="MoPubManager.OnRewardedVideoLoadedEvent"/> and /// <see cref="MoPubManager.OnRewardedVideoFailedEvent"/>. /// <para> /// For platform-specific implementations, see /// MoPubAndroid.<see cref="MoPubAndroid.RequestRewardedVideo(string,System.Collections.Generic.List{MoPubBase.LocalMediationSetting},string,string,double,double,string)"/> and /// MoPubiOS.<see cref="MoPubiOS.RequestRewardedVideo(string,System.Collections.Generic.List{MoPubBase.LocalMediationSetting},string,string,double,double,string)"/>. /// </para> /// </summary> /// <param name="adUnitId">A string with the ad unit id.</param> /// <param name="mediationSettings">See <see cref="MoPubBase.SdkConfiguration.MediationSettings"/>.</param> /// <param name="keywords">An optional comma-separated string with the desired keywords for this ad.</param> /// <param name="userDataKeywords">An optional comma-separated string with user data for this ad.</param> /// <param name="latitude">An optional location latitude to be used for this ad.</param> /// <param name="longitude">An optional location longitude to be used for this ad.</param> /// <param name="customerId">An optional string to indentify this user within this app. </param> /// <remarks>If a user is in a General Data Protection Regulation (GDPR) region and MoPub doesn't obtain consent /// from the user, "keywords" will be sent to the server but "userDataKeywords" will be excluded. /// (See <see cref="CanCollectPersonalInfo"/>).</remarks> public static void RequestRewardedVideo(string adUnitId, List <LocalMediationSetting> mediationSettings = null, string keywords = null, string userDataKeywords = null, double latitude = LatLongSentinel, double longitude = LatLongSentinel, string customerId = null) { MoPubLog.Log("RequestRewardedVideo", MoPubLog.AdLogEvent.LoadAttempted); RequestAdUnit(adUnitId); WaitOneFrame(() => { MoPubManager.Instance.EmitRewardedVideoLoadedEvent(ArgsToJson(adUnitId)); }); }
/// <summary> /// Requests an rewarded video ad with the given (optional) configuration to be loaded. The two possible resulting /// events are <see cref="MoPubManager.OnRewardedVideoLoadedEvent"/> and /// <see cref="MoPubManager.OnRewardedVideoFailedEvent"/>. /// </summary> /// <param name="adUnitId">A string with the ad unit id.</param> /// <param name="mediationSettings">See <see cref="MoPub.SdkConfiguration.MediationSettings"/>.</param> /// <param name="keywords">An optional comma-separated string with the desired keywords for this ad.</param> /// <param name="userDataKeywords">An optional comma-separated string with user data for this ad.</param> /// <param name="latitude">An optional location latitude to be used for this ad.</param> /// <param name="longitude">An optional location longitude to be used for this ad.</param> /// <param name="customerId">An optional string to indentify this user within this app. </param> /// <remarks>If a user is in a General Data Protection Regulation (GDPR) region and MoPub doesn't obtain consent /// from the user, "keywords" will be sent to the server but "userDataKeywords" will be excluded. /// (See <see cref="CanCollectPersonalInfo"/>).</remarks> public static void RequestRewardedVideo(string adUnitId, List <LocalMediationSetting> mediationSettings = null, string keywords = null, string userDataKeywords = null, double latitude = LatLongSentinel, double longitude = LatLongSentinel, string customerId = null) { MoPubLog.Log("RequestRewardedVideo", MoPubLog.AdLogEvent.LoadAttempted); AdUnitManager.GetAdUnit(adUnitId).RequestRewardedVideo(mediationSettings, keywords, userDataKeywords, latitude, longitude, customerId); }
public void EmitNativeLoadEvent(string argsJson) { var args = DecodeArgs(argsJson, min: 2); var adUnitId = args[0]; var data = AbstractNativeAd.Data.FromJson(args[1]); MoPubLog.Log("EmitNativeLoadEvent", MoPubLog.AdLogEvent.LoadSuccess); EmitNativeLoadEvent(adUnitId, data); }
/// <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"/>. /// <para> /// For platform-specific implementations, see /// MoPubAndroid.<see cref="MoPubAndroid.LoadConsentDialog()"/> and /// MoPubiOS.<see cref="MoPubiOS.LoadConsentDialog()"/>. /// </para> /// </summary> public static void LoadConsentDialog() { MoPubLog.Log("LoadConsentDialog", MoPubLog.ConsentLogEvent.LoadAttempted); _checkInitialized(); WaitOneFrame(() => { IsConsentDialogReady = true; MoPubManager.Instance.EmitConsentDialogLoadedEvent(); }); }
public static void InitializeSdk(string anyAdUnitId) { MoPubLog.Log("InitializeSdk", "SDK initialization started", Array.Empty <object>()); MoPubBase.ValidateAdUnitForSdkInit(anyAdUnitId); MoPubBase.SdkConfiguration sdkConfiguration = new MoPubBase.SdkConfiguration { AdUnitId = anyAdUnitId }; InitializeSdk(sdkConfiguration); }
public void EmitConsentDialogDismissedEvent() { MoPubLog.Log("EmitConsentDialogDismissedEvent", MoPubLog.ConsentLogEvent.Dismissed); var evt = OnConsentDialogDismissedEvent; if (evt != null) { evt(); } }
public void EmitNativeImpressionEvent(string adUnitId) { MoPubLog.Log("EmitNativeImpressionEvent", MoPubLog.AdLogEvent.ShowSuccess); var evt = OnNativeImpressionEvent; if (evt != null) { evt(adUnitId); } }
public void EmitNativeClickEvent(string adUnitId) { MoPubLog.Log("EmitNativeClickEvent", MoPubLog.AdLogEvent.Tapped); var evt = OnNativeClickEvent; if (evt != null) { evt(adUnitId); } }
/// <summary> /// Requests a banner ad and immediately shows it once loaded. /// </summary> /// <param name="adUnitId">A string with the ad unit id.</param> /// <param name="position">Where in the screen to position the loaded ad. See <see cref="MoPub.AdPosition"/>. /// </param> /// <param name="maxAdSize">The maximum size of the banner to load. See <see cref="MoPub.MaxAdSize"/>.</param> /// <param name="keywords">An optional comma-separated string with the desired non-PII keywords for this ad.</param> /// <param name="userDataKeywords">An optional comma-separated string with the desired PII keywords for this ad. /// </param> public static void RequestBanner(string adUnitId, AdPosition position, MaxAdSize maxAdSize = MaxAdSize.Width320Height50, string keywords = "", string userDataKeywords = "") { var width = maxAdSize.Width(); var height = maxAdSize.Height(); MoPubLog.Log("RequestBanner", MoPubLog.AdLogEvent.LoadAttempted); MoPubLog.Log("RequestBanner", "Size requested: " + width + "x" + height); AdUnitManager.GetAdUnit(adUnitId).RequestBanner(width, height, position, keywords, userDataKeywords); }
public void EmitConsentDialogShownEvent() { MoPubLog.Log("EmitConsentDialogShownEvent", MoPubLog.ConsentLogEvent.ShowSuccess); var evt = OnConsentDialogShownEvent; if (evt != null) { evt(); } }
/// <summary> /// Asynchronously initializes the relevant (Android or iOS) MoPub SDK. Call this before making any rewarded ads or /// advanced bidding requests. This will do the rewarded video custom event initialization any number of times, but /// the SDK itself can only be initialized once, and the rewarded ads module can only be initialized once. /// See <see cref="MoPubManager.OnSdkInitializedEvent"/> for the resulting triggered event. /// </summary> /// <param name="sdkConfiguration">The configuration including at least an ad unit. /// See <see cref="MoPub.SdkConfiguration"/> for details.</param> /// <remarks>The MoPub SDK needs to be initialized on Start() to ensure all other objects have been enabled first. /// (Start() rather than Awake() so that MoPubManager has had time to Awake() and OnEnable() in order to receive /// event callbacks.)</remarks> public static void InitializeSdk(SdkConfiguration sdkConfiguration) { MoPubLog.Log("InitializeSdk", MoPubLog.SdkLogEvent.InitStarted); ValidateAdUnitForSdkInit(sdkConfiguration.AdUnitId); MoPubManager.MoPubPlatformApi.InitializeSdk(sdkConfiguration); MoPubManager.MoPubPlatformApi.SetEngineInformation("unity", Application.unityVersion); CachedLogLevel = sdkConfiguration.LogLevel; }
/// <summary> /// Asynchronously initializes the relevant (Android or iOS) MoPub SDK. Call this before making any rewarded ads or /// advanced bidding requests. This will do the rewarded video custom event initialization any number of times, but /// the SDK itself can only be initialized once, and the rewarded ads module can only be initialized once. /// See <see cref="MoPubManager.OnSdkInitializedEvent"/> for the resulting triggered event. /// <para> /// For platform-specific implementations, see /// MoPubAndroid.<see cref="MoPubAndroid.InitializeSdk(MoPub.SdkConfiguration)"/> and /// MoPubiOS.<see cref="MoPubiOS.InitializeSdk(MoPub.SdkConfiguration)"/>. /// </para> /// </summary> /// <param name="sdkConfiguration">The configuration including at least an ad unit. /// See <see cref="MoPub.SdkConfiguration"/> for details.</param> /// <remarks>The MoPub SDK needs to be initialized on Start() to ensure all other objects have been enabled first. /// (Start() rather than Awake() so that MoPubManager has had time to Awake() and OnEnable() in order to receive /// event callbacks.)</remarks> public static void InitializeSdk(SdkConfiguration sdkConfiguration) { logLevel = sdkConfiguration.LogLevel; MoPubLog.Log("InitializeSdk", MoPubLog.SdkLogEvent.InitStarted); WaitOneFrame(() => { _isInitialized = true; MoPubManager.Instance.EmitSdkInitializedEvent(ArgsToJson(sdkConfiguration.AdUnitId, ((int)sdkConfiguration.LogLevel).ToString())); }); }
public static void ShowInterstitialAd(string adUnitId) { MoPubLog.Log("ShowInterstitialAd", "Attempting to show ad", Array.Empty <object>()); if (InterstitialPluginsDict.TryGetValue(adUnitId, out MoPubAndroidInterstitial interstitial)) { interstitial.ShowInterstitialAd(); } else { MoPubBase.ReportAdUnitNotFound(adUnitId); } }
public static void RequestInterstitialAd(string adUnitId, string keywords = "", string userDataKeywords = "") { MoPubLog.Log("RequestInterstitialAd", "Attempting to load ad", Array.Empty <object>()); if (InterstitialPluginsDict.TryGetValue(adUnitId, out MoPubAndroidInterstitial interstitial)) { interstitial.RequestInterstitialAd(keywords, userDataKeywords); } else { MoPubBase.ReportAdUnitNotFound(adUnitId); } }
/// <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.")); } }
public static void ShowBanner(string adUnitId, bool shouldShow) { MoPubLog.Log("ShowBanner", "Attempting to show ad", Array.Empty <object>()); if (BannerPluginsDict.TryGetValue(adUnitId, out MoPubAndroidBanner banner)) { banner.ShowBanner(shouldShow); } else { MoPubBase.ReportAdUnitNotFound(adUnitId); } }
public static void ShowRewardedVideo(string adUnitId, string customData = null) { MoPubLog.Log("ShowRewardedVideo", "Attempting to show ad", Array.Empty <object>()); if (RewardedVideoPluginsDict.TryGetValue(adUnitId, out MoPubAndroidRewardedVideo video)) { video.ShowRewardedVideo(customData); } else { MoPubBase.ReportAdUnitNotFound(adUnitId); } }
public static void CreateBanner(string adUnitId, MoPubBase.AdPosition position) { MoPubLog.Log("CreateBanner", "Attempting to load ad", Array.Empty <object>()); if (BannerPluginsDict.TryGetValue(adUnitId, out MoPubAndroidBanner banner)) { banner.CreateBanner(position); } else { MoPubBase.ReportAdUnitNotFound(adUnitId); } }
public static void RequestRewardedVideo(string adUnitId, List <MoPubBase.LocalMediationSetting> mediationSettings = null, string keywords = null, string userDataKeywords = null, double latitude = 99999.0, double longitude = 99999.0, string customerId = null) { MoPubLog.Log("RequestRewardedVideo", "Attempting to load ad", Array.Empty <object>()); if (RewardedVideoPluginsDict.TryGetValue(adUnitId, out MoPubAndroidRewardedVideo video)) { video.RequestRewardedVideo(mediationSettings, keywords, userDataKeywords, latitude, longitude, customerId); } else { MoPubBase.ReportAdUnitNotFound(adUnitId); } }
public void ForceRefresh(string adUnitId) { MoPubLog.Log("ForceRefresh", "Attempting to show ad", Array.Empty <object>()); if (BannerPluginsDict.TryGetValue(adUnitId, out MoPubAndroidBanner banner)) { banner.ForceRefresh(); } else { MoPubBase.ReportAdUnitNotFound(adUnitId); } }