From 897f39e6d9fdc4b694e976824970d262acd30ee3 Mon Sep 17 00:00:00 2001 From: huyfei Date: Fri, 23 Feb 2024 10:43:43 +0800 Subject: [PATCH] =?UTF-8?q?update:=20[DMA]=20=E5=AF=B9=E9=BD=90=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E9=9C=80=E6=B1=82,=20=E4=BD=BF=E7=94=A8=20Google=20?= =?UTF-8?q?=E7=9A=84=E6=98=A0=E5=B0=84=E6=A0=87=E5=87=86,=20=E5=AF=B9?= =?UTF-8?q?=E5=A4=96=E5=A2=9E=E5=8A=A0=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Editor/GuruConsent.Editor.asmdef | 2 +- Runtime/GuruConsent/Editor/Tester.meta | 3 + .../Editor/Tester/DMAValueTests.cs | 32 +++++++++ .../Editor/Tester/DMAValueTests.cs.meta | 3 + .../Runtime/Script/Consent/GoogleDMAHelper.cs | 65 ++++++++++++++----- .../Runtime/Script/Consent/GuruConsent.cs | 14 ++-- 6 files changed, 95 insertions(+), 24 deletions(-) create mode 100644 Runtime/GuruConsent/Editor/Tester.meta create mode 100644 Runtime/GuruConsent/Editor/Tester/DMAValueTests.cs create mode 100644 Runtime/GuruConsent/Editor/Tester/DMAValueTests.cs.meta diff --git a/Runtime/GuruConsent/Editor/GuruConsent.Editor.asmdef b/Runtime/GuruConsent/Editor/GuruConsent.Editor.asmdef index ebcc02a..aac65b6 100644 --- a/Runtime/GuruConsent/Editor/GuruConsent.Editor.asmdef +++ b/Runtime/GuruConsent/Editor/GuruConsent.Editor.asmdef @@ -1,7 +1,7 @@ { "name": "GuruConsent.Editor", "rootNamespace": "Guru.Editor", - "references": [], + "references": ["GUID:e241d247f550f427da05939864204192"], "includePlatforms": [ "Editor" ], diff --git a/Runtime/GuruConsent/Editor/Tester.meta b/Runtime/GuruConsent/Editor/Tester.meta new file mode 100644 index 0000000..0eda9f4 --- /dev/null +++ b/Runtime/GuruConsent/Editor/Tester.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3d74b53aaf9a4bf5a12996e226f8534c +timeCreated: 1708653746 \ No newline at end of file diff --git a/Runtime/GuruConsent/Editor/Tester/DMAValueTests.cs b/Runtime/GuruConsent/Editor/Tester/DMAValueTests.cs new file mode 100644 index 0000000..bcc09f8 --- /dev/null +++ b/Runtime/GuruConsent/Editor/Tester/DMAValueTests.cs @@ -0,0 +1,32 @@ +using UnityEngine; + +namespace Guru.Editor +{ + using NUnit.Framework; + using Guru; + + + public class DMAValueTests + { + + + [Test] + public static void TestDMAValue() + { + + GoogleDMAHelper.SetDMAStatus("0"); + Debug.Log($"\n-----------\n\n"); + + GoogleDMAHelper.SetDMAStatus("1011"); + Debug.Log($"\n-----------\n\n"); + + GoogleDMAHelper.SetDMAStatus("10000010"); + Debug.Log($"\n-----------\n\n"); + + GoogleDMAHelper.SetDMAStatus("1111111110"); + Debug.Log($"\n-----------\n\n"); + + } + + } +} \ No newline at end of file diff --git a/Runtime/GuruConsent/Editor/Tester/DMAValueTests.cs.meta b/Runtime/GuruConsent/Editor/Tester/DMAValueTests.cs.meta new file mode 100644 index 0000000..8025f73 --- /dev/null +++ b/Runtime/GuruConsent/Editor/Tester/DMAValueTests.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4d3e29acffc34b3d95731dfbf721b49b +timeCreated: 1708653764 \ No newline at end of file diff --git a/Runtime/GuruConsent/Runtime/Script/Consent/GoogleDMAHelper.cs b/Runtime/GuruConsent/Runtime/Script/Consent/GoogleDMAHelper.cs index b5161a1..c8aa45d 100644 --- a/Runtime/GuruConsent/Runtime/Script/Consent/GoogleDMAHelper.cs +++ b/Runtime/GuruConsent/Runtime/Script/Consent/GoogleDMAHelper.cs @@ -19,7 +19,8 @@ namespace Guru /// Set DMA status /// /// - public static void SetDMAStatus(string value) + /// map rules + public static void SetDMAStatus(string value, int mapRule = 0) { if (string.IsNullOrEmpty(value)) { @@ -32,7 +33,7 @@ namespace Guru // sometimes it will feedback with '0' so we need to fill the array with 'false' by 11 times. string purposeStr = ""; bool[] purposes = new bool[11]; - for(int i = 0; i < value.Length; i++) + for(int i = 0; i < purposes.Length; i++) { if (i < value.Length) { @@ -64,28 +65,24 @@ namespace Guru } // purpose 1, 7 granted => analyticsStorage granted - if (purposes[1] && purposes[2] && purposes[3] && purposes[4] && purposes[8]) + if (purposes[0] && purposes[6]) { consentData[ConsentType.AnalyticsStorage] = ConsentStatus.Granted; } - // purpose 1, 3, 4 => guru analytics granted - //---------------- Old Rules --------------------- - // bool granted = false; - // if (purposes[0] && purposes[2] && purposes[3]) - // { - // granted = true; - // } - // string result = granted? "1111" : "0000"; - // build result data for guru analytics - string result = ""; - result += consentData[ConsentType.AdStorage] == ConsentStatus.Granted ? "1" : "0"; - result += consentData[ConsentType.AnalyticsStorage] == ConsentStatus.Granted ? "1" : "0"; - result += consentData[ConsentType.AdPersonalization] == ConsentStatus.Granted ? "1" : "0"; - result += consentData[ConsentType.AdUserData] == ConsentStatus.Granted ? "1" : "0"; + string result = "0000"; + switch (mapRule) + { + default: + result = ApplyGoogleMapRule(consentData); // Google rules + break; + case 1: + result = ApplyGuruMapRule(purposes); // Guru rules + break; + } - Debug.Log($"{GuruConsent.Tag} --- GoogleDMAHelper::SetDMAStatus - status:{purposeStr} result: {result}"); + Debug.Log($"{GuruConsent.Tag} --- GoogleDMAHelper::SetDMAStatus - status:{purposeStr} result: {result} rule:{mapRule}"); //---------- Firebase report -------------- FirebaseAnalytics.SetConsent(consentData); @@ -110,5 +107,37 @@ namespace Guru }); } + + /// + /// using Guru map rules to generate the result + /// + /// + /// + private static string ApplyGuruMapRule(bool[] purposes) + { + // purpose 1, 3, 4 => guru analytics granted + //---------------- Guru Rules --------------------- + if (purposes[0] && purposes[2] && purposes[3]) + { + return "1111"; + } + return "0000"; + } + + /// + /// using Google map rules to generate the result + /// + /// + /// + private static string ApplyGoogleMapRule(Dictionary consentData) + { + string result = ""; + result += consentData[ConsentType.AdStorage] == ConsentStatus.Granted ? "1" : "0"; + result += consentData[ConsentType.AnalyticsStorage] == ConsentStatus.Granted ? "1" : "0"; + result += consentData[ConsentType.AdPersonalization] == ConsentStatus.Granted ? "1" : "0"; + result += consentData[ConsentType.AdUserData] == ConsentStatus.Granted ? "1" : "0"; + return result; + } + } } \ No newline at end of file diff --git a/Runtime/GuruConsent/Runtime/Script/Consent/GuruConsent.cs b/Runtime/GuruConsent/Runtime/Script/Consent/GuruConsent.cs index 488263e..14111d3 100644 --- a/Runtime/GuruConsent/Runtime/Script/Consent/GuruConsent.cs +++ b/Runtime/GuruConsent/Runtime/Script/Consent/GuruConsent.cs @@ -38,16 +38,20 @@ namespace Guru } } + private static int _dmaMapRule = 0; + /// /// 对外公开接口 /// /// /// /// - public static void StartConsent(Action onComplete = null, string deviceId = "", int debugGeography = -1 ) + /// + public static void StartConsent(Action onComplete = null, string deviceId = "", int debugGeography = -1 , int dmaMapRule = 0) { - Debug.Log($"{Tag} --- GuruConsent::StartConsent - deviceId: {deviceId} debugGeography: {debugGeography}"); - + Debug.Log($"{Tag} --- GuruConsent::StartConsent - deviceId:[{deviceId}] debugGeography:[{debugGeography}] dmaMapRule:[{dmaMapRule}]"); + + _dmaMapRule = dmaMapRule; onCompleteHandler = onComplete; // 初始化SDK对象 GuruSDKCallback.AddCallback(OnSDKCallback); @@ -65,8 +69,8 @@ namespace Guru private static void OnSDKCallback(string msg) { //-------- Fetch DMA status and report ----------- - var dma = Agent?.GetDMAValue() ?? ""; - GoogleDMAHelper.SetDMAStatus(dma); + var value = Agent?.GetDMAValue() ?? ""; + GoogleDMAHelper.SetDMAStatus(value, _dmaMapRule); //------- message send to unity ---------- Debug.Log($"{Tag} get callback msg:\n{msg}");