Xamarin Month: Code Snippets for App Center Analytics

This is the time of the year, that we celebrate the Xamarin Month and the community through the efforts of Luis Matos agreed to share code snippets that will make Xamarin Developers more productive and efficient by fully utilizing the code snippets feature of Visual Studio. With that in mind, I would like to share with you some simple code snippets that I used when integrating App Center analytics for Xamarin.

xamarin-month-code-snippets-luismts.com_

Configuration of Code Snippet Manager

In order to use custom code snippet first you need to download the “.snippet” file from this link as seen in Figure 1.

Figure1
Figure 1. Downloading Custom Code Snippets

After downloading the said files, we can add them in you Visual Studio by under the “Tools -> Code Snippet Manager” menu as show in Figure 2.

Figure2
Figure 2. Accessing the Code Snippets Manager

After clicking the Code Snippet Manager, you should see a “Menu” like in Figure 3.

Figure3
Figure 3. Code Snippet Manager

Let’s try to upload the code snippets by clicking the “Import button” then select all the .snippet files and click open as show in Figure 4.

Figure4
Figure 4. Uploading the .snippet files

After selecting the files to be uploaded, you will be asked on the location of the snippets to be organized which should be under “My Code Snippet” and just click the finish button as shown in Figure 5.

Figure5
Figure 5. Organizing Code snippets.

To verify if you have successfully added the .snippets you need to go to specific programming language which is C# as shown in Figure 6.

Figure6
Figure 6. Code Snippets under My Code Snippets folder

App Center Start

The first code snippet that I would like to share is the initialization or starting of the App Center analytics. Keep in mind that this is only code snippets so this will not automatically download and install the NuGet package needed so that you can use App Center analytics. The good thing for the code App Center analytics code snippets that I have is that it will automatically add the namespace needed for the corresponding code snippet. The expected command is “as” (AppCenter Start) and just click double tab to execute the shortcut command as seen in Figure 7.

Figure7
Figure 7. App Center Start code snippet

App Center Tracking of Simple Events

The second code snippet that I would like to share is the simple tracking of Events in App Center. The expected command is “ates” (AppCenter Track Events Simple) and just click double tab to execute the shortcut command as seen in Figure 8. You can use this shortcut if you just want a straight forward tracking of events.

Figure8
Figure 8. App Center Simple Tracking of Events code snippet

App Center Tracing of Full Events

We have already seen the simple tracking of events, what if you needed more details like app version and information. So the third code snippet that I would like to share is the full tracking of Events in App Center in which you can add information like date, app version, app id and details of the event so that you can thoroughly log events. The expected command is “atef” (AppCenter Track Events Full) and just click double tab to execute the shortcut command as seen in Figure 9.

Figure9
Figure 9. App Center Full Event Tracking code snippet

App Center Tracing of Crashes

The final snippet that I would like to share is the tracking of crashes in App Center. If you have not set you app center analytics to automatically send logs whenever there are app crash that have been encountered you can use this app center crash tracking instead in your try catch statements. The expected command is “atc” (AppCenter Track Crashes) and just click double tab to execute the shortcut command as seen in Figure 10.

Figure10
Figure 10. App Center Tracking of Crashes code snippet

Conclusion

To wrap things up, we discussed on how to simply integrate .snippet files in Visual Studio. I’ve also shared simple App Center code snippets that will prove useful especially on debugging application events as well as app crashes in you Xamarin Application. Hope you’ll try to use my code snippets in your daily Xamarin development as well as inspire you to create your own code snippets. Again a big kudos for Luis Matos for setting up the Xamarin Month Celebration and kindly also check the awesome code snippets from the other cool Xamarin developers that have contributed during this Xamarin month celebration in this link.

Happy Coding 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s