Skip to content

Commit 8244fbd

Browse files
authored
Merge pull request #757 from Autodesk/analytics
Analytics Implementation
2 parents a95e614 + 652b09f commit 8244fbd

File tree

10 files changed

+81
-38
lines changed

10 files changed

+81
-38
lines changed

engine/Assets/EditModeTests/AnalyticsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class AnalyticsTest
77
{
88
[Test]
99
public void EventTest() {
10-
var data = new AnalyticsEvent(category: "dog", action: "bark", value: "9");
10+
var data = new AnalyticsEvent(category: "dog", action: "bark", label: "9");
1111
AnalyticsManager.LogEvent(data);
1212
AnalyticsManager.PostData();
1313

engine/Assets/Scripts/AnalyticsManager.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
public static class AnalyticsManager
55
{
6-
76
private static string AllData = "";
87

98
public const string TRACKING_ID = "UA-81892961-6";
@@ -58,29 +57,35 @@ public struct PostResult {
5857
public bool usedBatchUrl;
5958
public string result;
6059
}
61-
6260
}
6361

64-
65-
6662
public interface IAnalytics
6763
{
6864
public string GetPostData();
6965
}
7066
public class AnalyticsEvent : IAnalytics
7167
{
7268

73-
public string Category, Value, Action;
69+
public string Category, Value, Action, Label;
7470

71+
public AnalyticsEvent(string category, string action, string label)
72+
{
73+
Category = category;
74+
Action = action;
75+
Label = label;
76+
}
77+
78+
/*
7579
public AnalyticsEvent(string category, string action, string value)
7680
{
7781
Category = category;
7882
Action = action;
7983
Value = value;
8084
}
85+
*/
8186

8287
public string GetPostData()
83-
=> $"t=event&ec={Category}&ea={Action}&ev={Value}";
88+
=> $"t=event&ec={Category}&ea={Action}&el={Label}";
8489
}
8590

8691
public class AnalyticsScreenView : IAnalytics
@@ -118,6 +123,5 @@ public AnalyticsLogTiming(string category, string vari, string label, int time)
118123
}
119124

120125
public string GetPostData() => $"t=timing&utc={Category}&utv={Vari}&utt={Time.ToString()}&utl={Label}";
121-
122126
}
123127

engine/Assets/Scripts/AutoUpdater.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
public class AutoUpdater : MonoBehaviour
1414
{
1515
// public static string updater;
16-
public const string LocalVersion = "5.0.0.0";
16+
public const string LocalVersion = "5.0.0.0"; // must be a version value
1717
public GameObject updaterPanelPrefab;
1818

1919
// Start is called before the first frame update
@@ -24,6 +24,11 @@ void Start()
2424
Debug.Log($"Version {LocalVersion} Beta");
2525
// game = GameObject.Find("UpdatePrompt");
2626

27+
// Analytics For Client Startup
28+
var init = new AnalyticsEvent(category: "Startup", action: "Launched", label: $"Version {LocalVersion} BETA");
29+
AnalyticsManager.LogEvent(init);
30+
AnalyticsManager.PostData();
31+
2732
if (CheckConnection())
2833
{
2934
WebClient client = new WebClient();

engine/Assets/Scripts/TestAnalytics.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

engine/Assets/Scripts/TestAnalytics.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

engine/Assets/Scripts/UI/NavigationBar.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class NavigationBar : MonoBehaviour
2222

2323
public NavigationBar navBarPrefab;
2424

25+
private string lastOpenedPanel;
26+
2527
private void Start() {
2628
VersionNumber.text = $"v {AutoUpdater.LocalVersion} BETA";
2729
OpenTab(homeTab);
@@ -31,7 +33,13 @@ public void Exit() {
3133
if (Application.isEditor)
3234
Debug.Log("Would exit, but it's editor mode");
3335
else
36+
{
37+
var update = new AnalyticsEvent(category: "Exit", action: "Closed", label: $"Closed Synthesis");
38+
AnalyticsManager.LogEvent(update);
39+
AnalyticsManager.PostData();
40+
3441
Application.Quit();
42+
}
3543
}
3644
private void Update()
3745
{
@@ -41,6 +49,13 @@ private void Update()
4149
}
4250
}
4351

52+
public void PanelAnalytics(string prefabName, string status)
53+
{
54+
var panel = new AnalyticsEvent(category: "Panel", action: status, label: prefabName);
55+
AnalyticsManager.LogEvent(panel);
56+
AnalyticsManager.PostData();
57+
}
58+
4459
public void OpenPanel(GameObject prefab)
4560
{
4661
if(prefab!=null){
@@ -51,12 +66,18 @@ public void OpenPanel(GameObject prefab)
5166
//set current panel button to the button clicked
5267
_currentPanelButton = EventSystem.current.currentSelectedGameObject;
5368
changePanelButton(artifaktBold,new Color(0.8705882f,0.8705882f,0.8705882f,1));
69+
70+
// Analytics Stuff
71+
lastOpenedPanel = prefab.name; // this will need to be an array for movable panels
72+
PanelAnalytics(prefab.name, "Opened");
5473
}
5574
}
5675
public void CloseAllPanels()
5776
{
5877
LayoutManager.ClosePanel();
5978
if(_currentPanelButton!=null) changePanelButton(artifaktRegular,new Color(1,1,1,1));
79+
80+
PanelAnalytics(lastOpenedPanel, "Closed");
6081
}
6182
private void changePanelButton(TMP_FontAsset f, Color c){ //changes color and font of the clicked button
6283
//set font
@@ -92,7 +113,5 @@ private void changeTabButton(TMP_FontAsset f, float underlineHeight, Color c){
92113
Image img = underline.GetComponent<Image>();
93114
img.color = c;//color
94115
}
95-
96-
97116
}
98117
}

engine/Assets/Scripts/UI/Panels/Variants/AddPanel/AddItem.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,23 @@ public class AddItem : MonoBehaviour
1515
GameObject p;
1616
private bool _isRobot;
1717

18+
private void ItemAnalytics(string item)
19+
{
20+
var update = new AnalyticsEvent(category: $"{item}", action: "Loaded", label: $"{item} Loaded");
21+
AnalyticsManager.LogEvent(update);
22+
AnalyticsManager.PostData();
23+
}
24+
1825
public void AddModel(bool reverseSideMotors)
1926
{
2027
ModelManager.AddModel(_fullPath, reverseSideMotors);
28+
ItemAnalytics("Robot");
2129
}
2230

2331
public void AddField()
2432
{
2533
ModelManager.SetField(_fullPath);
34+
ItemAnalytics("Field");
2635
}
2736

2837
public void Init(string name, string path)

engine/Assets/Scripts/UI/Panels/Variants/AddPanel/AddPanel.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ public void LoadField()
8080
}
8181
}
8282

