update: [DMA] 对齐实现需求, 使用 Google 的映射标准, 对外增加参数

deeplink
胡宇飞 2024-02-23 10:43:43 +08:00
parent bee51ce435
commit 897f39e6d9
6 changed files with 95 additions and 24 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "GuruConsent.Editor", "name": "GuruConsent.Editor",
"rootNamespace": "Guru.Editor", "rootNamespace": "Guru.Editor",
"references": [], "references": ["GUID:e241d247f550f427da05939864204192"],
"includePlatforms": [ "includePlatforms": [
"Editor" "Editor"
], ],

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3d74b53aaf9a4bf5a12996e226f8534c
timeCreated: 1708653746

View File

@ -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");
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4d3e29acffc34b3d95731dfbf721b49b
timeCreated: 1708653764

View File

@ -19,7 +19,8 @@ namespace Guru
/// Set DMA status /// Set DMA status
/// </summary> /// </summary>
/// <param name="value"></param> /// <param name="value"></param>
public static void SetDMAStatus(string value) /// <param name="mapRule">map rules </param>
public static void SetDMAStatus(string value, int mapRule = 0)
{ {
if (string.IsNullOrEmpty(value)) 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. // sometimes it will feedback with '0' so we need to fill the array with 'false' by 11 times.
string purposeStr = ""; string purposeStr = "";
bool[] purposes = new bool[11]; 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) if (i < value.Length)
{ {
@ -64,28 +65,24 @@ namespace Guru
} }
// purpose 1, 7 granted => analyticsStorage granted // 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; 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 // build result data for guru analytics
string result = ""; string result = "0000";
result += consentData[ConsentType.AdStorage] == ConsentStatus.Granted ? "1" : "0"; switch (mapRule)
result += consentData[ConsentType.AnalyticsStorage] == ConsentStatus.Granted ? "1" : "0"; {
result += consentData[ConsentType.AdPersonalization] == ConsentStatus.Granted ? "1" : "0"; default:
result += consentData[ConsentType.AdUserData] == ConsentStatus.Granted ? "1" : "0"; 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 -------------- //---------- Firebase report --------------
FirebaseAnalytics.SetConsent(consentData); FirebaseAnalytics.SetConsent(consentData);
@ -110,5 +107,37 @@ namespace Guru
}); });
} }
/// <summary>
/// using Guru map rules to generate the result
/// </summary>
/// <param name="purposes"></param>
/// <returns></returns>
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";
}
/// <summary>
/// using Google map rules to generate the result
/// </summary>
/// <param name="consentData"></param>
/// <returns></returns>
private static string ApplyGoogleMapRule(Dictionary<ConsentType, ConsentStatus> 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;
}
} }
} }

View File

@ -38,16 +38,20 @@ namespace Guru
} }
} }
private static int _dmaMapRule = 0;
/// <summary> /// <summary>
/// 对外公开接口 /// 对外公开接口
/// </summary> /// </summary>
/// <param name="onComplete"></param> /// <param name="onComplete"></param>
/// <param name="deviceId"></param> /// <param name="deviceId"></param>
/// <param name="debugGeography"></param> /// <param name="debugGeography"></param>
public static void StartConsent(Action<int> onComplete = null, string deviceId = "", int debugGeography = -1 ) /// <param name="dmaMapRule"></param>
public static void StartConsent(Action<int> 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; onCompleteHandler = onComplete;
// 初始化SDK对象 // 初始化SDK对象
GuruSDKCallback.AddCallback(OnSDKCallback); GuruSDKCallback.AddCallback(OnSDKCallback);
@ -65,8 +69,8 @@ namespace Guru
private static void OnSDKCallback(string msg) private static void OnSDKCallback(string msg)
{ {
//-------- Fetch DMA status and report ----------- //-------- Fetch DMA status and report -----------
var dma = Agent?.GetDMAValue() ?? ""; var value = Agent?.GetDMAValue() ?? "";
GoogleDMAHelper.SetDMAStatus(dma); GoogleDMAHelper.SetDMAStatus(value, _dmaMapRule);
//------- message send to unity ---------- //------- message send to unity ----------
Debug.Log($"{Tag} get callback msg:\n{msg}"); Debug.Log($"{Tag} get callback msg:\n{msg}");