Exemple #1
0
    public static void PrivacyManagerView(GameObject prefab)
    {
        var campaignId = CmpCampaignPopupQueue.CurrentCampaignToShow();

        switch (campaignId)
        {
        case 0:
            if (!isGdprPmInitialized)
            {
                NetworkClient.Instance.PrivacyManagerViews(campaignId, propertyId, language, OnPrivacyManagerViewsSuccessCallback, delegate { InstantiateOnCanvas(prefab); }, OnExceptionCallback);
            }
            else
            {
                InstantiateOnCanvas(prefab);
            }
            break;

        case 2:
            if (!isCcpaPmInitialized)
            {
                NetworkClient.Instance.PrivacyManagerViews(campaignId, propertyId, language, OnPrivacyManagerViewsSuccessCallback, delegate { InstantiateOnCanvas(prefab); }, OnExceptionCallback);
            }
            else
            {
                InstantiateOnCanvas(prefab);
            }
            break;
        }
    }
    async Task PostConsent(int actionType, int environment, PostConsentRequest body, Action <string> onSuccessAction, Action <Exception> onErrorAction)
    {
        try
        {
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            var options = new JsonSerializerOptions {
                IgnoreNullValues = true
            };
            string json = null;
            switch (CmpCampaignPopupQueue.CurrentCampaignToShow())
            {
            case 0:
                json = JsonSerializer.Serialize(body as PostConsentGdprRequest, options);
                break;

            case 2:
                json = JsonSerializer.Serialize(body as PostConsentCcpaRequest, options);
                break;
            }
            var    data = new StringContent(json, Encoding.UTF8, "application/json");
            string link = GetConsentGdprQueryParams(actionType, environment);
            HttpResponseMessage response = await client.PostAsync(link, data);

            response.EnsureSuccessStatusCode();
            string responseBody = await response.Content.ReadAsStringAsync();

            dispatcher.Enqueue(delegate { onSuccessAction?.Invoke(responseBody); });
        }
        catch (Exception ex)
        {
            dispatcher.Enqueue(delegate { onErrorAction?.Invoke(ex); });
        }
    }
Exemple #3
0
    private static void OnPrivacyManagerViewsSuccessCallback(string json)
    {
        switch (CmpCampaignPopupQueue.CurrentCampaignToShow())
        {
        case 0:
            NativeUiJsonDeserializer.DeserializeExtraCall(json: json,
                                                          categoryModels: ref gdprCategories,
                                                          specialPurposeModels: ref gdprSpecialPurposes,
                                                          featureModels: ref gdprFeatures,
                                                          specialFeatureModels: ref gdprSpecialFeatures,
                                                          vendorModels: ref gdprVendors);
            isGdprPmInitialized = true;
            break;

        case 2:
            NativeUiJsonDeserializer.DeserializeExtraCall(json: json,
                                                          categoryModels: ref ccpaCategories,
                                                          specialPurposeModels: ref ccpaSpecialPurposes,
                                                          featureModels: ref ccpaFeatures,
                                                          specialFeatureModels: ref ccpaSpecialFeatures,
                                                          vendorModels: ref ccpaVendors);
            isCcpaPmInitialized = true;
            break;
        }
        SaveContext.UpdateUserConsentUIState();
    }
Exemple #4
0
    private static void OnMessageSuccessCallback(string json)
    {
        var message = NativeUiJsonDeserializer.DeserializeMessageGdprGetResponse(json);

        if (message.message?.categories != null && message.message?.categories.Count > 0)
        {
            shortCategories?.Clear();
            shortCategories = message.message?.categories;
        }
        if (message.ui != null && message.ui.Count > 0)
        {
            switch (CmpCampaignPopupQueue.CurrentCampaignToShow())
            {
            case 0:
                gdprElements?.Clear();
                gdprElements = message.ui;
                break;

            case 2:
                ccpaElements?.Clear();
                ccpaElements = message.ui;
                break;
            }
        }
        if (message.popupBgColors != null && message.popupBgColors.Count > 0)
        {
            popupBgColors?.Clear();
            popupBgColors = message.popupBgColors;
        }
        SaveContext.UpdateUserConsentUIState();
        isInitialized         = true;
        IsPmReadyForResurface = true;
    }
