Max Plugin

Đây là 1 Plugin có các Class Base để phục vụ Init, Load và Show Ads của Max và 1 một số tracking tự động với GSM

1. Điều kiện sử dụng

  • Tích hợp GSM SDK V1.2.3.9 trở lên

2. Một số class chính

  • GSMMaxInfo: Mục đích để đẩy các thông tin như maxSDK, AdUnitId, Version lên GSM để kiểm tra xem game đã tích hợp đúng và đủ các thông số mà PM cần hay không

  • BaseMaxAdsController: Là 1 Class Base có tác dụng các sẵn các phương thức Load, Show, và 1 số Event Callback của Max. Lớp Base này có sẵn cho loại Ad RewardInterstitial

    • Đã có class GSMMaxInitialization giúp tự động khởi tạo Max SDK từ trước Scene Onload

    • Setting ở GSM:

      • Chú ý các AdsName của từng AdUnitId khai báo như thế nào thì trong code lấy ra phải lấy đúng Name như vậy

      • Khi sử dụng BaseMaxAdsController: Thì sẽ có sẵn 1 Counter log với Type= Max_LoadAd

      • Code mẫu sử dụng:

using GSM.Ads;
using GSM.Core;
using System.Collections;
using UnityEngine;

public class MaxAdsController : BaseMaxAdsController, IAdsInterface
{
    private static MaxAdsController _instance;
    public static MaxAdsController Instance => _instance;
    private string AD_REWARD_UNIT_ID, AD_FULL_UNIT_ID;

    protected override void Awake()
    {
        if (_instance == null)
        {
            _instance = this;
            DontDestroyOnLoad(this.gameObject);
        }
        else
        {
            Destroy(gameObject);
        }
        GetAdSettingGSM();
        //InitializeBannerAdCallBacks();
        base.Awake();
        OnSdkInitializedEvent += MaxAdsController_OnSdkInitializedEvent;
    }

    private void MaxAdsController_OnSdkInitializedEvent(MaxSdkBase.SdkConfiguration sdkConfiguration)
    {
        //Có thể khởi tạo thêm các loại Ad khác như: Banner, Mrec ...
        //InitializeBannerAds();
    }

    #region Base
    private void GetAdSettingGSM()
    {
        GSMSettings settings = GSMInitialization.GsmSettings;
        if (settings != null)
        {
            var rewardAdUnit = settings.GetMAXAdUnit("Reward");
            if (rewardAdUnit != null)
            {
                AD_REWARD_UNIT_ID = rewardAdUnit.adUnitId;
            }
            var interAdUnit = settings.GetMAXAdUnit("Inter");
            if (interAdUnit != null)
            {
                AD_FULL_UNIT_ID = interAdUnit.adUnitId;
            }
        }
        else
        {
            Debug.LogError("GSMSettings not found");
        }
    }

    public override string GetRewardVideoAdUnitId()
    {
        return AD_REWARD_UNIT_ID;
    }

    public override string GetInterstitialAdUnitId()
    {
        return AD_FULL_UNIT_ID;
    }

    protected override string GetTargetLevel()
    {
        return <Xử lý logic trả về Level Hiện tại của user>
    }

    protected override string GetGroup()
    {
        return string.Empty;
    }

    protected override string GetSubGroup()
    {
        return string.Empty;
    }

    protected override string GetUserType()
    {
        return string.Empty;
    }
   
    #endregion
    
}
  • Tại các Controller xử lý ShowAd thì ở chỗ nào Show thì cần gọi thêm các CounterLog như sau:

    • GSMMaxCounterLog.CounterFirstRewardedShow(); Dùng cho reward

    • GSMMaxCounterLog.CounterFirstInterShow(); Dùng cho Interstitial

 public void ShowVideoReward(System.Action onUserEarnedReward, System.Action onAdClosed)
 {
     GSMMaxCounterLog.CounterFirstRewardedShow();
     if (IsRewardVideoAdsReady())
     {  
         base.ShowVideoAds(onUserEarnedReward, onAdClosed);
         return;
     }

 }
 public void ShowInterstitial(Action onIntersAdsClosed)
{
    GSMMaxCounterLog.CounterFirstRewardedShow();
    if (Application.internetReachability != NetworkReachability.NotReachable /*&& IronsourceAdsController.Instance != null*/)
    {
        if (IsInterstitialReady())
        {
            base.ShowInterstitial(onIntersAdsClosed);
        }
    }

}

Last updated