update: [DMA] 对齐实现需求, 使用 Google 的映射标准, 对外增加参数
parent
bee51ce435
commit
897f39e6d9
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "GuruConsent.Editor",
|
||||
"rootNamespace": "Guru.Editor",
|
||||
"references": [],
|
||||
"references": ["GUID:e241d247f550f427da05939864204192"],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3d74b53aaf9a4bf5a12996e226f8534c
|
||||
timeCreated: 1708653746
|
||||
|
|
@ -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");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4d3e29acffc34b3d95731dfbf721b49b
|
||||
timeCreated: 1708653764
|
||||
|
|
@ -19,7 +19,8 @@ namespace Guru
|
|||
/// Set DMA status
|
||||
/// </summary>
|
||||
/// <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))
|
||||
{
|
||||
|
|
@ -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
|
|||
});
|
||||
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -38,16 +38,20 @@ namespace Guru
|
|||
}
|
||||
}
|
||||
|
||||
private static int _dmaMapRule = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 对外公开接口
|
||||
/// </summary>
|
||||
/// <param name="onComplete"></param>
|
||||
/// <param name="deviceId"></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;
|
||||
// 初始化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}");
|
||||
|
|
|
|||
Loading…
Reference in New Issue