public static void AddResourceEvent(EGAResourceFlowType flowType, string currency, double amount, string itemType, string itemId) { // Validate event params if (!GAValidator.ValidateResourceEvent(flowType, currency, (long)amount, itemType, itemId)) { GAHTTPApi.Instance.SendSdkErrorEvent(EGASdkErrorType.Rejected); return; } // If flow type is sink reverse amount if (flowType == EGAResourceFlowType.Sink) { amount *= -1; } // Create empty eventData JSONClass eventDict = new JSONClass(); // insert event specific values string flowTypeString = ResourceFlowTypeToString(flowType); eventDict["event_id"] = flowTypeString + ":" + currency + ":" + itemType + ":" + itemId; eventDict["category"] = CategoryResource; eventDict.Add("amount", new JSONData(amount)); // Add custom dimensions AddDimensionsToEvent(eventDict); // Log GALogger.I("Add RESOURCE event: {currency:" + currency + ", amount:" + amount + ", itemType:" + itemType + ", itemId:" + itemId + "}"); // Send to store AddEventToStore(eventDict); }
public static void AddResourceEvent(EGAResourceFlowType flowType, string currency, double amount, string itemType, string itemId, IDictionary <string, object> fields, bool mergeFields) { if (!GAState.IsEventSubmissionEnabled) { return; } // Validate event params if (!GAValidator.ValidateResourceEvent(flowType, currency, (long)amount, itemType, itemId)) { //GAHTTPApi.Instance.SendSdkErrorEvent(EGASdkErrorType.Rejected); return; } // If flow type is sink reverse amount if (flowType == EGAResourceFlowType.Sink) { amount *= -1; } // Create empty eventData JSONObject eventDict = new JSONObject(); // insert event specific values string flowTypeString = ResourceFlowTypeToString(flowType); eventDict["event_id"] = flowTypeString + ":" + currency + ":" + itemType + ":" + itemId; eventDict["category"] = CategoryResource; eventDict.Add("amount", new JSONNumber(amount)); // Add custom dimensions AddDimensionsToEvent(eventDict); IDictionary <string, object> fieldsToUse = new Dictionary <string, object>(fields != null && fields.Count > 0 ? fields : GAState.CurrentGlobalCustomEventFields); if (mergeFields && fields != null && fields.Count > 0) { foreach (KeyValuePair <string, object> pair in GAState.CurrentGlobalCustomEventFields) { if (!fieldsToUse.ContainsKey(pair.Key)) { fieldsToUse.Add(pair.Key, pair.Value); } } } // Add custom fields AddFieldsToEvent(eventDict, GAState.ValidateAndCleanCustomFields(fieldsToUse)); // Log GALogger.I("Add RESOURCE event: {currency:" + currency + ", amount:" + amount + ", itemType:" + itemType + ", itemId:" + itemId + "}"); // Send to store AddEventToStore(eventDict); }
public static void AddResourceEvent(GAResourceFlowType flowType, string currency, float amount, string itemType, string itemId, IDictionary <string, object> fields) { string fieldsAsString = DictionaryToJsonString(fields); #if UNITY_EDITOR if (GAValidator.ValidateResourceEvent(flowType, currency, amount, itemType, itemId)) { addResourceEvent((int)flowType, currency, amount, itemType, itemId, fieldsAsString); } #else addResourceEvent((int)flowType, currency, amount, itemType, itemId, fieldsAsString); #endif }
public void TestValidateResourceSinkEvent() { // Set available list GAState.AvailableResourceCurrencies = new string[] { "gems", "gold" }; GAState.AvailableResourceItemTypes = new string[] { "guns", "powerups" }; // Store result bool isValid; // Valid resource source events isValid = GAValidator.ValidateResourceEvent(EGAResourceFlowType.Sink, "gems", 100, "guns", "item"); Assert.True(isValid, "Valid resource source event should succeed"); // Valid resource source events isValid = GAValidator.ValidateResourceEvent(EGAResourceFlowType.Sink, "gold", 100, "powerups", "item"); Assert.True(isValid, "Valid resource source event should succeed"); // falset defined resource type should fail isValid = GAValidator.ValidateResourceEvent(EGAResourceFlowType.Sink, "iron", 100, "guns", "item"); Assert.False(isValid, "Resource event should falset allow falsen defined resource types"); // falset defined item type should fail isValid = GAValidator.ValidateResourceEvent(EGAResourceFlowType.Sink, "gems", 100, "cows", "item"); Assert.False(isValid, "Resource event should falset allow falsen defined item types"); // Should falset allow 0 amount isValid = GAValidator.ValidateResourceEvent(EGAResourceFlowType.Sink, "gems", 0, "guns", "item"); Assert.False(isValid, "Resource event should falset allow 0 amount"); // Should falset allow negative amount isValid = GAValidator.ValidateResourceEvent(EGAResourceFlowType.Sink, "gems", -10, "guns", "item"); Assert.False(isValid, "Resource event should falset allow negative amount"); // Should falset allow false item id isValid = GAValidator.ValidateResourceEvent(EGAResourceFlowType.Sink, "gems", 10, "guns", ""); Assert.False(isValid, "Resource event should falset allow empty item id"); isValid = GAValidator.ValidateResourceEvent(EGAResourceFlowType.Sink, "gems", 10, "guns", null); Assert.False(isValid, "Resource event should falset allow empty item id"); // Should falset allow false item type isValid = GAValidator.ValidateResourceEvent(EGAResourceFlowType.Sink, "gems", 10, "", "item"); Assert.False(isValid, "Resource event should falset allow empty item id"); isValid = GAValidator.ValidateResourceEvent(EGAResourceFlowType.Sink, "gems", 10, null, "item"); Assert.False(isValid, "Resource event should falset allow empty item id"); }