update: 再次对齐 Purposes 规则
parent
18c7876f8f
commit
82328c1555
|
|
@ -1,4 +1,6 @@
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Guru
|
namespace Guru
|
||||||
{
|
{
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -16,6 +18,15 @@ namespace Guru
|
||||||
{
|
{
|
||||||
public static readonly bool UsingDelayAppMeasurement = false;
|
public static readonly bool UsingDelayAppMeasurement = false;
|
||||||
|
|
||||||
|
public static List<string> PurposesRules = new List<string>
|
||||||
|
{
|
||||||
|
"0", // 1
|
||||||
|
"", // *
|
||||||
|
"2,3", // 3&4
|
||||||
|
"0,6" // 1&7
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set DMA status
|
/// Set DMA status
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -49,27 +60,7 @@ namespace Guru
|
||||||
}
|
}
|
||||||
|
|
||||||
// build an dict<type, status> for record consent data
|
// build an dict<type, status> for record consent data
|
||||||
Dictionary<ConsentType, ConsentStatus> consentData = new Dictionary<ConsentType, ConsentStatus>()
|
Dictionary<ConsentType, ConsentStatus> consentData = ApplyPurposesRules(purposes);
|
||||||
{
|
|
||||||
{ ConsentType.AdStorage, ConsentStatus.Denied },
|
|
||||||
{ ConsentType.AnalyticsStorage, ConsentStatus.Denied },
|
|
||||||
{ ConsentType.AdPersonalization, ConsentStatus.Denied },
|
|
||||||
{ ConsentType.AdUserData, ConsentStatus.Denied },
|
|
||||||
};
|
|
||||||
|
|
||||||
// purpose 2,3,4,5,9 granted => adStorage, adPersonalization, adUserData granted
|
|
||||||
if (purposes[1] && purposes[2] && purposes[3] && purposes[4] && purposes[8])
|
|
||||||
{
|
|
||||||
consentData[ConsentType.AdStorage] = ConsentStatus.Granted;
|
|
||||||
consentData[ConsentType.AdPersonalization] = ConsentStatus.Granted;
|
|
||||||
consentData[ConsentType.AdUserData] = ConsentStatus.Granted;
|
|
||||||
}
|
|
||||||
|
|
||||||
// purpose 1, 7 granted => analyticsStorage granted
|
|
||||||
if (purposes[0] && purposes[6])
|
|
||||||
{
|
|
||||||
consentData[ConsentType.AnalyticsStorage] = ConsentStatus.Granted;
|
|
||||||
}
|
|
||||||
|
|
||||||
// build result data for guru analytics
|
// build result data for guru analytics
|
||||||
string result = "0000";
|
string result = "0000";
|
||||||
|
|
@ -140,5 +131,59 @@ namespace Guru
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static Dictionary<ConsentType, ConsentStatus> ApplyPurposesRules(bool[] purposes)
|
||||||
|
{
|
||||||
|
Dictionary<ConsentType, ConsentStatus> consentData = new Dictionary<ConsentType, ConsentStatus>()
|
||||||
|
{
|
||||||
|
{ ConsentType.AdStorage, ConsentStatus.Denied },
|
||||||
|
{ ConsentType.AnalyticsStorage, ConsentStatus.Denied },
|
||||||
|
{ ConsentType.AdPersonalization, ConsentStatus.Denied },
|
||||||
|
{ ConsentType.AdUserData, ConsentStatus.Denied },
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < PurposesRules.Count; i++)
|
||||||
|
{
|
||||||
|
ConsentType type = ConsentType.AdStorage;
|
||||||
|
switch (i)
|
||||||
|
{
|
||||||
|
default: type = ConsentType.AdStorage; break;
|
||||||
|
case 1: type = ConsentType.AnalyticsStorage; break;
|
||||||
|
case 2: type = ConsentType.AdPersonalization; break;
|
||||||
|
case 3: type = ConsentType.AdUserData; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool granted = true;
|
||||||
|
if (string.IsNullOrEmpty(PurposesRules[i]))
|
||||||
|
{
|
||||||
|
// null pass directly.
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// parse all the single rule
|
||||||
|
int[] rule = Array.ConvertAll(PurposesRules[i].Split(','), s =>
|
||||||
|
{
|
||||||
|
if(string.IsNullOrEmpty(s)) return -1;
|
||||||
|
int.TryParse(s, out var v);
|
||||||
|
return v;
|
||||||
|
});
|
||||||
|
for (int j = 0; j < rule.Length; j++)
|
||||||
|
{
|
||||||
|
var idx = rule[j];
|
||||||
|
if (idx < 0 || idx >= purposes.Length || !purposes[rule[j]])
|
||||||
|
{
|
||||||
|
granted = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
consentData[type] = granted ? ConsentStatus.Granted : ConsentStatus.Denied;
|
||||||
|
}
|
||||||
|
|
||||||
|
return consentData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue