-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPrivacySettings.cs
More file actions
261 lines (233 loc) · 9.16 KB
/
PrivacySettings.cs
File metadata and controls
261 lines (233 loc) · 9.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
using ConsentManagementProvider;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
using System;
public class PrivacySettings : MonoBehaviour, IOnConsentReady, IOnConsentSpFinished
{
public int accountId = 22;
public int propertyId = 16893;
public string propertyName = "mobile.multicampaign.demo";
public string gdprPmId = "488393";
public string ccpaPmId = "509688";
public string usnatPmId = "943886";
public string authId = null;
public List<CAMPAIGN_TYPE> campaignTypes = new ();
[Header("GDPR Custom Consent")]
public string[] vendors = { "5fbe6f050d88c7d28d765d47", "5ff4d000a228633ac048be41" };
public string[] categories = { "60657acc9c97c400122f21f3", "608bad95d08d3112188e0e36", "608bad95d08d3112188e0e2f" };
public string[] legIntCategories = { };
[Header("UI")]
public Text consentValueText;
public Text authIdText;
public Button loadMessageButton;
public Button gdprPrivacySettingsButton;
public Button ccpaPrivacySettingsButton;
public Button usnatPrivacySettingsButton;
public Button customConsentButton;
public Button deleteCustomConsentButton;
public Button clearDataButton;
public Text sdkStatus;
public static string statusCampaignGDPR = "default";
public static string statusCampaignCCPA = "default";
public static string statusCampaignUSNAT = "default";
private MESSAGE_LANGUAGE language
{
get
{
switch (Application.systemLanguage)
{
case SystemLanguage.Spanish: return MESSAGE_LANGUAGE.SPANISH;
case SystemLanguage.French: return MESSAGE_LANGUAGE.FRENCH;
default: return MESSAGE_LANGUAGE.ENGLISH;
}
}
}
private string storedConsentString = null;
private void Awake()
{
ConsentMessenger.AddListener<IOnConsentReady>(gameObject);
ConsentMessenger.AddListener<IOnConsentSpFinished>(gameObject);
List<SpCampaign> spCampaigns = new List<SpCampaign>();
List<TargetingParam> gdprParams = new List<TargetingParam> { new TargetingParam("location", "EU") };
SpCampaign gdpr = new SpCampaign(CAMPAIGN_TYPE.GDPR, gdprParams);
spCampaigns.Add(gdpr);
campaignTypes.Add(CAMPAIGN_TYPE.GDPR);
List<TargetingParam> ccpaParams = new List<TargetingParam> { new TargetingParam("location", "US") };
SpCampaign ccpa = new SpCampaign(CAMPAIGN_TYPE.CCPA, ccpaParams);
spCampaigns.Add(ccpa);
campaignTypes.Add(CAMPAIGN_TYPE.CCPA);
List<TargetingParam> usnatParams = new List<TargetingParam> { new TargetingParam("location", "US") };
SpCampaign usnat = new SpCampaign(CAMPAIGN_TYPE.USNAT, usnatParams, transitionCCPAAuth: false, supportLegacyUSPString: false);
spCampaigns.Add(usnat);
campaignTypes.Add(CAMPAIGN_TYPE.USNAT);
UpdateSdkStatus("Running");
CMP.Instance.Initialize(
spCampaigns: spCampaigns,
accountId: accountId,
propertyId: propertyId,
propertyName: propertyName, // pay attention to any leading and trailing whitespaces;
// it's unlikely you voluntarily use them in property name, but if you do
// please note that we Trim them down in the call tree.
language: language,
campaignsEnvironment: CAMPAIGN_ENV.PUBLIC,
messageTimeoutInSeconds: 30
);
}
void Start()
{
UpdateUI();
CMP.Instance.LoadMessage(authId: authId);
}
public void OnLoadMessagePress()
{
UpdateSdkStatus("Running");
storedConsentString = null;
UpdateUI();
CMP.Instance.LoadMessage(authId: authId);
}
public void OnGDPRPrivacyManagerButtonClick()
{
UpdateSdkStatus("Running");
CMP.Instance.LoadPrivacyManager(
campaignType: CAMPAIGN_TYPE.GDPR,
pmId: gdprPmId
);
}
public void OnCCPAPrivacyManagerButtonClick()
{
UpdateSdkStatus("Running");
CMP.Instance.LoadPrivacyManager(
campaignType: CAMPAIGN_TYPE.CCPA,
pmId: ccpaPmId
);
}
public void OnUSNATPrivacyManagerButtonClick()
{
UpdateSdkStatus("Running");
CMP.Instance.LoadPrivacyManager(
campaignType: CAMPAIGN_TYPE.USNAT,
pmId: usnatPmId
);
}
private void SuccessDelegate(GdprConsent customConsent)
{
Debug.Log($"I am your success callback!");
CmpDebugUtil.ForceEnableNextCmpLog();
CmpDebugUtil.Log(customConsent.ToFullString());
storedConsentString = customConsent.euconsent;
UpdateUI();
}
public void OnCustomConsentButtonClick()
{
CMP.Instance.CustomConsentGDPR(vendors: vendors,
categories: categories,
legIntCategories: legIntCategories,
onSuccessDelegate: SuccessDelegate);
}
public void OnClearCustomConsentDataPress()
{
CMP.Instance.DeleteCustomConsentGDPR(
vendors: vendors,
categories: categories,
legIntCategories: legIntCategories,
onSuccessDelegate: SuccessDelegate
);
UpdateUI();
}
public void OnClearDataPress()
{
UpdateSdkStatus("Not Started");
CMP.Instance.ClearAllData();
storedConsentString = null;
UpdateUI();
}
public void OnConsentReady(SpConsents consents)
{
storedConsentString = consents.gdpr?.consents.euconsent ?? "--";
if(CMP.Instance.UseGDPR)
CmpDebugUtil.Log(consents.gdpr.consents.ToFullString());
if(CMP.Instance.UseCCPA)
CmpDebugUtil.Log(consents.ccpa.consents.ToFullString());
if(CMP.Instance.UseUSNAT)
CmpDebugUtil.Log(consents.usnat.consents.ToFullString());
UpdateUI();
statusCampaignGDPR = UpdateStatuses(consents, CAMPAIGN_TYPE.GDPR);
statusCampaignCCPA = UpdateStatuses(consents, CAMPAIGN_TYPE.CCPA);
statusCampaignUSNAT = UpdateStatuses(consents, CAMPAIGN_TYPE.USNAT);
}
public void OnConsentSpFinished()
{
UpdateSdkStatus("Finished");
UpdateUI();
}
private void UpdateUI()
{
if (storedConsentString != null)
{
loadMessageButton.interactable = false;
gdprPrivacySettingsButton.interactable = CMP.Instance.UseGDPR;
ccpaPrivacySettingsButton.interactable = CMP.Instance.UseCCPA;
usnatPrivacySettingsButton.interactable = CMP.Instance.UseUSNAT;
customConsentButton.interactable = true;
deleteCustomConsentButton.interactable = true;
clearDataButton.interactable = true;
consentValueText.text = storedConsentString;
authIdText.text = CMP.GetBridgeString("AuthId:"+authId);
}
else
{
loadMessageButton.interactable = true;
gdprPrivacySettingsButton.interactable = false;
ccpaPrivacySettingsButton.interactable = false;
usnatPrivacySettingsButton.interactable = false;
customConsentButton.interactable = false;
deleteCustomConsentButton.interactable = false;
clearDataButton.interactable = false;
consentValueText.text = "-";
authIdText.text = "-";
}
}
void UpdateSdkStatus(string status)
{
sdkStatus.text = "SDK:"+status;
}
string UpdateStatuses(SpConsents consents, CAMPAIGN_TYPE campaign)
{
if (campaign == CAMPAIGN_TYPE.GDPR)
{
bool rejectedAny = consents.gdpr?.consents.consentStatus.rejectedAny ?? false;
bool rejectedLI = consents.gdpr?.consents.consentStatus.rejectedLI ?? false;
bool consentedAll = consents.gdpr?.consents.consentStatus.consentedAll ?? false;
bool consentedToAny = consents.gdpr?.consents.consentStatus.consentedToAny ?? false;
if (consentedAll && consentedToAny)
return "accepted";
else if (rejectedAny && rejectedLI && !consentedAll && !consentedToAny)
return "rejected";
}
if (campaign == CAMPAIGN_TYPE.CCPA)
{
if (consents.ccpa?.consents.status == "consentedAll")
return "accepted";
else if (consents.ccpa?.consents.status == "rejectedAll")
return "rejected";
}
if (campaign == CAMPAIGN_TYPE.USNAT)
{
bool rejectedAny = consents.usnat?.consents.statuses.rejectedAny ?? false;
bool consentedToAll = consents.usnat?.consents.statuses.consentedToAll ?? false;
bool consentedToAny = consents.usnat?.consents.statuses.consentedToAny ?? false;
if (consentedToAll && consentedToAny)
return "accepted";
else if (rejectedAny)
return "rejected";
}
return "default";
}
private void OnDestroy()
{
ConsentMessenger.RemoveListener<IOnConsentSpFinished>(gameObject);
ConsentMessenger.RemoveListener<IOnConsentReady>(gameObject);
CMP.Instance.Dispose();
}
}