Use App Center Analytics, Crashlytics and more with .NET MAUI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Oh, yeah. App Center is back for .NET MAUI. You can now use Analytics, Crashlytics and Distribution for your .NET MAUI app. Let's go check it out. Now, before I dive into the technical part, let me give you the backstory for App Center just so we're all on the same page because not everyone might be familiar with it. App Center has been a product by Microsoft for a good number of years now, and it's basically your one stop control center for everything that has to do with mobile apps. And not just built with Microsoft technology, also with Objective-C and Java. So the Android and iOS parts even React maybe, and then some other things. So there's a lot of cool stuff that you can do here. What you can do is build your application so that's like whatever you can do. Also, with Azure DevOps or GitHub actions, you can implement analytics. So follow your user through the mobile app that you've built and collect some analytics things. They've clicked. Other things that you might want to collect Crashlytics. So whenever the app crashes, you will get the Stack trace and some information that might be useful for you as a developer to see what happens. And you can see how often a certain crash happens and that kind of stuff. You can use it for distribution. So you can send your apps from there to the App Store. You can first build it, then distribute it from there to the App Store or distribute it directly through App Center. That's a possibility as well. There's also automated UI testing. I'll get to that in a little bit. But that's basically all the things that you can do from App Center. Now, like I said, it has been around for a good number of years, but the development at some point really slowed down and there weren't really new features being added. It was still maintained. You can still use it, but there weren't really exciting features coming. And also with .NET MAUI being released, a lot of people were asking like, okay, is .NET MAUI going to be supported now? So yes, because they've now released a prerelease package that also supports .NET MAUI, which is the good news, and we're going to see that in a little bit. But also no. So for building, for instance, like building your application through App Center, that's not supporting .NET MAUI right now. And at this point, it's probably important to say I don't have any preexisting knowledge about this, although I work at Microsoft. But my bet would be if you want to use Build, go to Azure DevOps, go to GitHub Actions because we already have those two services that can build your application. So it would be kind of weird to also have that still in App Center. Who knows what might happen? But it hasn't happened until now. So maybe you want to look at other solutions for that. But maybe it will still come. I don't know. I honestly don't know. But now what has happened for the SDKs, at least for analytics, Crashlytics and distribution, they have released a prerelease package. So apparently that is going to be supported. Yay, so that's exactly what we're going to see that is now supported in .NET MAUI. Then there's also the question for the UI tests. I'm going to save that for the end of the video. So make sure that you catch it all. Let's hop over to Visual Studio 2022 and see how to integrate this in your .NET MAUI application. Before we go into Visual Studio 2022 and integrate App Center inside of our app, go to https://appcenter.ms in your favorite browser. You'll get on a landing page where you can sign in or sign up for an account. Please do that. And whenever you do, you will find yourself here in this portal of App Center. Here you can start creating your app definitions for the different platforms. So let's start by clicking here in the top right, add new and add new app. And here you can enter some metadata for your application. So at the top, let's start with a name. MauiAppCenterTest. There we go. And I like to add the platform in here because else you will have all these duplicate names and it's hard to kind of like parse what is what. Right? So let's add the platform in that. Actually I'm going to make this win. And then you can specify a release type, which is only for your administration, just labeled to specify if it's an alpha or an enterprise version or whatever. I'm going to skip over that for now. And then underneath that there is the OS and the platform. So that's where it gets kind of interesting, but also not really, because the good news is it's not really important what you select here. It's only important if you're going to use the App Center build. Because with App Center build, it's going to try to detect what build definition they should use for building your app. So iOS needs Xcode and Windows needs Visual Studio, right? So whenever you select the wrong one, it's not going to be able to build. But .NET MAUI is not supported for the build section on App Center anyway, so we don't have to worry about that. What the rest does is kind of like specify the instructions that you will see inside of the portal and you will have a nice separation between all the analytics and the crash reports for the different platforms. So you probably want to make it close to the platform that you're actually going to do here. Now the cool thing is iOS, you can also see Objective-C and Swift and React Native and all the things that I mentioned. So it's not just Microsoft products. If we switch around between the different OS options, you can see that we have all these kinds of different things, which is cool. So I'm going to stick with Windows. The other thing is that you will notice is that it says Xamarin. And for windows. We only have UWP. So there is not really an updated portal yet for .NET MAUI as well. So I'm going to stick with Windows and UWP, which is the closest thing to whatever we have. Then behind my camera, there's the Add new app button. So click that to add the new app. And you will get here inside of your app definition for Windows. Now in the middle here, we see all the instructions which you should follow. And we can go over to the Xamarin.Forms instructions because that's kind of like closer to .NET MAUI as well. So just go there. And this will instruct you to how to add the packages which is actually still correct. I'll show you that in a little bit. Start the SDK. This is still correct as well. And you need these separate app secrets right here. The only thing that's not correct here is UWP. We need to change that. So be aware of that. And here you can actually find the app secret. And this will be different for all the app definitions that you create. So here we have this one. And then if I go back and create another one real quick and I say MauiAppCenterTest-ios. And I do iOS and I do Xamarin, Add new app. You will see the exact instructions and your Xamarin.Forms. And you can scroll down here and you can see this different app ID, right? And you will just fill that in for iOS, UWP, Android on the right places and it will connect it to the right things from your code to the App Center app definitions. That's really cool. Now let's go back to the Windows one so that it all checks out. So here you can see all the different sections. On the left you can see Build. We're going to ignore that distribute to distribute your app. The diagnostics that's like the Crashlytics that I mentioned and the analytics that's for the analytics of your app, right? So we're going to focus on the Crashlytics and analytics for now. If there's something that you want to know more about the other sections in more detail, please let me know down in the comments and I'll make a little follow up here. So let's go back to the instructions here and copy this little AppCenter.Start() We're going to use that in a little bit. So copy that and go over to Visual Studio 2022. Now. I created a File, New, .NET MAUI application. And I installed the App Center packages. So go to your project right here. Right-click, Manage NuGet Packages, search for App Center and you will find the right packages. Make sure to check the Include Prelease checkbox here and you will find version 5.0.0 at the time of recording. And depending on what service you want to use, you don't have to use all of them, you can just use one of them. Install the analytics one, the crashes one. I did that for this project and that will bring on all the right dependencies. And if you need more, then you can also do distribute. Please don't use push that has been deprecated. So please don't do that. Analytics and crashes is it for now. And then you need to initialize kind of like this SDK. So the most logical place for that is MauiProgram. So let's go in here and just outside of our builder, let's just paste in that AppCenter.Start(); now it's not going to recognize it. So to do that, we want to go here and add the right using so we can also use IntelliSense, but it's pretty easy. So let's just show you that so that it's really clear. using Microsoft.AppCenter; and then we also need it for these analytics and crashes right here. So we can just paste this and we can say analytics and do it again. And we can say crashes and then we have it all. So what this does is it initializes it with all the right app IDs, right? So we need to fill those in here. And then here, the second parameter is on the second and the third actually we specify which services we want to enable here. So we are going to say analytics and crashes. And by just setting this up, we don't need to do anything else. You will already get information. So that's cool. Let me get the IDs right here. So let's go back to the portal, scroll down. And this is my Windows ID. So let's copy that and put it in the right place. So I'm going to put it here in the UWP one. But please note, this is very important. It's not UWP, else it won't work. It won't connect it to the right place. In App Center. You want to do windowsdesktop. One word, lowercase. windowsdesktop. That is the one for .NET MAUI apps, actually for WinUI apps. So make sure that you change that one. Android, iOS and macOS I think are still the same. But for Windows you need to change this. So for iOS, just to show you how it is done, go back, go to our iOS one, get the ID from here and specify that for your iOS one so that you can get it for all the platforms. And it will depending on the platform that you're running on, it will put it in the right places. Right? So that's how this works. Now, without doing anything else, you will get from the analytics, you will already get like, well, actually let me run it here on Windows. Maybe we'll see that immediately. You will get like how many sessions or how many times your app was started, by which user, what language was on their device, which version of the app they were using. So kind of like the global information at this point, it's probably good to say that if you're going to do this for your users, you probably want to make really clear that you have enabled analytics and what roughly is going to send over to your services. Where the data is stored is important as well these days. So really be clear and transparent about that. There's even APIs to kind of like disable the analytics and the crashes entirely if users is that what users want. So make sure that you do that and do the right thing here. So this is our application. Click me. It's just the default template. And now if we go back to the App Center portal, we should see our first things here. So this is iOS. So let's go back to Windows and go to our analytics. And here you can see boom. This is like real time. There's no cut in here. This actually happened. So you can see active users, one monthly, one weekly, one daily. One I'm on a Surface Book 2, you can see the OS version. So Windows 10 something, active users per version. You can see which version, you can see the language. You can see all these kinds of data right here. And you can also do something with sessions, so you can start tracking sessions and events. So this is all stuff that you can get for free. So really cool. Now for the crashes, kind of like the same thing for crashes. Whenever an unhandled exception happens, it will store all the data that it can, the stack trays and whatnot. It will save that. And whenever the user launches the application again, that's kind of important. It will send it all over. Because if a crash happened at that point, they can't send the logs out, right? So you'll have to wait until the application is restarted and then you can send the well then the application will send it automatically. You don't have to do anything for that. So without configuring anything, just this, you will already get functionality. That's really cool, but you can take it a step further. So if we go to our main page code behind, and we go into the button thingy right here, let me just add it here after the count. So first let's do the crashes. So you can start typing Crashes and boom. It will automatically do that for you. It will add the right using here at the top. You can do that manually if you want crashes. And let's see all the API. So you can do something with the user confirmation. So you can ask the confirmation of the user, like, do you want to send logs, error logs and whatnot. So maybe that's a good thing to do as well. There are some other things or TrackError. So you can also do errors that you are handling. So you can do your try/catch block and in the catch block you can say TrackError. You can just specify the exception in there. Have a dictionary with some properties that you can use to specify extra data. You can even have attachments so you can take a screenshot if that's what you want, attach that and send that over to App Center which is really, really cool. Again, I can keep saying it, it's really cool. GenerateTestCrash can also be very useful. So that is whenever we press this button, actually, let's just try and see what this does. Generate test crash. So whenever I do this, I go to Windows, we click the button and it will generate some kind of error so that we can see if everything is working and it actually shows up in our App Center portal. So let me just quickly use this button, see if it actually crashes and see if maybe our data shows up in the portal. That would be really cool. I'll do that right after this to not jump around too much. So you can see here breakpoint whatever unhandled exception. So like I said, maybe that's the important thing here. I need to start the application now again to make sure that it actually sends the crash report, right? So let's do that just to be sure to see that our data hopefully shows up in the App Center portal as well. All right, there we are. And that's done. But the only thing that you can also do is with the analytics. So let's go back to our main page. So this was the crashes, not really that exciting. It's more or less doing itself. So analytics and here we have a couple of things more. So we can do StartSession so that will whenever your user may be logged in, you can say start session and then it starts tracking and then grouping everything into a session which is for reporting purposes. You don't need to do that. You can also just do track event which allows you to track loose events. So for this we are doing account. So we could do give it a name. You want to have that name consistently for the events that you want to track, right? And you want to count and let's just say a new dictionary of strings. And what we want to do here then is specify maybe the count of well, let's name this counter just to be a little bit more clear. So this is the counter event and then we have account and the count is of count to string because that is the thing that we're tracking here, right? We want to really know how far those people are counting. So there we have that. And whenever we do that, we should see an event of count and it will report the count to us. So probably in your application it's going to be a little bit more useful, hopefully. But just to get the point across to see how to work with this analytics right here and also here, there's a couple of other stuff like I already mentioned to disable it whenever the user sets maybe a setting like, hey, I don't want to be tracked, I don't want the analytics to maybe disable that. And there's a couple of other things in there as well. So that's really cool. Whenever the application comes up now, I should be able to press the button and it shouldn't crash, but it should report these analytics back to the App Center portal. So I've clicked it a couple of times. Let's go back to the portal to see if it actually happened already. We should see here an increase in the active users and whatnot. Not really, not yet.... Okay, so that hasn't worked yet. The events, you can see the events right here, counter count three. And you can see a trend right if it's going up or down. So you can also use this for A/B testing if that's what you want. See how many times a user uses this feature, if it's discoverable enough, all that kind of stuff. You can click through here, you can see the number of users that's actually going through this event, the count, et cetera, et cetera. All the things that I just mentioned basically. And maybe our crashes here as well. Oh, there we go. So under the diagnostics we have issues and we have our test crash. You can see the number of crashes, the number of errors, and you can click through here all the way at the bottom to the details right here. Although it didn't really collect any details right here, but typically you would see the stack traces together with all the details, like the most effective device, the OS, all kinds of useful stuff in here. So that's how to get started with App Center on .NET MAUI. As you could probably already tell, I'm pretty excited about App Center being supported for .NET MAUI now because this is such a beautiful product and I always hated that it didn't really see any development. So hopefully this is the start of a new era where App Center will be our go to mobile command center for everything that has to do with .NET MAUI. At least now you can use it with your crashes, your analytics, and your distribution of apps. So that's really cool. I did mention at the beginning the UI test, so that's something that has been ongoing. We're investigating at Microsoft to make that happen for .NET MAUI as well, so stay tuned for that. We don't have any official thing to report right now, but it's being worked on, so keep your eyes on this space. Basically, I hope you like this video. Let me know if there's anything of the sections or App Center that you want to see in more detail now that we have the official support coming. It's still in preview, but I have good hopes that this will be released so that you can use it in public applications as well. Let me know down in the comments if you want to see more about that. While you're down there, please click the like button so that this video can spread to more other people to let them know that App Center is back. Oh yeah! And subscribe to my channel. If you haven't done so already, maybe you want to check out a little bit more videos on .NET MAUI. Check out this playlist for that. Check out this recommended video, which is recommended especially for you. And I'll be seeing you for the next video.
Info
Channel: Gerald Versluis
Views: 9,541
Rating: undefined out of 5
Keywords: .net maui, .net 6, dotnet maui, .net 6 maui, dotnet maui tutorial, .net 6 xamarin, visual studio 2022, app center, app center .net maui, dotnet maui app center, app center distribute, app center analytics, app center crashes, app center crashlytics, .net maui crash reporting, dotnet maui crash reporting, dotnet maui analytics, .net maui analytics, maui app center support, app center tutorial, app center test, .net maui ui test, dotnet maui ui test, microsoft app center
Id: Bz1XLecJlXc
Channel Id: undefined
Length: 17min 38sec (1058 seconds)
Published: Tue Oct 04 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.