public GameEvent CreateEventTriggeredActionEvent(bool incrementRuns, string name = "ddnaEventTriggeredAction", string actionKey = "ddnaEventTriggeredAction", string campaignIdKey = "ddnaEventTriggeredCampaignID", string campaignPriorityKey = "ddnaEventTriggeredCampaignPriority", string variantIdKey = "ddnaEventTriggeredVariantID", string actionTypeKey = "ddnaEventTriggeredActionType", string sessionCountKey = "ddnaEventTriggeredSessionCount", string campaignNameKey = "ddnaEventTriggeredCampaignName", string variantNameKey = "ddnaEventTriggeredVariantName") { if (incrementRuns) { runs++; } var eventTriggeredActionEvent = new GameEvent(actionKey) .AddParam(campaignIdKey, campaignId) .AddParam(campaignPriorityKey, priority) .AddParam(variantIdKey, variantId) .AddParam(actionTypeKey, GetAction()) .AddParam(sessionCountKey, runs); if (campaignName != null) { eventTriggeredActionEvent.AddParam(campaignNameKey, campaignName); } if (variantName != null) { eventTriggeredActionEvent.AddParam(variantNameKey, variantName); } return(eventTriggeredActionEvent); }
private void TriggerDefaultEvents(bool newPlayer) { 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); } if (Settings.OnInitSendGameStartedEvent) { Logger.LogDebug("Sending 'gameStarted' event"); var gameStartedEvent = new GameEvent("gameStarted") .AddParam("clientVersion", this.ClientVersion) .AddParam("userLocale", ClientInfo.Locale); if (!String.IsNullOrEmpty(this.PushNotificationToken)) { gameStartedEvent.AddParam("pushNotificationToken", this.PushNotificationToken); } if (!String.IsNullOrEmpty(this.AndroidRegistrationID)) { gameStartedEvent.AddParam("androidRegistrationID", this.AndroidRegistrationID); } RecordEvent(gameStartedEvent); } 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); } }
public void DoesThrowArgumentExceptionIfKeyIsNull() { Assert.Throws <System.ArgumentNullException>(() => { var gameEvent = new GameEvent("myEvent"); gameEvent.AddParam(null, null); }); }
public void CreateWithNestedParameters() { var gameEvent = new GameEvent("myEvent"); gameEvent.AddParam("level1", new Dictionary <string, object>() { { "level2", new Dictionary <string, object>() { { "yo!", "greeting" } } } }); CollectionAssert.AreEquivalent(new Dictionary <string, object>() { { "eventName", "myEvent" }, { "eventParams", new Dictionary <string, object>() { { "level1", new Dictionary <string, object>() { { "level2", new Dictionary <string, object>() { { "yo!", "greeting" } } } } } } } }, gameEvent.AsDictionary()); }
public void CreateWithParameters() { var gameEvent = new GameEvent("myEvent"); gameEvent.AddParam("level", 5); gameEvent.AddParam("ending", "Kaboom!"); CollectionAssert.AreEquivalent(new Dictionary <string, object>() { { "eventName", "myEvent" }, { "eventParams", new Dictionary <string, object>() { { "level", 5 }, { "ending", "Kaboom!" } } } }, gameEvent.AsDictionary()); }
override internal EventAction RecordEvent(string eventName, Dictionary <string, object> eventParams) { var gameEvent = new GameEvent(eventName); foreach (var key in eventParams.Keys) { gameEvent.AddParam(key, eventParams[key]); } return(RecordEvent(gameEvent)); }
/// <summary> /// Records an event with a name and a dictionary of event parameters. The eventParams dictionary /// should match the 'eventParams' branch of the event schema. /// </summary> /// <param name="eventName">Event name.</param> /// <param name="eventParams">Event parameters.</param> public void RecordEvent(string eventName, Dictionary <string, object> eventParams) { var gameEvent = new GameEvent(eventName); foreach (var key in eventParams.Keys) { gameEvent.AddParam(key, eventParams[key]); } RecordEvent(gameEvent); }
private static GameEvent Evnt(string name = "a", params object[] values) { var evnt = new GameEvent(name); for (int i = 0; i < values.Length; i += 2) { evnt.AddParam(values[i] as string, values[i + 1]); } return(evnt); }
public void RecordGameRunningEvent() { var gameRunningEvent = new GameEvent("gameRunning") .AddParam("clientVersion", this.ClientVersion) .AddParam("userLocale", ClientInfo.Locale); if (!string.IsNullOrEmpty(CrossGameUserID)) { gameRunningEvent.AddParam("ddnaCrossGameUserID", CrossGameUserID); } if (!String.IsNullOrEmpty(this.PushNotificationToken)) { gameRunningEvent.AddParam("pushNotificationToken", this.PushNotificationToken); } if (!String.IsNullOrEmpty(this.AndroidRegistrationID)) { gameRunningEvent.AddParam("androidRegistrationID", this.AndroidRegistrationID); } RecordEvent(gameRunningEvent).Run(); }
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).Run(); imageMessage.Close(); }); break; } case "link": { actions.Add(() => { if (imageMessage.OnAction != null) { imageMessage.OnAction(eventArgs); } if (valueObj != null) { Application.OpenURL((string)valueObj); } ddna.RecordEvent(actionEvent).Run(); imageMessage.Close(); }); break; } case "store": { actions.Add(() => { if (imageMessage.OnStore != null) { imageMessage.OnStore(eventArgs); } ddna.RecordEvent(actionEvent).Run(); imageMessage.Close(); }); break; } default: { // "dismiss" actions.Add(() => { if (imageMessage.OnDismiss != null) { imageMessage.OnDismiss(eventArgs); } ddna.RecordEvent(actionEvent).Run(); imageMessage.Close(); }); break; } } } }
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); } //BRD: Added the armoury common properties #if !DELTA_DNA_PUBLIC_REPO if (Armoury.DeltaDnaApi.instance?.overrideImageMessageEvent ?? false) { actionEvent.AddParam("client_event_name", actionEvent.Name); foreach (var pair in Armoury.Analytics.AnalyticsService.GetAllCommonEventProperties()) { actionEvent.AddParam(pair.Key, pair.Value); } } #endif 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).Run(); imageMessage.Close(); }); break; } case "link": { actions.Add(() => { if (imageMessage.OnAction != null) { imageMessage.OnAction(eventArgs); } if (valueObj != null) { Application.OpenURL((string)valueObj); } ddna.RecordEvent(actionEvent).Run(); imageMessage.Close(); }); break; } case "store": { actions.Add(() => { if (imageMessage.OnStore != null) { imageMessage.OnStore(eventArgs); } ddna.RecordEvent(actionEvent).Run(); imageMessage.Close(); }); break; } default: { // "dismiss" actions.Add(() => { if (imageMessage.OnDismiss != null) { imageMessage.OnDismiss(eventArgs); } ddna.RecordEvent(actionEvent).Run(); imageMessage.Close(); }); break; } } } }
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) { this.RecordEvent(notificationEvent); } else { this.launchNotificationEvent = notificationEvent; } }
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); } runs++; var eventTriggeredActionEvent = new GameEvent("ddnaEventTriggeredAction") .AddParam("ddnaEventTriggeredCampaignID", campaignId) .AddParam("ddnaEventTriggeredCampaignPriority", priority) .AddParam("ddnaEventTriggeredVariantID", variantId) .AddParam("ddnaEventTriggeredActionType", GetAction()) .AddParam("ddnaEventTriggeredSessionCount", runs); if (campaignName != null) { eventTriggeredActionEvent.AddParam("ddnaEventTriggeredCampaignName", campaignName); } if (variantName != null) { eventTriggeredActionEvent.AddParam("ddnaEventTriggeredVariantName", variantName); } ddna.RecordEvent(eventTriggeredActionEvent); } return(result); }