public void TestValidateBusinessEvent()
        {
            // Store result
            bool isValid;

            // Valid business events
            isValid = GAValidator.ValidateBusinessEvent("USD", 99, "cartType", "itemType", "itemId");
            Assert.True(isValid, "Valid business event should succeed");

            // Should allow false carttype (optional)
            isValid = GAValidator.ValidateBusinessEvent("USD", 99, "", "itemType", "itemId");
            Assert.True(isValid, "Business event cartType should be optional");

            // Should allow 0 amount
            isValid = GAValidator.ValidateBusinessEvent("USD", 0, "", "itemType", "itemId");
            Assert.True(isValid, "Business event should allow amount 0");

            // Should allow negative amount
            isValid = GAValidator.ValidateBusinessEvent("USD", -99, "", "itemType", "itemId");
            Assert.True(isValid, "Business event should allow amount less than 0");

            // Should fail on empty item type
            isValid = GAValidator.ValidateBusinessEvent("USD", 99, "", "", "itemId");
            Assert.False(isValid, "Business event should not allow empty item type");

            // Should fail on empty item id
            isValid = GAValidator.ValidateBusinessEvent("USD", 99, "", "itemType", "");
            Assert.False(isValid, "Business event should not allow empty item id");
        }
Exemple #2
0
        public static void AddBusinessEvent(
            string currency,
            int amount,
            string itemType,
            string itemId,
            string cartType,
            IDictionary <string, object> fields
            )
        {
            if (!GAState.IsEventSubmissionEnabled)
            {
                return;
            }

            // Validate event params
            if (!GAValidator.ValidateBusinessEvent(currency, amount, cartType, itemType, itemId))
            {
                //GAHTTPApi.Instance.SendSdkErrorEvent(EGASdkErrorType.Rejected);
                return;
            }

            // Create empty eventData
            JSONObject eventDict = new JSONObject();

            // Increment transaction number and persist
            GAState.IncrementTransactionNum();
            GAStore.SetState(GAState.TransactionNumKey, GAState.TransactionNum.ToString(CultureInfo.InvariantCulture));

            // Required
            eventDict["event_id"] = itemType + ":" + itemId;
            eventDict["category"] = CategoryBusiness;
            eventDict["currency"] = currency;
            eventDict.Add("amount", new JSONNumber(amount));
            eventDict.Add(GAState.TransactionNumKey, new JSONNumber(GAState.TransactionNum));

            // Optional
            if (!string.IsNullOrEmpty(cartType))
            {
                eventDict.Add("cart_type", cartType);
            }

            // Add custom dimensions
            AddDimensionsToEvent(eventDict);

            // Add custom fields
            AddFieldsToEvent(eventDict, GAState.ValidateAndCleanCustomFields(fields));

            // Log
            GALogger.I("Add BUSINESS event: {currency:" + currency + ", amount:" + amount + ", itemType:" + itemType + ", itemId:" + itemId + ", cartType:" + cartType + "}");

            // Send to store
            AddEventToStore(eventDict);
        }
Exemple #3
0
        public static void AddBusinessEvent(string currency, int amount, string itemType, string itemId, string cartType, IDictionary <string, object> fields)
        {
            string fieldsAsString = DictionaryToJsonString(fields);

#if UNITY_EDITOR
            if (GAValidator.ValidateBusinessEvent(currency, amount, cartType, itemType, itemId))
            {
                addBusinessEvent(currency, amount, itemType, itemId, cartType, fieldsAsString);
            }
#else
            addBusinessEvent(currency, amount, itemType, itemId, cartType, fieldsAsString);
#endif
        }