MREC
MREC is 300x250 banner. This type can be useful if the application has a large free area for placing a banner in the interface.
Initialize
1. Import the namespaces:
using AppodealStack.Monetization.Api; using AppodealStack.Monetization.Common;
Start()
method of your main scene’s MonoBehavior: Appodeal.Initialize("YOUR_APPODEAL_APP_KEY", AppodealAdType.Mrec, this);
appKey - appKey is generated when you add an application to Appodeal.
adType - Ad types can be combined using "|" operator. For example, AppodealAdType.Interstitial | AppodealAdType.Banner.
By default, auto caching is enabled: Appodeal SDK starts to load MREC right away after the initialization method is called. The next MREC ad starts to load after the previous one was shown.
Display
MREC ads are refreshed every 15 seconds automatically by default. To display MREC, you need to call the following code in the activity:
Appodeal.ShowMrecView((int) yPosition, (int) xPosition, (string) placement);
xPosition
and yPosition
use custom int value or constants:
AppodealViewPosition.HorizontalSmart
— to use the full-screen width;AppodealViewPosition.HorizontalCenter
— to center MREC horizontally;AppodealViewPosition.HotizontalRight
— to align MREC to the right;AppodealViewPosition.HorizontalLeft
— to align MREC to the left;
For yPosition
you can use custom int value or constants:
AppodealViewPosition.VerticalTop
— to align MREC to the top of the screen;AppodealViewPosition.VerticalBottom
— to align MREC to the bottom of the screen.
The X coordinate (horizontal position) of the MREC relative to the top left corner of the screen.
The Y coordinate (vertical position) of the MREC relative to the top left corner of the screen.
To set your custom width and height, you can use the constants of The Unity’s Screen.width
and Screen.height
with a constant value.
Hide
Appodeal.HideMrecView();
Placements
Appodeal SDK allows you to tag each impression with different placement. For using placements you need to create placements in Appodeal Dashboard. Read more about placements.
To show an ad with placement, you have to call show method like this in your activity:
Appodeal.ShowMrecView((int) yPosition, (int) xPosition, (string) placement);
If the loaded ad can’t be shown for a specific placement, nothing will be shown.
You can configure your impression logic for each placement.
If you have no placements, or call Appodeal.Show with placement that do not exist, the impression will be tagged with 'default' placement and its settings will be applied.
Important!
Placement settings affect ONLY ad presentation, not loading or caching.
If auto caching is enabled, sdk will start to cache another ad, which can affect display rate. To save the loaded ad for future use (for instance, for another placement) check if the ad can be shown before calling show method:
if(Appodeal.CanShow(AppodealAdType.Mrec, “placementName”)){ Appodeal.ShowMrecView((int) yPosition, (int) xPosition, (string) placement); }
Callbacks
The callbacks are used to track different events in the lifecycle of an ad, e.g. when an ad was clicked on or closed. To implement them, you need to follow below steps:
- Subscribe to the desired Mrec event using one of the options from this guide. (you can subscribe to any event you want)
- You can use callbacks as shown below after:
public void YourMethod() { AppodealCallbacks.Mrec.OnLoaded += (sender, args) => OnMrecLoaded(args.IsPrecache); AppodealCallbacks.Mrec.OnFailedToLoad += (sender, args) => OnMrecFailedToLoad(); AppodealCallbacks.Mrec.OnShown += (sender, args) => OnMrecShown(); AppodealCallbacks.Mrec.OnShowFailed += (sender, args) => OnMrecShowFailed(); AppodealCallbacks.Mrec.OnClicked += (sender, args) => OnMrecClicked(); AppodealCallbacks.Mrec.OnExpired += (sender, args) => OnMrecExpired(); } #region MrecAd Callbacks // Called when mrec is loaded precache flag shows if the loaded ad is precache) private void OnMrecLoaded(bool isPrecache) { Debug.Log("Mrec loaded"); } // Called when mrec failed to load private void OnMrecFailedToLoad() { Debug.Log("Mrec failed to load"); } // Called when mrec is failed to show private void OnMrecShowFailed() { Debug.Log("Mrec show failed"); } // Called when mrec is shown private void OnMrecShown() { Debug.Log("Mrec shown"); } // Called when mrec is clicked private void OnMrecClicked() { Debug.Log("Mrec clicked"); } // Called when mrec is expired and can not be shown private void OnMrecExpired() { Debug.Log("Mrec expired"); } #endregion
All callbacks are called on native main threads that do not match the main thread of the Unity. If you need to receive callbacks in the main Unity thread follow our Callback Usage Guide .
Get Predicted eCPM
This method returns expected eCPM for a currently cached advertisement. The amount is calculated based on historical data for the current ad unit:
Appodeal.GetPredictedEcpm(AppodealAdType.Mrec);