Introduction
Xamarin Insights is used for using analytics and crash reporting for Xamarin. For more details, you can click here.
Let’s start
Before starting an Android application, we need to register the Xamarin Insights dashboard new app.
Step 1
Goto https://insights.xamarin.com/. Now, click New App button. Open New Window.
Step 2
In the new window, enter new app's name. Click "Create new app" button. Afterwards, the system generates new API key. This key uses Android app, so copy the API key value.
API key
Step 3
Open Visual Studio->New Project->Templates->Visual C#->Android->Blank App.
Select Blank App. Give your project a name and assign the project location.
Step 4
Go to Solution Explorer-> Project Name-> References. Right click on "Manage NuGet Packages" and open new dialog box. This dialog box is required to search Xamarin Insights, followed by installing Xamarin.Insights Packages.
Step 5
Now, we need to initialize Xamarin.Insights in MainActvity.cs and add the new namespace given below.
using Xamarin;
Step 6
Open Solution Explorer-> Project Name-> MainActivity.cs. Click Open CS code page view, followed by adding namespaces given below.
C# Code
- namespace XamarinInsights {
- [Activity(Label = "XamarinInsights", MainLauncher = true, Icon = "@drawable/icon")]
- public class MainActivity: Activity {
- Context context;
- protected override void OnCreate(Bundle bundle) {
- base.OnCreate(bundle);
- SetContentView(Resource.Layout.Main);
- Insights.Initialize("API_KEY", this);
- }
- }
Step 7
Now, implement exceptions result in Xamarin Insights.
C# Code
- try {
- Toast.MakeText(context, "Test", ToastLength.Short).Show();
- } catch (System.Exception error) {
- Insights.Report(error);
- }
Step 8
Now, implement the Exceptions result with the user data in Insights.
C# Code
- try {
- Toast.MakeText(context, "Test", ToastLength.Short).Show();
- } catch (System.Exception error) {
- var UserInfo = new Dictionary < string,
- string > {
- {
- "Email",
- "[email protected]"
- },
- {
- "Name",
- "Anbu Mani"
- }
- };
- Insights.Report(error);
- Insights.Identify("USER001", UserInfo);
- }
- if ('this_is' == /an_example/) {
- of_beautifier();
- } else {
- var a = b ? (c % d) : e[f];
- }
Step 9
Press F5 or build and run the application. Check the Xamarin.Insights dashboard.
Step 10
Go to Xamarin.Insights dashboard and we will see the exception log. In this log, we can get particular user information once this error is fixed. Afterwards, change the status to open/close.
Finally, we have successfully created Android app using Xamarin Insights.