re-added analytics

This commit is contained in:
Ellpeck 2020-06-09 19:03:55 +02:00
parent 5d81b5374d
commit 6c83312ad3
13 changed files with 5917 additions and 11 deletions

View file

@ -1,5 +1,7 @@
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Net;
using Android.OS;
using Android.Views;
using Microsoft.Xna.Framework;
@ -29,9 +31,12 @@ namespace Android {
this.Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;
TextInputWrapper.Current = new TextInputWrapper.Mobile();
this.game = new GameImpl();
this.game = new GameImpl(new AndroidAnalytics(this));
this.game.GraphicsDeviceManager.ResetWidthAndHeight(this.game.Window);
this.game.OnLoadContent += game => game.InputHandler.HandleMouse = false;
this.game.OnLoadContent += game => {
game.InputHandler.HandleMouse = false;
game.UiSystem.LinkBehavior = l => this.StartActivity(new Intent(Intent.ActionView, Uri.Parse(l.Match.Groups[1].Value)));
};
this.game.GraphicsDeviceManager.IsFullScreen = true;
this.view = this.game.Services.GetService(typeof(View)) as View;

View file

@ -54,6 +54,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Activity1.cs" />
<Compile Include="AndroidAnalytics.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@ -70,6 +71,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Contentless" Version="2.0.6" />
<PackageReference Include="GameAnalytics.Xamarin.SDK" Version="4.1.0" />
<PackageReference Include="MonoGame.Content.Builder" Version="3.7.0.9" />
<PackageReference Include="MonoGame.Framework.Android" Version="3.7.1.189" />
</ItemGroup>

View file

@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using Android.App;
using GameAnalyticsSDK;
using GameAnalyticsSDK.Utilities;
using TouchyTickets;
namespace Android {
public class AndroidAnalytics : Analytics {
private readonly Activity activity;
public AndroidAnalytics(Activity activity) {
this.activity = activity;
}
public override void Setup(Dictionary<string, object> json) {
GameAnalytics.Initialize(this.activity, GA_MiniJSON.JsonEncode(new Hashtable(json)));
}
public override void AddResourceEvent(bool sink, string currency, float amount, string itemType, string itemId) {
GameAnalytics.NewResourceEvent(sink ? GAResourceFlowType.Sink : GAResourceFlowType.Source, currency, amount, itemType, itemId);
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace TouchyTickets {
public abstract class Analytics {
public abstract void Setup(Dictionary<string, object> json);
public abstract void AddResourceEvent(bool sink, string currency, float amount, string itemType, string itemId);
}
}

View file

@ -21,6 +21,7 @@
"Tutorial11": "Now that you have a couple of attractions, you can start thinking about purchasing modifiers for them! Swipe to access the modifier menu on the far right and purchase a modifier.",
"Tutorial12": "Different kinds of modifiers can be applied to different attractions. Click on one of your attractions and add the modifier to it.",
"Tutorial13": "Modifiers add a ticket sale multiplier to a single attraction. Each attraction can have an infinite amount of any given modifier, so they're a great way to rack up tickets faster.",
"GDPRInfo": "This game uses user data for advertising and analytics. For more information, see <c CornflowerBlue><l https://gameanalytics.com/privacy>GameAnalytics'</l></c> and <c CornflowerBlue><l http://www.google.com/policies/privacy/partners/>Google's</l></c> policies on data collection.",
"Carousel": "Carousel",
"FoodCourt": "Food Court",
"FerrisWheel": "Ferris Wheel",

View file

@ -13,6 +13,8 @@ namespace TouchyTickets {
public static GameImpl Instance { get; private set; }
public readonly ISet<Upgrade> AppliedUpgrades = new HashSet<Upgrade>();
public readonly Tutorial Tutorial = new Tutorial();
public bool ReadAnalyticsInfo;
public readonly Analytics Analytics;
public BigInteger Tickets;
public int TimesRestarted;
public int Stars;
@ -23,8 +25,21 @@ namespace TouchyTickets {
public DateTime LastUpdate;
private double saveCounter;
public GameImpl() {
public GameImpl(Analytics analytics) {
this.Analytics = analytics;
Instance = this;
// set up analytics
var settings = new Dictionary<string, object>();
settings["InfoLog"] = true;
settings["VerboseLog"] = true;
settings["SubmitErrors"] = true;
settings["ResourceCurrencies"] = new[] {"Tickets", "Stars"};
settings["ResourceItemTypes"] = new[] {"Attraction", "Restart", "Upgrade"};
// ios comes first, then android. For now they're the same
settings["GameKey"] = new[] {"cc18de06eebbc5d5e987c384fcd28000", "cc18de06eebbc5d5e987c384fcd28000"};
settings["SecretKey"] = new[] {"82ca1a930ee38e2383ffb02db7631e16033b511d", "82ca1a930ee38e2383ffb02db7631e16033b511d"};
this.Analytics.Setup(settings);
}
protected override void LoadContent() {

View file

@ -25,7 +25,8 @@ namespace TouchyTickets {
Stars = game.Stars,
TimesRestarted = game.TimesRestarted,
Upgrades = game.AppliedUpgrades.Select(u => u.Name).ToList(),
TutorialStep = game.Tutorial.CurrentStep
TutorialStep = game.Tutorial.CurrentStep,
ReadAnalyticsInfo = game.ReadAnalyticsInfo
};
Serializer.Serialize(stream, data);
}
@ -48,6 +49,7 @@ namespace TouchyTickets {
foreach (var name in data.Upgrades)
game.AppliedUpgrades.Add(Upgrade.Upgrades[name]);
game.Tutorial.CurrentStep = data.TutorialStep;
game.ReadAnalyticsInfo = data.ReadAnalyticsInfo;
// version 1 had smaller maps
if (data.SaveVersion <= 1) {
@ -88,6 +90,7 @@ namespace TouchyTickets {
public int TimesRestarted;
public List<string> Upgrades;
public int TutorialStep;
public bool ReadAnalyticsInfo;
}
}

View file

@ -6,7 +6,7 @@
<ItemGroup>
<PackageReference Include="Coroutine" Version="1.0.4" />
<PackageReference Include="MLEM.Startup" Version="3.3.3-201" />
<PackageReference Include="MLEM.Startup" Version="3.3.3-204" />
<PackageReference Include="MonoGame.Framework.Portable" Version="3.7.1.189">
<PrivateAssets>all</PrivateAssets>
</PackageReference>

View file

@ -172,6 +172,8 @@ namespace TouchyTickets {
yesNoUi.AddChild(new Button(Anchor.AutoInlineIgnoreOverflow, new Vector2(0.5F, 30), Localization.Get("Place")) {
OnPressed = e2 => {
GameImpl.Instance.Tickets -= price;
GameImpl.Instance.Analytics.AddResourceEvent(true, "Tickets", (long) price, "Attraction", attraction.Key);
map.Place(map.PlacingPosition, map.PlacingAttraction);
this.FadeUi(false, () => this.uiSystem.Remove(e2.Root.Name));
},
@ -234,7 +236,11 @@ namespace TouchyTickets {
if (map.SelectedPosition == null)
return;
var attraction = map.GetAttractionAt(map.SelectedPosition.Value);
GameImpl.Instance.Tickets -= attraction.GetModifierPrice(map.PlacingModifier);
var price = attraction.GetModifierPrice(map.PlacingModifier);
GameImpl.Instance.Tickets -= price;
GameImpl.Instance.Analytics.AddResourceEvent(true, "Tickets", price, "Modifier", modifier.Name);
attraction.ApplyModifier(map.PlacingModifier);
},
OnUpdated = (e2, time) => {
@ -297,6 +303,9 @@ namespace TouchyTickets {
this.uiSystem.Remove(e2.Root.Name);
var game = GameImpl.Instance;
game.Analytics.AddResourceEvent(true, "Tickets", (long) game.Tickets, "Restart", "Restart" + game.TimesRestarted);
game.Analytics.AddResourceEvent(false, "Stars", (long) game.Tickets, "Restart", "Restart" + game.TimesRestarted);
game.Stars += game.GetBuyableStars();
game.TimesRestarted++;
game.Tickets = 0;
@ -378,6 +387,19 @@ namespace TouchyTickets {
center.DrawAlpha -= 0.015F;
yield return new WaitEvent(CoroutineEvents.Update);
}
if (!GameImpl.Instance.ReadAnalyticsInfo) {
var evt = new Event();
var panel = splash.AddChild(new Panel(Anchor.Center, new Vector2(0.8F), Vector2.Zero, true));
panel.AddChild(new Paragraph(Anchor.AutoLeft, 1, Localization.Get("GDPRInfo")));
panel.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 30), Localization.Get("Okay")) {
OnPressed = e2 => {
GameImpl.Instance.ReadAnalyticsInfo = true;
splash.RemoveChild(panel);
CoroutineHandler.RaiseEvent(evt);
}
});
yield return new WaitEvent(evt);
}
while (splash.DrawAlpha > 0) {
splash.DrawAlpha -= 0.015F;
yield return new WaitEvent(CoroutineEvents.Update);
@ -457,6 +479,8 @@ namespace TouchyTickets {
ChildPadding = new Vector2(4),
OnPressed = e => {
GameImpl.Instance.Stars -= upgrade.Price;
GameImpl.Instance.Analytics.AddResourceEvent(true, "Stars", upgrade.Price, "Upgrade", upgrade.Name);
GameImpl.Instance.AppliedUpgrades.Add(upgrade);
upgrade.OnApplied();
PopulateUpgradeList(upgradeList);

19
iOS/IosAnalytics.cs Normal file
View file

@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using GameAnalyticsSDK;
using GameAnalyticsSDK.Utilities;
using TouchyTickets;
namespace iOS {
public class IosAnalytics : Analytics {
public override void Setup(Dictionary<string, object> json) {
GameAnalytics.Initialize(GA_MiniJSON.JsonEncode(new Hashtable(json)));
}
public override void AddResourceEvent(bool sink, string currency, float amount, string itemType, string itemId) {
GameAnalytics.NewResourceEvent(sink ? GAResourceFlowType.Sink : GAResourceFlowType.Source, currency, amount, itemType, itemId);
}
}
}

View file

@ -11,7 +11,7 @@ namespace iOS {
private static void RunGame() {
TextInputWrapper.Current = new TextInputWrapper.Mobile();
game = new GameImpl();
game = new GameImpl(new IosAnalytics());
game.Run();
}

View file

@ -111,6 +111,7 @@
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<Compile Include="IosAnalytics.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@ -131,6 +132,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Contentless" Version="2.0.6" />
<PackageReference Include="GameAnalytics.Xamarin.SDK" Version="4.1.0" />
<PackageReference Include="MonoGame.Content.Builder" Version="3.7.0.9" />
<PackageReference Include="MonoGame.Framework.iOS" Version="3.8.0.1375-develop" />
</ItemGroup>