protected void RegisterAction(JSONObject action, string id)
            {
                object typeObj, valueObj;

                if (action.TryGetValue("type", out typeObj))
                {
                    action.TryGetValue("value", out valueObj);

                    EventArgs eventArgs = EventArgs.Create(
                        DDNA.Instance.Platform, id, (string)typeObj, valueObj);

                    GameEvent actionEvent = new GameEvent("imageMessageAction");
                    if (imageMessage.engagement.JSON.ContainsKey("eventParams"))
                    {
                        var eventParams = imageMessage.engagement.JSON["eventParams"] as Dictionary <string, object>;
                        actionEvent.AddParam("responseDecisionpointName", eventParams["responseDecisionpointName"]);
                        actionEvent.AddParam("responseEngagementID", eventParams["responseEngagementID"]);
                        actionEvent.AddParam("responseEngagementName", eventParams["responseEngagementName"]);
                        actionEvent.AddParam("responseEngagementType", eventParams["responseEngagementType"]);
                        actionEvent.AddParam("responseMessageSequence", eventParams["responseMessageSequence"]);
                        actionEvent.AddParam("responseVariantName", eventParams["responseVariantName"]);
                        actionEvent.AddParam("responseTransactionID", eventParams["responseTransactionID"]);
                    }

                    actionEvent.AddParam("imActionName", id);
                    actionEvent.AddParam("imActionType", (string)typeObj);
                    if (!string.IsNullOrEmpty(eventArgs.ActionValue) &&
                        (string)typeObj != "dismiss")
                    {
                        actionEvent.AddParam("imActionValue", eventArgs.ActionValue);
                    }

                    switch ((string)typeObj)
                    {
                    case "none": {
                        actions.Add(() => {});
                        break;
                    }

                    case "action": {
                        actions.Add(() => {
                                if (valueObj != null)
                                {
                                    if (imageMessage.OnAction != null)
                                    {
                                        imageMessage.OnAction(eventArgs);
                                    }
                                }

                                ddna.RecordEvent(actionEvent);
                                imageMessage.Close();
                            });
                        break;
                    }

                    case "link": {
                        actions.Add(() => {
                                if (imageMessage.OnAction != null)
                                {
                                    imageMessage.OnAction(eventArgs);
                                }
                                if (valueObj != null)
                                {
                                    Application.OpenURL((string)valueObj);
                                }

                                ddna.RecordEvent(actionEvent);
                                imageMessage.Close();
                            });
                        break;
                    }

                    case "store": {
                        actions.Add(() => {
                                if (imageMessage.OnStore != null)
                                {
                                    imageMessage.OnStore(eventArgs);
                                }

                                ddna.RecordEvent(actionEvent);
                                imageMessage.Close();
                            });
                        break;
                    }

                    default: {      // "dismiss"
                        actions.Add(() => {
                                if (imageMessage.OnDismiss != null)
                                {
                                    imageMessage.OnDismiss(eventArgs);
                                }

                                ddna.RecordEvent(actionEvent);
                                imageMessage.Close();
                            });
                        break;
                    }
                    }
                }
            }
Exemplo n.º 2
0
 internal static EventAction CreateEmpty(GameEvent evnt)
 {
     return(new EventAction(evnt, EMPTY_TRIGGERS));
 }