83-
8483
void Start()
8584
{
8685
_root = ParsePath(Path.Combine("$appdata/Autodesk/Synthesis", Folder), '/');
@@ -117,7 +116,6 @@ private void ShowDirectory(string filePath)
117116
ParsePath(path, '\\'));
118117
}
119118
}
120-
121119
}
122120

123121
private string ParsePath(string p, char c)
@@ -141,7 +139,5 @@ private string ParsePath(string p, char c)
141139
// Debug.Log(b);
142140
return b;
143141
}
144-
145-
146142
}
147143
}

engine/Assets/Scripts/UI/Panels/Variants/Settings/SettingsPanel.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ void Start()
6868
DisplaySettings();
6969
}
7070

71-
7271
public void disableSaveButton()
7372
{
7473
saveButton.GetComponent<Image>().color = disabledColor;
@@ -109,14 +108,16 @@ private void DisplaySettings()
109108
setup = false;
110109
}
111110

112-
113-
114111
public void SaveSettings()
115112
{//writes settings back into preference manager when save button is clicked
116113
Save();
117114
LoadSettings();
118115
disableSaveButton();
119116
RepopulatePanel();
117+
118+
var update = new AnalyticsEvent(category: "Settings", action: "Saved", label: $"Saved Settings");
119+
AnalyticsManager.LogEvent(update);
120+
AnalyticsManager.PostData();
120121
}
121122
public void onValueChanged(SettingsInput si)
122123
{
@@ -177,13 +178,21 @@ public override void Close()
177178
{
178179
Save();
179180
base.Close();
181+
182+
var update = new AnalyticsEvent(category: "Settings", action: "Closed", label: $"Closed Settings");
183+
AnalyticsManager.LogEvent(update);
184+
AnalyticsManager.PostData();
180185
}
181186

182187
public void ResetSettings()
183188
{
184189
SetDefaultPreferences();
185190
LoadSettings();
186191
RepopulatePanel();
192+
193+
var update = new AnalyticsEvent(category: "Settings", action: "Reset", label: $"Reset Settings");
194+
AnalyticsManager.LogEvent(update);
195+
AnalyticsManager.PostData();
187196
}
188197
private void SetMaxResolution()
189198
{

engine/Assets/Scripts/UI/Panels/Variants/UpdatePromptPanel.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,32 @@ public class UpdatePromptPanel: Panel {
1010
public string UpdaterLink = string.Empty;
1111

1212
public void Agreed() {
13+
14+
bool updateAgreed = false;
15+
1316
if (UpdaterLink == string.Empty)
17+
{
1418
Debug.LogWarning("No updater link provided");
19+
}
1520
else
21+
{
22+
updateAgreed = true;
23+
1624
Process.Start(UpdaterLink);
1725

26+
var update = new AnalyticsEvent(category: "Startup", action: "Update Prompted", label: $"Update Agreed");
27+
AnalyticsManager.LogEvent(update);
28+
}
29+
30+
if(updateAgreed == false)
31+
{
32+
Debug.Log("Update Declined");
33+
var update = new AnalyticsEvent(category: "Startup", action: "Update Prompted", label: $"Update Declined");
34+
AnalyticsManager.LogEvent(update);
35+
}
36+
37+
AnalyticsManager.PostData();
38+
1839
if (Application.isEditor)
1940
Debug.Log("Would exit, but it's editor mode");
2041
else

0 commit comments

Comments
 (0)