facebook twitter hatena line email

Unity/GoogleMobileAds/SKAdNetwork

提供: 初心者エンジニアの簡易メモ
2021年2月10日 (水) 20:55時点におけるAdmin (トーク | 投稿記録)による版 (自動反映する場合)

移動: 案内検索

SKAdNetworkとは

ios14のidfa対応するために、使えば良いじゃんとadmobに推奨されてるライブラリ

admobからios14対応時に推奨されてるお知らせ

To help you prepare for these changes and improve iOS monetization rates, Google recommends that you take the following actions as soon as possible:
1. 	Install the latest Google Mobile Ads SDK for iOS (for AdMob or
Ad Manager). Versions 7.64 or later include critical features for iOS 14 compatibility.
2. 	Configure SKAdNetwork with Google’s network identifier. Advertisers will be using Apple’s SKAdNetwork API to measure the value they get from your app, so doing so is the best way to get credit for your app’s ads performance. Learn more about configuring SKAdNetwork for mobile and video.
3. 	Review Apple’s ATT consent prompt and determine if implementing is right for your app. Conducting a limited user experiment (via server configuration) can help you understand what implementation works best for your users. Google’s Funding Choices user messaging is an option you may want to evaluate for creating and managing the ATT prompt & explainer messaging. Learn more about configuring Funding Choices IDFA messages.

unityのadmobライブラリ

https://github.com/googleads/googleads-mobile-unity/releases

Google Mobile Ads Unity Plugin v5.4.0

であれば、

Google Mobile Ads iOS SDK 7.68.0

となっていて、7.64より上なので、Google Mobile Ads Unity Plugin 5.4.0を入れておけば良い。

unityのadmobライブラリでSKAdNetwork対応方法

iosをビルドすると Info.plistに以下が出力される

    <key>SKAdNetworkItems</key>
    <array>
      <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>cstr6suwn9.skadnetwork</string>
      </dict>
    </array>

SKAdNetworkIdentifierの値は、以下ページにある値と同じか、確認しておく。

https://developers.google.com/admob/ios/ios14?hl=ja

App Tracking Transparency で許可をリクエストする

Info.plistに以下を追加

<key>NSUserTrackingUsageDescription</key>
<string>This identifier will be used to deliver personalized ads to you.</string>

自動反映する場合

Editor/PListProcessor.cs

#if UNITY_IOS
using System.IO;
using UnityEditor.iOS.Xcode;
using UnityEditor;
using UnityEditor.Callbacks;

namespace iOS.Editor
{
    public class PostBuildProcessForIosAtt
    {
        private const string ATT_FRAMEWORK = "AppTrackingTransparency.framework";

        [PostProcessBuild]
        public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath)
        {
            if (buildTarget != BuildTarget.iOS)
            {
                return;
            }
            var pbxPath = PBXProject.GetPBXProjectPath(buildPath);
            var pbx = new PBXProject();
            pbx.ReadFromFile(pbxPath);
            string target = GetUnityMainTargetGuidWithCompatible(pbx);
            pbx.AddFrameworkToProject(target, ATT_FRAMEWORK, true);
            pbx.WriteToFile(pbxPath);

            var path  = buildPath + "/Info.plist";
            var plist = new PlistDocument();
            plist.ReadFromFile(path);
            var root = plist.root;
            root.SetString( "NSUserTrackingUsageDescription", "本アプリは、広告効果の測定や分析などのためにIDFA(広告識別子)を利用します。");
            plist.WriteToFile(path);
        }

        private static string GetUnityMainTargetGuidWithCompatible(PBXProject pbx)
        {
#if UNITY_2019_3_OR_NEWER
            return pbx.GetUnityFrameworkTargetGuid();
#else
            return pbx.TargetGuidByName(PBXProject.GetUnityTargetName());
#endif
        }
    }
}
#endif

unityからのリクエスト方法はこちら

https://creator.game.cyberagent.co.jp/?p=7382

参考

https://qiita.com/bosteri_bon/items/36233fdbc478d7e74cc9

http://blog.be-style.jpn.com/article/188329627.html