Exemple #5
0
    private static void OnConsentSuccessCallback(string json)
    {
        var consent = JsonSerializer.Deserialize <PostConsentResponse>(json);

        SaveContext.SaveLocalState(consent.localState);
        CmpPopupDestroyer.DestroyAllPopups();
        switch (CmpCampaignPopupQueue.CurrentCampaignToShow())
        {
        case 0:
            gdprUserConsent = consent.userConsent;
            SaveContext.SaveGdprUserConsent(gdprUserConsent);
            gdprUserConsent.uuid = consent.uuid;
            isGdprConsented      = true;
            CmpCampaignPopupQueue.DequeueCampaignId();
            break;

        case 2:
            ccpaUserConsent = consent.userConsent;
            SaveContext.SaveCcpaUserConsent(ccpaUserConsent);
            ccpaUserConsent.uuid = consent.uuid;
            isCcpaConsented      = true;
            CmpCampaignPopupQueue.DequeueCampaignId();
            break;
        }
        if (CmpCampaignPopupQueue.IsCampaignAvailable)
        {
            InstantiateOnCanvas(homePrefab);
        }
        else
        {
            CmpPopupDestroyer.DestroyAllHelperGO();
        }
    }
    public void OnButtonClick()
    {
        if (scrollController is CmpCategoryDetailsScrollController catDetailsScroll)
        {
            var model = catDetailsScroll.GetModel();
            model.accepted = true;
            switch (CmpCampaignPopupQueue.CurrentCampaignToShow())
            {
            case 0:
                CmpPmSaveAndExitVariablesContext.AcceptCategory(model);
                break;

            case 2:
                CmpPmSaveAndExitVariablesContext.ExcludeCategory(model._id, true);
                break;
            }
        }
        else if (scrollController is CmpVendorDetailsScrollController vendDetailsScroll)
        {
            var model = vendDetailsScroll.GetModel();
            model.accepted = true;
            switch (CmpCampaignPopupQueue.CurrentCampaignToShow())
            {
            case 0:
                CmpPmSaveAndExitVariablesContext.AcceptVendor(model);
                break;

            case 2:
                CmpPmSaveAndExitVariablesContext.ExcludeVendor(model.vendorId, model.name);
                break;
            }
        }
        Destroy(scrollController.gameObject);
    }
Exemple #7
0
 private static void OnExceptionCallback(Exception ex)
 {
     UnityEngine.Debug.LogError("All popups will be destroyed!!!");
     CmpPopupDestroyer.DestroyAllPopups();
     cmpException = ex;
     CmpCampaignPopupQueue.DequeueCampaignId();
     if (CmpCampaignPopupQueue.IsCampaignAvailable)
     {
         InstantiateOnCanvas(homePrefab);
     }
 }
Exemple #8
0
 public void OnSaveAndExitClick()
 {
     if (CmpCampaignPopupQueue.CurrentCampaignToShow() == 2 && dnsClicked)
     {
         OnRejectAllClick();
     }
     else
     {
         CmpLocalizationMapper.Consent(1);
     }
 }
    private static string GetConsentGdprQueryParams(int action, int environment)
    {
        // https://cdn.privacy-mgmt.com/wrapper/v2/messages/choice/gdpr/11?env=prod
        // return BuildUriWithQuery(baseAdr: "https://cdn.privacy-mgmt.com/",
        string env          = environment == 0 ? "stage" : "prod";
        string campaignName = CmpCampaignPopupQueue.CurrentCampaignToShow() == 0 ? "gdpr/" : "ccpa/";

        return(BuildUriWithQuery(baseAdr: "https://cdn.sp-stage.net/",
                                 path: "wrapper/v2/messages/choice/" + campaignName + action.ToString(),
                                 qParams: new Dictionary <string, string>()
        {
            { "env", env },
        }));
    }
 public static void AcceptCategoryFromPreviousSession(string categoryId, bool consent = true)
 {
     if (!previousSessionCategories[CmpCampaignPopupQueue.CurrentCampaignToShow()].Exists(x => x._id.Equals(categoryId)))
     {
         foreach (var cat in CmpLocalizationMapper.CurrentCategories)
         {
             if (cat._id.Equals(categoryId))
             {
                 previousSessionCategories[CmpCampaignPopupQueue.CurrentCampaignToShow()].Add(new ConsentGdprSaveAndExitVariablesCategory(categoryId, cat.iabId, cat.type, consent, false));
                 break;
             }
         }
     }
 }
    public static void AcceptCategory(CmpCategoryModel model, bool consent = true)
    {
        var cat = new ConsentGdprSaveAndExitVariablesCategory(model._id, model.iabId, model.type, consent, false);

        if (!categories[CmpCampaignPopupQueue.CurrentCampaignToShow()].Exists(x => (x._id != null && cat._id != null && cat._id.Equals(x._id))))
        {
            categories[CmpCampaignPopupQueue.CurrentCampaignToShow()].Add(cat);
        }
        List <CmpCategoryConsentVendorModel> vendors = new List <CmpCategoryConsentVendorModel>();

        foreach (var vendor in model.requiringConsentVendors)
        {
            vendors.Add(vendor);
        }
        vendors.AddRange(model.legIntVendors);
        foreach (var vendor in vendors)
        {
            int?iabId = null;
            foreach (var v in CmpLocalizationMapper.CurrentVendors)
            {
                if (v.vendorId != null && v.vendorId.Equals(vendor.vendorId))
                {
                    if (v.iabId.HasValue)
                    {
                        iabId = v.iabId.Value;
                    }
                    v.accepted = consent;
                }
                //List init
                if (!categoryVendors[CmpCampaignPopupQueue.CurrentCampaignToShow()].ContainsKey(model._id))
                {
                    categoryVendors[CmpCampaignPopupQueue.CurrentCampaignToShow()][model._id] = new List <ConsentGdprSaveAndExitVariablesVendor>();
                }
                //Duplicate check
                if (!categoryVendors[CmpCampaignPopupQueue.CurrentCampaignToShow()][model._id].Exists(x => (x._id != null && vendor.vendorId != null && x._id.Equals(vendor.vendorId)) || (x.name != null && vendor.name != null && vendor.name.Equals(x.name))))
                {
                    categoryVendors[CmpCampaignPopupQueue.CurrentCampaignToShow()][model._id].Add(new ConsentGdprSaveAndExitVariablesVendor(vendor.vendorId, iabId, vendor.vendorType, true, false, vendor.name));
                    isAcceptedVendorsChanged = true;
                }
            }
        }
        foreach (var category in CmpLocalizationMapper.CurrentCategories)
        {
            if (category._id.Equals(model._id))
            {
                category.accepted = consent;
            }
        }
        isAcceptedCategoriesChanged = true;
    }
