Hi there! After having UGS Analytics perfectly work for a while, I have created a new build (without any major changes related to analytics itself) - and have everything stuck. My errors during initialization:
1:
Error Unity ServicesInitializationException: The Analytics service has not been initialized. Please initialize Unity Services.
2:
Error Unity [ServicesCore]: An error occured while trying to get the project configuration for services.
3:
Error Unity Can not initialize UGS Analytics! Consent error, reason: DeserializationIssue
- My UGS Analytics version from package manager is 4.4.2 (and I can’t get the docs for exactly this version)
- My unity engine version is 2020.3.38f1
How can I fix it?
How I initialize:
await UnityServices.InitializeAsync();
// checking consent identifiers and showing popup, if needed - no errors here
//if got PIPL consent:
AnalyticsService.Instance.ProvideOptInConsent(PIPL_CONSENT_IDENTIFIER, result);
//after all the consent manipulations
_ = AnalyticsService.Instance.SetAnalyticsEnabled(true);
Full code:
public UgsAnalytics(PopupManager popupManager)
{
_popupManager = popupManager;
if (PlayerPrefs.HasKey(ANALYTICS_OPT_OUT_KEY) && PlayerPrefs.GetInt(ANALYTICS_OPT_OUT_KEY) == 1)
{
AnalyticsService.Instance.OptOut();
}
InitializeUnityAnalyticsAsync();
}
private async void InitializeUnityAnalyticsAsync()
{
try
{
await UnityServices.InitializeAsync();
List<string> consentIdentifiers = await AnalyticsService.Instance.CheckForRequiredConsents();
foreach (var identifier in consentIdentifiers)
{
if (identifier == PIPL_CONSENT_IDENTIFIER)
{
CheckUserConsent();
}
}
}
catch (ConsentCheckException e)
{
Debug.LogError("Can not initialize UGS Analytics! Consent error, reason: " + e.Reason);
}
_ = AnalyticsService.Instance.SetAnalyticsEnabled(true);
}
public void CheckUserConsent()
{
try
{
var consentPopup = _popupManager.GetPopup<UgsAnalyticsConsentController, UgsAnalyticsConsentController.Factory>();
consentPopup.OnResult += OnConsentResult;
consentPopup.Show();
}
catch (ConsentCheckException e)
{
Debug.LogError("Error during getting PIPL consent, reason: " + e.Reason);
}
}
private void OnConsentResult(bool result)
{
AnalyticsService.Instance.ProvideOptInConsent(PIPL_CONSENT_IDENTIFIER, result);
}