Exemplo n.º 3
0
        internal virtual bool Evaluate(GameEvent evnt)
        {
            if (limit != -1 && runs >= limit)
            {
                return(false);
            }
            if (evnt.Name != eventName)
            {
                return(false);
            }

            var parameters = evnt.parameters.AsDictionary();
            var stack      = new Stack <object>();

            foreach (var token in condition)
            {
                if (token.ContainsKey("o"))
                {
                    string op    = (string)token["o"];
                    object right = stack.Pop();
                    object left  = stack.Pop();

                    try {
                        if (right is bool)
                        {
                            if (left is bool)
                            {
                                stack.Push(BOOLS[op]((bool)left, (bool)right));
                            }
                            else
                            {
                                Logger.LogWarning(
                                    left + " and " + right + " have mismatched types");
                                return(false);
                            }
                        }
                        else if (right is long)
                        {
                            if (left is int)
                            {
                                stack.Push(LONGS[op]((int)left, (long)right));
                            }
                            else if (left is long)
                            {
                                stack.Push(LONGS[op]((long)left, (long)right));
                            }
                            else
                            {
                                Logger.LogWarning(
                                    left + " and " + right + " have mismatched types");
                                return(false);
                            }
                        }
                        else if (right is double)
                        {
                            if (left is float)
                            {
                                stack.Push(DOUBLES[op]((float)left, (double)right));
                            }
                            else if (left is double)
                            {
                                stack.Push(DOUBLES[op]((double)left, (double)right));
                            }
                            else
                            {
                                Logger.LogWarning(
                                    left + " and " + right + " have mismatched types");
                                return(false);
                            }
                        }
                        else if (right is string)
                        {
                            if (left is string)
                            {
                                stack.Push(STRINGS[op]((string)left, (string)right));
                            }
                            else
                            {
                                Logger.LogWarning(
                                    left + " and " + right + " have mismatched types");
                                return(false);
                            }
                        }
                        else if (right is DateTime)
                        {
                            if (left is string)
                            {
                                stack.Push(DATES[op](
                                               DateTime.ParseExact(
                                                   (string)left,
                                                   Settings.EVENT_TIMESTAMP_FORMAT,
                                                   System.Globalization.CultureInfo.InvariantCulture),
                                               (DateTime)right));
                            }
                            else
                            {
                                Logger.LogWarning(
                                    left + " and " + right + " have mismatched types");
                                return(false);
                            }
                        }
                        else
                        {
                            Logger.LogWarning("Unexpected type for " + right);
                            return(false);
                        }
                    } catch (KeyNotFoundException) {
                        Logger.LogWarning(string.Format(
                                              "Failed to find operation {0} for {1} and {2}",
                                              op,
                                              left,
                                              right));
                        return(false);
                    } catch (FormatException) {
                        Logger.LogWarning("Failed converting parameter " + left + " to DateTime");
                        return(false);
                    }
                }
                else if (token.ContainsKey("p"))
                {
                    var param = (string)token["p"];
                    if (parameters.ContainsKey(param))
                    {
                        stack.Push(parameters[param]);
                    }
                    else
                    {
                        Logger.LogWarning("Failed to find " + param + " in event params");
                        return(false);
                    }
                }
                else if (token.ContainsKey("b"))
                {
                    stack.Push((bool)token["b"]);
                }
                else if (token.ContainsKey("i"))
                {
                    // ints are double precision in JSON
                    stack.Push((long)token["i"]);
                }
                else if (token.ContainsKey("f"))
                {
                    var value = token["f"];
                    // serialiser inserts a whole double as a long
                    if (value is long)
                    {
                        stack.Push((double)(long)token["f"]);
                    }
                    else
                    {
                        // floats are double precision in JSON
                        stack.Push((double)token["f"]);
                    }
                }
                else if (token.ContainsKey("s"))
                {
                    stack.Push((string)token["s"]);
                }
                else if (token.ContainsKey("t"))
                {
                    try {
                        stack.Push(DateTime.Parse((string)token["t"], null));
                    } catch (FormatException) {
                        Logger.LogWarning("Failed converting " + token["t"] + " to DateTime");
                        return(false);
                    }
                }
                else
                {
                    stack.Push(token);
                }
            }

            var result = stack.Count == 0 || (stack.Pop() as bool? ?? false);

            if (result)
            {
                runs++;
                ddna.RecordEvent(new GameEvent("ddnaEventTriggeredAction")
                                 .AddParam("ddnaEventTriggeredCampaignID", campaignId)
                                 .AddParam("ddnaEventTriggeredCampaignPriority", priority)
                                 .AddParam("ddnaEventTriggeredVariantID", variantId)
                                 .AddParam("ddnaEventTriggeredActionType", GetAction())
                                 .AddParam("ddnaEventTriggeredSessionCount", runs));
            }
            return(result);
        }
        private void TriggerDefaultEvents(bool newPlayer)
        {
            if (launchNotificationEvent != null)
            {
                RecordEvent(launchNotificationEvent).Run();
                launchNotificationEvent = null;
            }
            if (hasSentDefaultEvents)
            {
                return;
            }
            if (Settings.OnFirstRunSendNewPlayerEvent && newPlayer)
            {
                Logger.LogDebug("Sending 'newPlayer' event");

                var newPlayerEvent = new GameEvent("newPlayer");
                if (ClientInfo.CountryCode != null)
                {
                    newPlayerEvent.AddParam("userCountry", ClientInfo.CountryCode);
                }

                RecordEvent(newPlayerEvent).Run();
            }

            if (Settings.OnInitSendGameStartedEvent)
            {
                Logger.LogDebug("Sending 'gameStarted' event");

                var gameStartedEvent = new GameEvent("gameStarted")
                                       .AddParam("clientVersion", this.ClientVersion)
                                       .AddParam("userLocale", ClientInfo.Locale);

                if (!string.IsNullOrEmpty(CrossGameUserID))
                {
                    gameStartedEvent.AddParam("ddnaCrossGameUserID", CrossGameUserID);
                }

                if (!String.IsNullOrEmpty(this.PushNotificationToken))
                {
                    gameStartedEvent.AddParam("pushNotificationToken", this.PushNotificationToken);
                }

                if (!String.IsNullOrEmpty(this.AndroidRegistrationID))
                {
                    gameStartedEvent.AddParam("androidRegistrationID", this.AndroidRegistrationID);
                }

                RecordEvent(gameStartedEvent).Run();
            }

            if (Settings.OnInitSendClientDeviceEvent)
            {
                Logger.LogDebug("Sending 'clientDevice' event");

                var clientDeviceEvent = new GameEvent("clientDevice")
                                        .AddParam("deviceName", ClientInfo.DeviceName)
                                        .AddParam("deviceType", ClientInfo.DeviceType)
                                        .AddParam("hardwareVersion", ClientInfo.DeviceModel)
                                        .AddParam("operatingSystem", ClientInfo.OperatingSystem)
                                        .AddParam("operatingSystemVersion", ClientInfo.OperatingSystemVersion)
                                        .AddParam("timezoneOffset", ClientInfo.TimezoneOffset)
                                        .AddParam("userLanguage", ClientInfo.LanguageCode);

                if (ClientInfo.Manufacturer != null)
                {
                    clientDeviceEvent.AddParam("manufacturer", ClientInfo.Manufacturer);
                }

                RecordEvent(clientDeviceEvent).Run();
            }

            hasSentDefaultEvents = true;
        }
        override internal void RecordPushNotification(Dictionary <string, object> payload)
        {
            Logger.LogDebug("Received push notification: " + payload);

            var notificationEvent = new GameEvent("notificationOpened");

            try {
                if (payload.ContainsKey("_ddId"))
                {
                    notificationEvent.AddParam("notificationId", Convert.ToInt64(payload["_ddId"]));
                }
                if (payload.ContainsKey("_ddName"))
                {
                    notificationEvent.AddParam("notificationName", payload["_ddName"]);
                }

                bool insertCommunicationAttrs = false;
                if (payload.ContainsKey("_ddCampaign"))
                {
                    notificationEvent.AddParam("campaignId", Convert.ToInt64(payload["_ddCampaign"]));
                    insertCommunicationAttrs = true;
                }
                if (payload.ContainsKey("_ddCohort"))
                {
                    notificationEvent.AddParam("cohortId", Convert.ToInt64(payload["_ddCohort"]));
                    insertCommunicationAttrs = true;
                }
                if (insertCommunicationAttrs && payload.ContainsKey("_ddCommunicationSender"))
                {
                    // _ddCommunicationSender inserted by respective native notification SDK
                    notificationEvent.AddParam("communicationSender", payload["_ddCommunicationSender"]);
                    notificationEvent.AddParam("communicationState", "OPEN");
                }

                if (payload.ContainsKey("_ddLaunch"))
                {
                    // _ddLaunch inserted by respective native notification SDK
                    notificationEvent.AddParam("notificationLaunch", Convert.ToBoolean(payload["_ddLaunch"]));
                }
                if (payload.ContainsKey("_ddCampaign"))
                {
                    notificationEvent.AddParam("campaignId", Convert.ToInt64(payload["_ddCampaign"]));
                }
                if (payload.ContainsKey("_ddCohort"))
                {
                    notificationEvent.AddParam("cohortId", Convert.ToInt64(payload["_ddCohort"]));
                }
                notificationEvent.AddParam("communicationState", "OPEN");
            } catch (Exception ex) {
                Logger.LogError("Error parsing push notification payload. " + ex.Message);
            }

            if (this.started)
            {
                RecordEvent(notificationEvent).Run();
            }
            else
            {
                this.launchNotificationEvent = notificationEvent;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Records an event with no custom parameters.
        /// </summary>
        /// <param name="eventName">Name of the event.</param>
        public void RecordEvent(string eventName)
        {
            var gameEvent = new GameEvent(eventName);

            RecordEvent(gameEvent);
        }
Exemplo n.º 7
0
        internal virtual bool Evaluate(GameEvent evnt)
        {
            if (evnt.Name != eventName)
            {
                return(false);
            }

            var parameters = evnt.parameters.AsDictionary();
            var stack      = new Stack <object>();

            foreach (var token in condition)
            {
                if (token.ContainsKey("o"))
                {
                    string op = (string)token["o"];
                    op = op.ToLower();
                    object right = stack.Pop();
                    object left  = stack.Pop();

                    try{
                        if (right is bool)
                        {
                            if (left is bool)
                            {
                                stack.Push(BOOLS[op]((bool)left, (bool)right));
                            }
                            else
                            {
                                Logger.LogWarning(
                                    left + " and " + right + " have mismatched types");
                                return(false);
                            }
                        }
                        else if (right is long)
                        {
                            if (left is int)
                            {
                                stack.Push(LONGS[op]((int)left, (long)right));
                            }
                            else if (left is long)
                            {
                                stack.Push(LONGS[op]((long)left, (long)right));
                            }
                            else
                            {
                                Logger.LogWarning(
                                    left + " and " + right + " have mismatched types");
                                return(false);
                            }
                        }
                        else if (right is double)
                        {
                            if (left is float)
                            {
                                stack.Push(DOUBLES[op]((float)left, (double)right));
                            }
                            else if (left is double)
                            {
                                stack.Push(DOUBLES[op]((double)left, (double)right));
                            }
                            else
                            {
                                Logger.LogWarning(
                                    left + " and " + right + " have mismatched types");
                                return(false);
                            }
                        }
                        else if (right is string)
                        {
                            if (left is string)
                            {
                                stack.Push(STRINGS[op]((string)left, (string)right));
                            }
                            else
                            {
                                Logger.LogWarning(
                                    left + " and " + right + " have mismatched types");
                                return(false);
                            }
                        }
                        else if (right is DateTime)
                        {
                            if (left is string)
                            {
                                stack.Push(DATES[op](
                                               DateTime.ParseExact(
                                                   (string)left,
                                                   Settings.EVENT_TIMESTAMP_FORMAT,
                                                   System.Globalization.CultureInfo.InvariantCulture),
                                               (DateTime)right));
                            }
                            else
                            {
                                Logger.LogWarning(
                                    left + " and " + right + " have mismatched types");
                                return(false);
                            }
                        }
                        else
                        {
                            Logger.LogWarning("Unexpected type for " + right);
                            return(false);
                        }
                    }
                    catch (KeyNotFoundException) {
                        Logger.LogWarning(string.Format(
                                              "Failed to find operation {0} for {1} and {2}",
                                              op,
                                              left,
                                              right));
                        return(false);
                    }
                    catch (FormatException) {
                        Logger.LogWarning("Failed converting parameter " + left + " to DateTime");
                        return(false);
                    }
                }
                else if (token.ContainsKey("p"))
                {
                    var param = (string)token["p"];
                    if (parameters.ContainsKey(param))
                    {
                        stack.Push(parameters[param]);
                    }
                    else
                    {
                        Logger.LogWarning("Failed to find " + param + " in event params");
                        return(false);
                    }
                }
                else if (token.ContainsKey("b"))
                {
                    stack.Push((bool)token["b"]);
                }
                else if (token.ContainsKey("i"))
                {
                    // ints are double precision in JSON
                    stack.Push((long)token["i"]);
                }
                else if (token.ContainsKey("f"))
                {
                    var value = token["f"];
                    // serialiser inserts a whole double as a long
                    if (value is long)
                    {
                        stack.Push((double)(long)token["f"]);
                    }
                    else
                    {
                        // floats are double precision in JSON
                        stack.Push((double)token["f"]);
                    }
                }
                else if (token.ContainsKey("s"))
                {
                    stack.Push((string)token["s"]);
                }
                else if (token.ContainsKey("t"))
                {
                    try{
                        stack.Push(DateTime.Parse((string)token["t"], null));
                    }
                    catch (FormatException) {
                        Logger.LogWarning("Failed converting " + token["t"] + " to DateTime");
                        return(false);
                    }
                }
                else
                {
                    stack.Push(token);
                }
            }



            var result = stack.Count == 0 || (stack.Pop() as bool? ?? false);

            if (result)
            {
                // Default to true if no conditions exist
                bool triggerConditionsReached = campaignTriggerConditions.Count == 0;

                // Only one condition needs to be true to flip conditions to true
                this.executionCountManager.incrementExecutionCount(this.variantId);
                foreach (TriggerCondition campaignTriggerCondition in campaignTriggerConditions)
                {
                    if (campaignTriggerCondition.CanExecute())
                    {
                        triggerConditionsReached = true;
                    }
                }

                // If none reached return false
                if (!triggerConditionsReached)
                {
                    return(false);
                }
                if (limit != -1 && runs >= limit)
                {
                    return(false);
                }

                var eventTriggeredActionEvent = CreateEventTriggeredActionEvent(true);
                ddna.RecordEvent(eventTriggeredActionEvent);
            }

            return(result);
        }