Skip to content

MREC Ads

Str4tos edited this page May 13, 2024 · 2 revisions

Medium Rectangle (MREC) are rectangular image or text ads that occupy a spot with size in dp (300x250) on screen. They stay on screen while users are interacting with the app, and can refresh automatically after a certain period of time. If you're new to mobile advertising, they're a great place to start.

Load an Ad

Call manual load ad before each show if Autoload MRec Ads not checked.
In Blueprints you can use Load node just for register Loaded/Failed events.

UCASMobileAds::LoadMRecAd();
image

Note

The Event Once checkbox will fire the Loaded/Failed event only once. if Autoload Ads used, events can be triggered many times while the game world exists.

Ad Availability

You can ask for the ad availability directly by calling the following function:

bool MRecLoaded = UCASMobileAds::IsMRecAdReady();
image

Important

We don’t recommend waiting for IsMRecAdReady to change each frame. This property call the native SDK and can affect the performance of your game. Subscribe to the OnMRecAdLoaded event instead.

Display the Ad

When you are ready to show the ad on the screen, just call the following method:

UCASMobileAds::ShowMRecAd();

When you need to hide the ad from the user, just call the following method:

UCASMobileAds::HideMRecAd();
image

Note

You can change the MRec's activity even if it is not ready to be shown yet. When the ad is ready, MRec will shown automatically.

Ad events

To further customize the behavior of your ad, you can hook into a number of events in the ad's lifecycle: loading, opening, closing, and so on. Listen for these events by registering a delegate for the appropriate event, as shown below.

// Called when the ad loaded and ready to present.
UCASMobileAds::OnMRecAdLoaded.AddLambda([=](){
    UE_LOG(LogTemp, Log, TEXT("MRec loaded"));
});
// Сalled when an error occurred with the ad.
UCASMobileAds::OnMRecAdFailed.AddLambda([=](ECASError Error){
    UE_LOG(LogTemp, Log, TEXT("MRec failed to load: %s"),
        UCASMobileAds::GetAdsErrorMessage(Error));
});
// Called when the user clicks on the Ad.
UCASMobileAds::OnMRecAdClicked.AddLambda([=](){
    UE_LOG(LogTemp, Log, TEXT("MRec clicked"));
});

Note

Ad events in Blueprints are registered in the Load nodes. Each new Load Ad node cancels previous node events.

Ad position

The position where the MRec ad should be placed. The ECASPosition enum lists the valid ad position values.
By default, the MRec ad is centered at the bottom.
Changing the position of a MRec ad does not destroy the current MRec or load a new one.

Change the MRec position on screen using the following method:

UCASMobileAds::SetMRecAdPosition(ECASPosition::TopCenter);
image

Ad Refresh rate

An ad unit’s automatic refresh rate (in seconds) determines how often a new ad request is generated for that ad unit.
We recommended using refresh rate 30 seconds. However, you can choose any value you want. Or set 0 to disable automatic refresh ads.

Change the MRec automatic refresh rate using the following method:

UCASMobileAds::SetMRecAdRefreshInterval(RefreshIntervalInSeconds);
image

Note

Ad requests should not be made when the device screen is turned off.

Free ad memory

If you no longer need the ad with specific size then free memory using the following method:

UCASMobileAds::DestroyMRecAd();
image

After calling DestroyMRecAd(), you can use LoadMRecAd() method to create a new ad view.


🔗 Done! What’s Next?