-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStandardEventPayload.cs
114 lines (106 loc) · 4.34 KB
/
StandardEventPayload.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Collections.Generic;
namespace UnityEngine.Analytics
{
[Serializable]
public class StandardEventPayload
{
private static Dictionary<string, object> m_EventData = new Dictionary<string, object>();
[SerializeField]
private bool m_IsEventExpanded = true;
[SerializeField]
private string m_StandardEventType = "CustomEvent";
[SerializeField]
private string m_Name = string.Empty;
public System.Type standardEventType;
[SerializeField]
private AnalyticsEventParamListContainer m_Parameters;
public StandardEventPayload()
{
this.m_Parameters = new AnalyticsEventParamListContainer();
}
public AnalyticsEventParamListContainer parameters
{
get
{
return this.m_Parameters;
}
}
public string name
{
get
{
return this.m_Name;
}
set
{
this.m_Name = value;
}
}
public virtual AnalyticsResult Send()
{
if (string.IsNullOrEmpty(this.name))
throw new Exception("Analtyics Event Tracker failed to send the CustomEvent. The event Name field cannot be empty.");
if (!this.IsCustomDataValid())
throw new Exception("Analytics event tracker failed to send. The event data is not valid. Parameter names cannot be null or empty.");
if (!this.IsRequiredDataValid())
throw new Exception("Analytics event tracker failed to send. The event data is not valid. Please check the values of required parameters.");
return AnalyticsEvent.Custom(this.name.Trim(), this.GetParameters());
}
private IDictionary<string, object> GetParameters()
{
StandardEventPayload.m_EventData.Clear();
List<AnalyticsEventParam> parameters = this.parameters.parameters;
for (int index = 0; index < parameters.Count; ++index)
{
if (parameters[index] != null && parameters[index].valueProperty.IsValid())
StandardEventPayload.m_EventData.Add(parameters[index].name, parameters[index].value);
}
return (IDictionary<string, object>)StandardEventPayload.m_EventData;
}
private bool IsCustomDataValid()
{
List<AnalyticsEventParam> parameters = this.parameters.parameters;
for (int index = 0; index < parameters.Count; ++index)
{
if (parameters[index] != null && string.IsNullOrEmpty(parameters[index].name) && parameters[index].valueProperty.IsValid())
return false;
}
return true;
}
private bool IsRequiredDataValid()
{
List<AnalyticsEventParam> parameters = this.parameters.parameters;
Dictionary<string, List<bool>> dictionary = new Dictionary<string, List<bool>>();
for (int index = 0; index < parameters.Count; ++index)
{
if (parameters[index] != null && parameters[index].requirementType == AnalyticsEventParam.RequirementType.Required)
{
if (string.IsNullOrEmpty(parameters[index].groupID))
{
if (!dictionary.ContainsKey("none"))
dictionary.Add("none", new List<bool>());
dictionary["none"].Add(parameters[index].valueProperty.IsValid());
}
else
{
if (!dictionary.ContainsKey(parameters[index].groupID))
dictionary.Add(parameters[index].groupID, new List<bool>());
dictionary[parameters[index].groupID].Add(parameters[index].valueProperty.IsValid());
}
}
}
foreach (string key in dictionary.Keys)
{
if (key != null && key == "none")
{
if (dictionary[key].Contains(false))
return false;
}
else if (!dictionary[key].Contains(true))
return false;
}
return true;
}
}
}