Skip to content

Advertising

VirtueSky edited this page Dec 3, 2024 · 14 revisions

Advertising for unity

(Tested with applovin > v5.11.3 and google admob > v8.5.2)

Use

Setting

Open tab Advertising in Magic Panel

Unity_r1v2Ygg9sY

  • Create AdClient and AdVariable
  • Choose AdNetwork Max or Admob
  • You can click install sdk if your project doesn't have it yet.
  • Add Scripting Define Symbols to use

Set id for AdUnitVariable

AdVariable

(For Admob, you can get the test Id by going to Context Menu and selecting Get Id Test)

idtest

Attach Advertising to the object in the scene to load the ads

Adsvertising

Script show ads (demo)

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using VirtueSky.Ads;

public class AdsManager : MonoBehaviour
{
    public TextMeshProUGUI textNoti;
    public AdUnitVariable banner;
    public AdUnitVariable inter;
    public AdUnitVariable reward;

    public void ShowBanner()
    {
        Debug.Log(banner.IsReady());
        banner.Show();
    }

    public void ShowInter()
    {
        if (inter.IsReady())
        {
            LogMessage("inter is ready");
            inter.Show().OnCompleted(() => { LogMessage("inter is completed"); });
        }
        else
        {
            LogMessage("Inter is not ready");
        }
    }

    public void ShowReward()
    {
        if (reward.IsReady())
        {
            LogMessage("reward is ready");
            reward.Show().OnCompleted(() => { LogMessage("Reward is completed"); }).OnSkipped(() => { LogMessage("reward is skipped"); });
        }
        else
        {
            LogMessage("reward is not ready");
        }
    }

    void LogMessage(string message)
    {
        textNoti.text = message;
        Debug.Log(message);
    }
}

Note: If Enable GDPR

  • Android: Advertising will only be initialized after user consent allows requesting ads.
  • iOS: If ATT is authorized, GDPR compliance will be initialized, and advertising will only be initialized after user consent allows requesting ads.
    If ATT is not authorized, GDPR compliance will not be initialized, and advertising will proceed without GDPR conditions.
  • When using GDPR, make sure you have created the GDPR message in Admob
  • Advertising is successfully initialized only when the Android logcat shows currentAdClient: ...