Exemple #12
0
    private void Start()
    {
        CmpNativeButtonUiController uiController = gameObject.GetComponent <CmpNativeButtonUiController>();
        Button butt = gameObject.GetComponent <Button>();

        if (CmpCampaignPopupQueue.CurrentCampaignToShow() == 2 && uiController.ID.Equals("DoNotSellButton"))
        {
            butt.onClick.AddListener(OnDoNotSellClick);
        }
        else if (uiController.ID.Equals("RejectAllButton"))
        {
            butt.onClick.AddListener(OnRejectAllClick);
        }
    }
Exemple #13
0
    public static bool IsCurrentCampaignPmInitialized()
    {
        var campaignId = CmpCampaignPopupQueue.CurrentCampaignToShow();

        switch (campaignId)
        {
        case 0:
            return(isGdprPmInitialized);

        case 2:
            return(isCcpaPmInitialized);

        default:
            return(false);
        }
    }
    public static ConsentGdprSaveAndExitVariablesSpecialFeature[] GetSpecialFeatures()
    {
        List <ConsentGdprSaveAndExitVariablesSpecialFeature> result = new List <ConsentGdprSaveAndExitVariablesSpecialFeature>();

        foreach (var kv in specFeatures[CmpCampaignPopupQueue.CurrentCampaignToShow()])
        {
            foreach (var specFeat in kv.Value)
            {
                if (!result.Exists(x => x._id.Equals(specFeat._id)))
                {
                    result.Add(specFeat);
                }
            }
        }
        return(result.ToArray());
    }
    private static string GetMessageUriWithQueryParams(int environment, string consentLanguage, string propertyId, string messageId)
    {
        // https://cdn.sp-stage.net/wrapper/v2/message/gdpr?env=stage&consentLanguage=en&propertyId=4933&messageId=16434
        string env          = environment == 0 ? "stage" : "prod";
        string campaignName = CmpCampaignPopupQueue.CurrentCampaignToShow() == 0 ? "gdpr" : "ccpa";

        return(BuildUriWithQuery(baseAdr: "https://cdn.sp-stage.net/wrapper/v2/",
                                 path: "wrapper/v2/message/" + campaignName,
                                 qParams: new Dictionary <string, string>()
        {
            { "env", env },
            { "consentLanguage", consentLanguage },
            { "propertyId", propertyId },
            { "messageId", messageId },
        }));
    }
    public static ConsentGdprSaveAndExitVariablesCategory[] GetAcceptedCategories()
    {
        List <ConsentGdprSaveAndExitVariablesCategory> result = new List <ConsentGdprSaveAndExitVariablesCategory>();

        foreach (var accepted in categories[CmpCampaignPopupQueue.CurrentCampaignToShow()])
        {
            result.Add(accepted);
        }
        foreach (var accepted in previousSessionCategories[CmpCampaignPopupQueue.CurrentCampaignToShow()])
        {
            if (!result.Exists(x => x._id.Equals(accepted._id)))
            {
                result.Add(accepted);
            }
        }
        return(result.ToArray());
    }
