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);
        }
示例#2
0
        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 bool ValidateResourceEvent(EGAResourceFlowType flowType, string currency, long amount, string itemType, string itemId)
 {
     if (flowType == EGAResourceFlowType.Undefined)
     {
         GALogger.I("Validation fail - resource event - flowType: Invalid flow type.");
         return(false);
     }
     if (string.IsNullOrEmpty(currency))
     {
         GALogger.I("Validation fail - resource event - currency: Cannot be (null)");
         return(false);
     }
     if (!GAState.HasAvailableResourceCurrency(currency))
     {
         GALogger.I("Validation fail - resource event - currency: Not found in list of pre-defined available resource currencies. String: " + currency);
         return(false);
     }
     if (!(amount > 0))
     {
         GALogger.I("Validation fail - resource event - amount: Float amount cannot be 0 or negative. Value: " + amount);
         return(false);
     }
     if (string.IsNullOrEmpty(itemType))
     {
         GALogger.I("Validation fail - resource event - itemType: Cannot be (null)");
         return(false);
     }
     if (!ValidateEventPartLength(itemType, false))
     {
         GALogger.I("Validation fail - resource event - itemType: Cannot be (null), empty or above 64 characters. String: " + itemType);
         return(false);
     }
     if (!ValidateEventPartCharacters(itemType))
     {
         GALogger.I("Validation fail - resource event - itemType: Cannot contain other characters than A-z, 0-9, -_., ()!?. String: " + itemType);
         return(false);
     }
     if (!GAState.HasAvailableResourceItemType(itemType))
     {
         GALogger.I("Validation fail - resource event - itemType: Not found in list of pre-defined available resource itemTypes. String: " + itemType);
         return(false);
     }
     if (!ValidateEventPartLength(itemId, false))
     {
         GALogger.I("Validation fail - resource event - itemId: Cannot be (null), empty or above 64 characters. String: " + itemId);
         return(false);
     }
     if (!ValidateEventPartCharacters(itemId))
     {
         GALogger.I("Validation fail - resource event - itemId: Cannot contain other characters than A-z, 0-9, -_., ()!?. String: " + itemId);
         return(false);
     }
     return(true);
 }
示例#4
0
        public static void AddResourceEvent(EGAResourceFlowType flowType, string currency, float amount, string itemType, string itemId)
        {
            GADevice.UpdateConnectionType();

            GAThreading.PerformTaskOnGAThread("addResourceEvent", () =>
            {
                if (!IsSdkReady(true, true, "Could not add resource event"))
                {
                    return;
                }

                GAEvents.AddResourceEvent(flowType, currency, amount, itemType, itemId);
            });
        }
示例#5
0
        public static void AddResourceEvent(EGAResourceFlowType flowType, string currency, float amount, string itemType, string itemId, IDictionary <string, object> customFields = null, bool mergeFields = false)
        {
            if (_endThread)
            {
                return;
            }

            GADevice.UpdateConnectionType();

            GAThreading.PerformTaskOnGAThread("addResourceEvent", () =>
            {
                if (!IsSdkReady(true, true, "Could not add resource event"))
                {
                    return;
                }

                GAEvents.AddResourceEvent(flowType, currency, amount, itemType, itemId, customFields, mergeFields);
            });
        }
        private static string ResourceFlowTypeToString(EGAResourceFlowType value)
        {
            switch (value)
            {
            case EGAResourceFlowType.Source:
            {
                return("Source");
            }

            case EGAResourceFlowType.Sink:
            {
                return("Sink");
            }

            default:
            {
                return("");
            }
            }
        }