PIP 모드 광고 구현 (베타)

플랫폼 선택: Android iOS Unity

PIP 모드

PIP 모드 광고는 도움말, 피드, 게임플레이와 같은 화면의 콘텐츠 위에 표시되는 플로팅 창에 표시됩니다. 이 형식을 사용하면 광고가 계속 표시되는 동안 사용자가 앱과 상호작용할 수 있습니다. 전체 화면을 차지하지 않는 광고를 표시하려면 이 형식을 선택하세요. PIP 모드 광고 에 대해 자세히 알아보세요.

이 가이드에서는 앱에서 PIP 모드 광고를 요청하고 표시하는 방법을 설명합니다 Google Mobile Ads Unity Plugin을(를) 사용하여

시작하기 전에

계속하기 전에 다음 작업을 실행하세요.

  • 테스트 광고를 사용 설정하고 다음 테스트 광고 단위 ID를 사용합니다.

    Android

    ca-app-pub-3940256099942544/9657123429
    

    iOS

    ca-app-pub-3940256099942544/8810945611
    

광고 로드하기

PictureInPictureAd 객체를 로드하려면 광고 요청을 만들고 로드 메서드를 호출합니다.

public void LoadPictureInPictureAd()
{
    // Clean up any existing ad before loading a new one.
    if (_pictureInPictureAd != null)
    {
        _pictureInPictureAd.Destroy();
        _pictureInPictureAd = null;
    }

    // Create our request used to load the ad.
    var adRequest = new AdRequest();

    // Send the request to load the ad.
    PictureInPictureAd.Load(_adUnitId, adRequest,
        (PictureInPictureAd ad, LoadAdError error) =>
        {
            if (error != null || ad == null)
            {
                Debug.LogWarning(
                    "Picture-in-picture ad failed to load: " + error);
                return;
            }

            // Capture the PictureInPictureAd reference for later use.
            _pictureInPictureAd = ad;
        });
}

_adUnitId를 광고 단위 ID로 바꿉니다.

광고 게재

화면에 PIP 모드 광고를 표시하려면 표시 메서드를 호출합니다. 다음 예에서는 광고를 기본 위치에 표시합니다.

public void ShowPictureInPictureAd()
{
    // Use the ad reference saved from the Load callback.
    if (_pictureInPictureAd != null)
    {
        _pictureInPictureAd.Show();
    }
    else
    {
        Debug.Log("No ad to show.");
    }
}

위치 설정

기본적으로 Google Mobile Ads Unity Plugin는 처음 표시될 때 화면의 오른쪽 하단 에 PIP 모드 광고를 표시하거나 이전에 표시된 경우 마지막으로 알려진 위치에 표시합니다. 광고가 표시되는 위치를 맞춤설정하려면 광고를 표시할 때 위치를 지정하세요. 다음 예에서는 화면 왼쪽 상단의 콘텐츠 위에 위치를 설정합니다.

public void ShowPictureInPictureAdTopLeft()
{
    // Use the ad reference saved from the Load callback.
    if (_pictureInPictureAd != null)
    {
        _pictureInPictureAd.Show(PictureInPictureAdPosition.TopLeft);
    }
    else
    {
        Debug.Log("No ad to show.");
    }
}

사용 가능한 모든 위치는 PictureInPictureAdPosition을 참조하세요.

광고 이벤트 수신 대기

PIP 모드 광고 수명 주기 이벤트를 처리하려면 광고를 표시하기 전에 광고 이벤트를 등록하세요. 이러한 이벤트는 클릭 및 노출과 같은 광고 상호작용을 보고합니다. 이러한 이벤트는 광고가 표시되거나 숨겨지는 경우와 같은 PIP 모드 관련 이벤트도 보고합니다.

private void RegisterEventHandlers(PictureInPictureAd ad)
{
    // Raised when the ad is estimated to have earned money.
    ad.OnAdPaid += (AdValue adValue) =>
    {
        Debug.Log($"Picture-in-picture ad paid: {adValue.Value} {adValue.CurrencyCode}");
    };
    // Raised when an impression is recorded for an ad.
    ad.OnAdImpressionRecorded += () =>
    {
        Debug.Log("Picture-in-picture ad recorded an impression.");
    };
    // Raised when a click is recorded for an ad.
    ad.OnAdClicked += () =>
    {
        Debug.Log("Picture-in-picture ad recorded a click.");
    };
    // Raised when the picture-in-picture ad is displayed on the screen.
    ad.OnAdShown += () =>
    {
        Debug.Log("Picture-in-picture ad shown.");
    };
    // Raised when the picture-in-picture ad is hidden from the screen.
    ad.OnAdHidden += () =>
    {
        Debug.Log("Picture-in-picture ad hidden.");
    };
    // Raised when an ad opened full screen content.
    ad.OnAdFullScreenContentOpened += () =>
    {
        Debug.Log("Picture-in-picture ad opened full screen content.");
    };
    // Raised when the ad closed full screen content.
    ad.OnAdFullScreenContentClosed += () =>
    {
        Debug.Log("Picture-in-picture ad closed full screen content.");
    };
    // Raised when the ad failed to open full screen content.
    ad.OnAdFullScreenContentFailed += (AdError error) =>
    {
        Debug.LogWarning(
            "Picture-in-picture ad failed to open full screen " +
            "content: " + error);
    };
}

광고 숨기기

화면에서 플로팅 광고를 삭제하려면 숨기기 메서드를 호출합니다. 이 메서드는 광고 숨김 이벤트를 호출합니다.

public void HidePictureInPictureAd()
{
    // Use the ad reference saved from the Load callback.
    if (_pictureInPictureAd != null)
    {
        _pictureInPictureAd.Hide();
    }
    else
    {
        Debug.Log("No ad to hide.");
    }
}

광고 리소스 정리

메모리 누수를 방지하려면 앱에서 광고 사용을 완료할 때 광고 객체에 대한 참조를 삭제하세요. 예를 들어 앱이 더 이상 광고를 표시하지 않거나 광고와 상호작용하지 않는 경우입니다.

public void DestroyPictureInPictureAd()
{
    // Use the ad reference saved from the Load callback.
    if (_pictureInPictureAd != null)
    {
        _pictureInPictureAd.Destroy();
        _pictureInPictureAd = null;
    }
}