Exemple #17
0
    public static void Consent(int actionCode)
    {
        lastActionCode = actionCode;
        switch (actionCode)
        {
        case 1:
            ConsentSaveAndExitVariables saveAndExitVariables = null;
            switch (CmpCampaignPopupQueue.CurrentCampaignToShow())
            {
            case 0:
                saveAndExitVariables = new ConsentGdprSaveAndExitVariables(
                    language: language,
                    privacyManagerId: privacyManagerId,
                    categories: CmpPmSaveAndExitVariablesContext.GetAcceptedCategories(),
                    vendors: CmpPmSaveAndExitVariablesContext.GetAcceptedVendors(),
                    specialFeatures: CmpPmSaveAndExitVariablesContext.GetSpecialFeatures());
                break;

            case 2:
                saveAndExitVariables = new ConsentCcpaSaveAndExitVariables(
                    language: language,
                    privacyManagerId: privacyManagerId,
                    rejectedCategories: CmpPmSaveAndExitVariablesContext.GetAcceptedCategories(),
                    rejectedVendors: CmpPmSaveAndExitVariablesContext.GetAcceptedVendors(),
                    specialFeatures: CmpPmSaveAndExitVariablesContext.GetSpecialFeatures());
                break;
            }
            NetworkClient.Instance.Consent(actionType: actionCode,
                                           environment: environment,
                                           language: language,
                                           privacyManagerId: privacyManagerId,
                                           onSuccessAction: OnConsentSuccessCallback,
                                           onErrorAction: OnExceptionCallback,
                                           pmSaveAndExitVariables: saveAndExitVariables);
            break;

        default:
            NetworkClient.Instance.Consent(actionType: actionCode,
                                           environment: environment,
                                           language: language,
                                           privacyManagerId: privacyManagerId,
                                           onSuccessAction: OnConsentSuccessCallback,
                                           onErrorAction: OnExceptionCallback);
            break;
        }
    }
    public static void AcceptVendor(CmpVendorModel model, bool consent = true)
    {
        var vend = new ConsentGdprSaveAndExitVariablesVendor(model.vendorId, model.iabId, model.vendorType, consent, false, model.name);

        if (vendors[CmpCampaignPopupQueue.CurrentCampaignToShow()] != null
            // && (vendors[CmpCampaignPopupQueue.CurrentCampaignToShow()].Count>0
            && !vendors[CmpCampaignPopupQueue.CurrentCampaignToShow()].Exists(x =>
                                                                              (vend._id != null && x._id.Equals(vend._id)) || x.name.Equals(vend.name)))
        {
            vendors[CmpCampaignPopupQueue.CurrentCampaignToShow()].Add(vend);
        }
        if (model.iabSpecialFeatures != null)
        {
            foreach (var specFeat in model.iabSpecialFeatures)
            {
                //List init
                if (!specFeatures[CmpCampaignPopupQueue.CurrentCampaignToShow()].ContainsKey(model.vendorId))
                {
                    specFeatures[CmpCampaignPopupQueue.CurrentCampaignToShow()][model.vendorId] = new List <ConsentGdprSaveAndExitVariablesSpecialFeature>();
                }
                //Duplicate check
                if (!specFeatures[CmpCampaignPopupQueue.CurrentCampaignToShow()][model.vendorId].Exists(x => x._id.Equals(specFeat)))
                {
                    int?iabId = null;
                    foreach (var v in CmpLocalizationMapper.CurrentVendors)
                    {
                        if (v.vendorId.Equals(model.vendorId))
                        {
                            // v.accepted = true;
                            if (v.iabId.HasValue)
                            {
                                iabId = v.iabId.Value;
                            }
                            break;
                        }
                    }
                    specFeatures[CmpCampaignPopupQueue.CurrentCampaignToShow()][model.vendorId].Add(new ConsentGdprSaveAndExitVariablesSpecialFeature(specFeat, iabId));
                }
            }
        }
        isAcceptedVendorsChanged = true;
    }
    public static void ExcludeVendor(string id, string name)
    {
        ConsentGdprSaveAndExitVariablesVendor excluded = null;

        foreach (var vendor in vendors[CmpCampaignPopupQueue.CurrentCampaignToShow()])
        {
            if (vendor._id != null && vendor._id.Equals(id))
            {
                excluded = vendor;
                break;
            }
            else if (vendor.name != null && vendor.name.Equals(name))
            {
                excluded = vendor;
                break;
            }
        }
        if (excluded != null)
        {
            vendors[CmpCampaignPopupQueue.CurrentCampaignToShow()].Remove(excluded);
            if (excluded._id != null && specFeatures[CmpCampaignPopupQueue.CurrentCampaignToShow()].ContainsKey(excluded._id))
            {
                specFeatures[CmpCampaignPopupQueue.CurrentCampaignToShow()].Remove(excluded._id);
            }
        }
        foreach (var kv in categoryVendors[CmpCampaignPopupQueue.CurrentCampaignToShow()])
        {
            foreach (var vendor in kv.Value)
            {
                if (id != null && vendor._id != null && vendor._id.Equals(id))
                {
                    excluded = vendor;
                    break;
                }
            }
            kv.Value.Remove(excluded);
        }
        // foreach (var v in CmpLocalizationMapper.vendors)
        //     if (v.vendorId.Equals(id))
        //         v.accepted = false;
        isAcceptedVendorsChanged = true;
    }
    public static ConsentGdprSaveAndExitVariablesVendor[] GetAcceptedVendors()
    {
        List <ConsentGdprSaveAndExitVariablesVendor> resultList = new List <ConsentGdprSaveAndExitVariablesVendor>();

        foreach (var vend in vendors[CmpCampaignPopupQueue.CurrentCampaignToShow()])
        {
            resultList.Add(vend);
        }
        foreach (var kv in categoryVendors[CmpCampaignPopupQueue.CurrentCampaignToShow()])
        {
            foreach (var vendor in kv.Value)
            {
                if (vendor._id != null && !resultList.Exists(x => x._id.Equals(vendor._id)))
                {
                    resultList.Add(vendor);
                }
            }
        }
        return(resultList.ToArray());
    }
    public static bool IsCategoryAcceptedAnywhere(string categoryId)
    {
        bool result = false;

        foreach (var cat in categories[CmpCampaignPopupQueue.CurrentCampaignToShow()])
        {
            if (cat._id.Equals(categoryId) && cat.consent)
            {
                result = true;
            }
        }
        foreach (var cat in previousSessionCategories[CmpCampaignPopupQueue.CurrentCampaignToShow()])
        {
            if (cat._id.Equals(categoryId) && cat.consent)
            {
                result = true;
            }
        }
        return(result);
    }
 public static bool IsVendorAcceptedAnywhere(string vendorId)
 {
     foreach (var vendor in vendors[CmpCampaignPopupQueue.CurrentCampaignToShow()])
     {
         if (vendorId != null && vendorId.Equals(vendor._id))
         {
             return(true);
         }
     }
     foreach (var kv in categoryVendors[CmpCampaignPopupQueue.CurrentCampaignToShow()])
     {
         foreach (var vendor in kv.Value)
         {
             if (vendorId != null && vendorId.Equals(vendor._id))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #23
0
        public static void LoadPrivacyManager(GameObject cmpHomePrefab,
                                              Canvas canvas,
                                              CAMPAIGN_TYPE campaignType,
                                              string privacyManagerId,
                                              string propertyId)
        {
#if !UNITY_ANDROID || (!UNITY_IOS && UNITY_EDITOR_OSX)
            CmpLocalizationMapper.propertyId       = propertyId;
            CmpLocalizationMapper.privacyManagerId = privacyManagerId;
            CreateBroadcastExecutorGO();
            if (campaignType == CAMPAIGN_TYPE.GDPR)
            {
                CmpCampaignPopupQueue.EnqueueCampaignId(0);
            }
            else
            {
                CmpCampaignPopupQueue.EnqueueCampaignId(2);
            }
            CmpLocalizationMapper.Message();
            InstantiateHomePrefab(cmpHomePrefab, canvas);
#endif
        }
Exemple #24
0
    public static CmpUiElementModel GetCmpUiElement(string viewId, string uiElementId)
    {
        CmpUiElementModel result = null;

        // campaignType == GDPR = 0, CCPA = 2
        switch (CmpCampaignPopupQueue.CurrentCampaignToShow())
        {
        case 0:
            if (gdprElements != null && gdprElements.ContainsKey(viewId))
            {
                foreach (var uiElement in gdprElements[viewId])
                {
                    if (uiElement.id.Equals(uiElementId))
                    {
                        result = uiElement;
                        break;
                    }
                }
            }
            break;

        case 2:
            if (ccpaElements != null && ccpaElements.ContainsKey(viewId))
            {
                foreach (var uiElement in ccpaElements[viewId])
                {
                    if (uiElement.id.Equals(uiElementId))
                    {
                        result = uiElement;
                        break;
                    }
                }
            }
            break;
        }
        return(result);
    }
 private void MapLocalization()
 {
     foreach (var ui in uiElements)
     {
         if (CmpCampaignPopupQueue.CurrentCampaignToShow() == 2)
         {
             var controller = ui.gameObject.GetComponent <CmpNativeButtonUiController>();
             if (controller != null && controller.ID.Equals("RejectAllButton"))
             {
                 controller.SetId("DoNotSellButton");
             }
         }
         CmpUiElementModel initializer = CmpLocalizationMapper.GetCmpUiElement(viewId, ui.ID);
         if (initializer != null)
         {
             if (initializer is CmpTextModel txt)
             {
                 string str = txt.Text;
                 if (str.Contains("<p>"))
                 {
                     str = str.Replace("<p>", "");
                 }
                 if (str.Contains("</p>"))
                 {
                     str = str.Replace("</p>", "");
                 }
                 txt.SetText(str);
             }
             ui.SetLocalization(initializer);
         }
         else
         {
             Debug.LogError(">>>DAFUQ >:C " + ui.ID);
         }
     }
 }
    public void Consent(/*CONSENT_ACTION_TYPE == */ int actionType,
                        int environment,
                        string language,
                        string privacyManagerId,
                        Action <string> onSuccessAction,
                        Action <Exception> onErrorAction,
                        ConsentSaveAndExitVariables pmSaveAndExitVariables = null)
    {
        var dict = new Dictionary <string, string> {
            { "type", "RecordString" }
        };
        var includeData = new IncludeDataPostGetMessagesRequest()
        {
            localState = dict,
            TCData     = dict
                         // messageMetaData = dict,
        };
        ConsentSaveAndExitVariables concretePmSaveAndExitVariables;
        PostConsentRequest          body = null;

        switch (CmpCampaignPopupQueue.CurrentCampaignToShow())
        {
        case 0:
            if (pmSaveAndExitVariables != null)
            {
                concretePmSaveAndExitVariables = pmSaveAndExitVariables as ConsentGdprSaveAndExitVariables;
            }
            else
            {
                concretePmSaveAndExitVariables = new ConsentGdprSaveAndExitVariables(
                    language: language,
                    privacyManagerId: privacyManagerId,
                    categories: new ConsentGdprSaveAndExitVariablesCategory[] { },
                    vendors: new ConsentGdprSaveAndExitVariablesVendor[] { },
                    specialFeatures: new ConsentGdprSaveAndExitVariablesSpecialFeature[] { }
                    );
            }
            body = new PostConsentGdprRequest(
                requestUUID: GUID.Value,
                idfaStatus: "accepted",
                localState: SaveContext.GetLocalState(),
                includeData: includeData,
                pmSaveAndExitVariables: (ConsentGdprSaveAndExitVariables)concretePmSaveAndExitVariables
                );
            break;

        case 2:
            if (pmSaveAndExitVariables != null)
            {
                //remove if vendor._id == null
                concretePmSaveAndExitVariables = pmSaveAndExitVariables as ConsentCcpaSaveAndExitVariables;
                List <ConsentGdprSaveAndExitVariablesVendor> rej = new List <ConsentGdprSaveAndExitVariablesVendor>();
                foreach (var rejected in (pmSaveAndExitVariables as ConsentCcpaSaveAndExitVariables).rejectedVendors)
                {
                    if (!string.IsNullOrEmpty(rejected._id))
                    {
                        rej.Add(rejected);
                    }
                }
                (concretePmSaveAndExitVariables as ConsentCcpaSaveAndExitVariables).rejectedVendors = rej.ToArray();
            }
            else
            {
                concretePmSaveAndExitVariables = new ConsentCcpaSaveAndExitVariables(
                    language: language,
                    privacyManagerId: privacyManagerId,
                    rejectedCategories: new ConsentGdprSaveAndExitVariablesCategory[] { },
                    rejectedVendors: new ConsentGdprSaveAndExitVariablesVendor[] { },
                    specialFeatures: new ConsentGdprSaveAndExitVariablesSpecialFeature[] { }
                    );
            }
            body = new PostConsentCcpaRequest(
                requestUUID: GUID.Value,
                idfaStatus: "accepted",
                localState: SaveContext.GetLocalState(),
                includeData: includeData,
                pmSaveAndExitVariables: (ConsentCcpaSaveAndExitVariables)concretePmSaveAndExitVariables
                );
            break;
        }

        if (body == null)
        {
            onErrorAction?.Invoke(new Exception("Message body is null!!!"));
        }
        else
        {
            Task.Factory.StartNew(async delegate { await PostConsent(actionType, environment, body, onSuccessAction, onErrorAction); });
        }
    }
Exemple #27
0
    private static void OnGetMessagesSuccessCallback(string json)
    {
        GetMessageResponse messages = NativeUiJsonDeserializer.DeserializeGetMessages(json);

        SaveContext.SaveCampaigns(messages.campaigns);
        SaveContext.SaveLocalState(messages.localState);
        SaveContext.SavePropertyId(messages.propertyId);
        var gdprCamp = messages.GetGdprCampaign();
        var ccpaCamp = messages.GetCcpaCampaign();

        if (gdprCamp != null)
        {
            if (gdprCamp?.message == null || gdprCamp.ui == null || gdprCamp.ui.Count == 0)
            {
                if (gdprCamp.userConsent == null)
                {
                    UnityEngine.Debug.LogError("UserConsent is NULL");
                }
                else
                {
                    gdprUserConsent = new PostConsentUserConsent()
                    {
                        TCData = gdprCamp.userConsent.TCData,
                        grants = gdprCamp.userConsent.grants,
                        // specialFeatures = gdprCamp.userConsent.,
                        // legIntCategories = gdprCamp.userConsent.,
                        // acceptedVendors = gdprCamp.userConsent.,
                        // acceptedCategories = gdprCamp.userConsent.,
                        euconsent      = gdprCamp.userConsent.euconsent,
                        addtlConsent   = gdprCamp.userConsent.addtlConsent,
                        dateCreated    = gdprCamp.userConsent.dateCreated,
                        consentedToAll = gdprCamp.userConsent.consentedToAll.GetValueOrDefault(false)
                    };
                    SaveContext.SaveGdprUserConsent(gdprUserConsent);
                    CmpCampaignPopupQueue.DequeueCampaignId();
                    isGdprConsented = true;
                }
            }
            else
            {
                GdprMessage gdpr = gdprCamp?.message;
                shortCategories = gdpr?.categories;
                popupBgColors   = gdprCamp?.popupBgColors;
                gdprElements    = gdprCamp?.ui;
            }
        }
        if (ccpaCamp != null)
        {
            if (ccpaCamp.userConsent != null && (!ccpaCamp.userConsent.newUser || ccpaCamp.userConsent.rejectedAll || ccpaCamp.userConsent.status.Equals("consentedAll")))
            {
                ccpaUserConsent = new PostConsentUserConsent()
                {
                    uspstring          = ccpaCamp.userConsent.uspstring,
                    status             = ccpaCamp.userConsent.status,
                    rejectedVendors    = ccpaCamp.userConsent.rejectedVendors.ToArray(),
                    rejectedCategories = ccpaCamp.userConsent.rejectedCategories.ToArray(),
                    signedLspa         = ccpaCamp.userConsent.signedLspa,
                    rejectedAll        = ccpaCamp.userConsent.rejectedAll,
                };
                SaveContext.SaveCcpaUserConsent(ccpaUserConsent);
                CmpCampaignPopupQueue.DequeueCampaignId();
                isCcpaConsented = true;
            }
            else if (ccpaCamp?.message != null || ccpaCamp.ui != null || ccpaCamp.ui.Count != 0)
            {
                BaseMessage ccpa = ccpaCamp?.message;
                popupBgColors = ccpaCamp.popupBgColors;
                ccpaElements  = ccpaCamp.ui;
                // shortCategories ??
            }
            else if (ccpaCamp.userConsent == null)
            {
                UnityEngine.Debug.LogError("UserConsent is NULL");
            }
        }
        isInitialized = true;
        if (!CmpCampaignPopupQueue.IsCampaignAvailable)
        {
            CmpPopupDestroyer.DestroyAllHelperGO();
        }
    }
    public static void ExcludeCategory(string id, bool consented = false)
    {
        ConsentGdprSaveAndExitVariablesCategory excluded = null;

        foreach (var cat in categories[CmpCampaignPopupQueue.CurrentCampaignToShow()])
        {
            if (cat._id.Equals(id))
            {
                excluded = cat;
            }
        }
        if (excluded != null)
        {
            categories[CmpCampaignPopupQueue.CurrentCampaignToShow()].Remove(excluded);
            if (categoryVendors[CmpCampaignPopupQueue.CurrentCampaignToShow()].ContainsKey(excluded._id) && categoryVendors[CmpCampaignPopupQueue.CurrentCampaignToShow()][excluded._id] != null)
            {
                categoryVendors[CmpCampaignPopupQueue.CurrentCampaignToShow()].Remove(excluded._id);
                isAcceptedVendorsChanged = true;
            }
        }
        foreach (var category in CmpLocalizationMapper.CurrentCategories)
        {
            if (category._id.Equals(id))
            {
                category.accepted = consented;
                if (categoryVendors[CmpCampaignPopupQueue.CurrentCampaignToShow()].ContainsKey(category._id) && categoryVendors[CmpCampaignPopupQueue.CurrentCampaignToShow()][category._id] != null)
                {
                    categoryVendors[CmpCampaignPopupQueue.CurrentCampaignToShow()].Remove(category._id);
                    isAcceptedVendorsChanged = true;
                }
                List <CmpCategoryConsentVendorModel> vendoritos = new List <CmpCategoryConsentVendorModel>();
                vendoritos.AddRange(category.legIntVendors);
                vendoritos.AddRange(category.disclosureOnlyVendors);
                vendoritos.AddRange(category.requiringConsentVendors);
                ConsentGdprSaveAndExitVariablesVendor vendo = null;
                foreach (var vendorez in vendoritos)
                {
                    if (vendors[CmpCampaignPopupQueue.CurrentCampaignToShow()].Exists(x => x._id != null && vendorez.vendorId != null && vendorez.vendorId.Equals(x._id)))
                    {
                        vendo = vendors[CmpCampaignPopupQueue.CurrentCampaignToShow()].Find(x =>
                                                                                            x._id != null && vendorez.vendorId != null && vendorez.vendorId.Equals(x._id));
                    }
                }
                if (vendo != null)
                {
                    if (CmpLocalizationMapper.CurrentVendors != null)
                    {
                        foreach (var vendor in CmpLocalizationMapper.CurrentVendors)
                        {
                            if (vendor.vendorId != null && vendo._id != null && vendo._id.Equals(vendor.vendorId) ||
                                vendor.name.Equals(vendo.name))
                            {
                                vendor.accepted = consented;
                            }
                        }
                    }
                    vendors[CmpCampaignPopupQueue.CurrentCampaignToShow()].Remove(vendo);
                    isAcceptedVendorsChanged = true;
                }
                break;
            }
        }
        ConsentGdprSaveAndExitVariablesCategory excluded2 = null;

        foreach (var cat in previousSessionCategories[CmpCampaignPopupQueue.CurrentCampaignToShow()])
        {
            if (cat._id.Equals(id))
            {
                excluded2 = cat;
            }
        }
        if (excluded2 != null)
        {
            previousSessionCategories[CmpCampaignPopupQueue.CurrentCampaignToShow()].Remove(excluded2);
        }
        isAcceptedCategoriesChanged = true;
    }
    public static void UpdateUserConsentUIState()
    {
        string key = userConsentKey;

        switch (CmpCampaignPopupQueue.CurrentCampaignToShow())
        {
        case 0:
            key += gdprKey;
            break;

        case 2:
            key += ccpaKey;
            break;
        }
        var userConsent = saver.GetUserConsent(key);
        Dictionary <string, SpGetMessagesVendorGrant> grants = userConsent?.grants;

        if (key.Equals(userConsentKey + gdprKey) && grants == null)
        {
            return;
        }
        if (key.Equals(userConsentKey + ccpaKey))
        {
            //CCPA
            var rejectedC = userConsent.rejectedCategories;
            var rejectedV = userConsent.rejectedVendors;
            if (rejectedC != null && CmpLocalizationMapper.CurrentCategories != null)
            {
                foreach (var categoryId in rejectedC)
                {
                    //accepting category
                    foreach (var cat in CmpLocalizationMapper.CurrentCategories)
                    {
                        if (cat._id.Equals(categoryId))
                        {
                            cat.accepted = false;
                            CmpPmSaveAndExitVariablesContext.AcceptCategoryFromPreviousSession(cat._id, false);
                            break;
                        }
                    }
                    //accepting vendor if at least 1 category is accepted
                    // if (CmpLocalizationMapper.CurrentVendors != null)
                    // {
                    //     foreach (var vendor in CmpLocalizationMapper.CurrentVendors)
                    //     {
                    //         vendor.
                    //         if (vendor.vendorId != null && vendor.vendorId.Equals(vendorId))
                    //         {
                    //             // vendor.accepted = true; //TODO
                    //             // CmpPmSaveAndExitVariablesContext.AcceptVendor(vendor);
                    //             break;
                    //         }
                    //     }
                    // }
                }
            }
            if (rejectedV != null && CmpLocalizationMapper.CurrentVendors != null)
            {
                foreach (var vendorId in rejectedV)
                {
                    foreach (var vendor in CmpLocalizationMapper.CurrentVendors)
                    {
                        if (vendor.vendorId != null && vendor.vendorId.Equals(vendorId))
                        {
                            vendor.accepted = false;
                            CmpPmSaveAndExitVariablesContext.AcceptVendor(vendor, false);
                            break;
                        }
                    }
                }
            }
        }
        else
        {
            //GDPR
            foreach (var kv in grants)
            {
                if (CmpLocalizationMapper.CurrentVendors != null && kv.Value.vendorGrant)
                {
                    var vendorId = kv.Key;
                    foreach (var vendor in CmpLocalizationMapper.CurrentVendors)
                    {
                        if (vendor.vendorId != null && vendor.vendorId.Equals(vendorId))
                        {
                            vendor.accepted = true;
                            CmpPmSaveAndExitVariablesContext.AcceptVendor(vendor);
                            break;
                        }
                    }
                }
                foreach (var kvPups in kv.Value.purposeGrants)
                {
                    if (CmpLocalizationMapper.CurrentCategories != null && kvPups.Value)
                    {
                        //accepting category
                        var categoryId = kvPups.Key;
                        foreach (var cat in CmpLocalizationMapper.CurrentCategories)
                        {
                            if (cat._id.Equals(categoryId))
                            {
                                cat.accepted = true;
                                CmpPmSaveAndExitVariablesContext.AcceptCategoryFromPreviousSession(cat._id);
                                break;
                            }
                        }
                        //accepting vendor if at least 1 category is accepted
                        if (CmpLocalizationMapper.CurrentVendors != null)
                        {
                            var vendorId = kv.Key;
                            foreach (var vendor in CmpLocalizationMapper.CurrentVendors)
                            {
                                if (vendor.vendorId != null && vendor.vendorId.Equals(vendorId))
                                {
                                    vendor.accepted = true;
                                    CmpPmSaveAndExitVariablesContext.AcceptVendor(vendor);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Exemple #30
0
        public static void Initialize(List <SpCampaign> spCampaigns,
                                      int accountId,
                                      string propertyName,
                                      MESSAGE_LANGUAGE language,
                                      CAMPAIGN_ENV campaignsEnvironment,
                                      long messageTimeoutInSeconds = 3)
        {
            if (!IsSpCampaignsValid(spCampaigns))
            {
                return;
            }
            CreateBroadcastExecutorGO();
#if UNITY_ANDROID && !UNITY_EDITOR
            if (Application.platform == RuntimePlatform.Android)
            {
                //excluding ios14 campaign if any
                RemoveIos14SpCampaign(ref spCampaigns);
                if (!IsSpCampaignsValid(spCampaigns))
                {
                    return;
                }
                ConsentWrapperAndroid.Instance.InitializeLib(spCampaigns: spCampaigns,
                                                             accountId: accountId,
                                                             propertyName: propertyName,
                                                             language: language,
                                                             campaignsEnvironment: campaignsEnvironment,
                                                             messageTimeoutMilliSeconds: messageTimeoutInSeconds * 1000);
            }
#elif UNITY_IOS && !UNITY_EDITOR_OSX
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                ConsentWrapperIOS.Instance.InitializeLib(spCampaigns: spCampaigns,
                                                         accountId: accountId,
                                                         propertyName: propertyName,
                                                         language: language,
                                                         campaignsEnvironment: campaignsEnvironment,
                                                         messageTimeoutInSeconds: messageTimeoutInSeconds);
            }
#else
            CmpLocalizationMapper.language = CSharp2JavaStringEnumMapper.GetMessageLanguageKey(language);
            SingleCampaignPostGetMessagesRequest gdprTargetingParams = null;
            SpCampaign gdpr = spCampaigns.Find(x => x.CampaignType == CAMPAIGN_TYPE.GDPR);
            if (gdpr != null)
            {
                CmpCampaignPopupQueue.EnqueueCampaignId(0);
                Dictionary <string, string> tarParams = new Dictionary <string, string>();
                foreach (var param in gdpr.TargetingParams)
                {
                    tarParams[param.Key] = param.Value;
                }
                gdprTargetingParams = new SingleCampaignPostGetMessagesRequest(tarParams);
            }
            SingleCampaignPostGetMessagesRequest ccpaTargetingParams = null;
            SpCampaign ccpa = spCampaigns.Find(x => x.CampaignType == CAMPAIGN_TYPE.CCPA);
            if (ccpa != null)
            {
                CmpCampaignPopupQueue.EnqueueCampaignId(2);
                Dictionary <string, string> tarParams = new Dictionary <string, string>();
                foreach (var param in ccpa.TargetingParams)
                {
                    tarParams[param.Key] = param.Value;
                }
                ccpaTargetingParams = new SingleCampaignPostGetMessagesRequest(tarParams);
            }
            CmpLocalizationMapper.GetMessages(accountId: accountId,
                                              propertyHref: propertyName,
                                              gdpr: gdprTargetingParams,
                                              ccpa: ccpaTargetingParams,
                                              environment: (int)campaignsEnvironment,
                                              millisTimeout: Convert.ToInt32(messageTimeoutInSeconds * 1000));
#endif
        }