Events not tracked in App Center

3.3k views Asked by At

I am trying new Visual Studio App Center platform for mobile apps. It gives me the crashes and the installed versions OK, so the app secret and SDK are configured OK.

But when I try to track custom Events, according to this tutorial I get "No events found" in the Mobile Center dashboard. I try with my app in release and debug mode, without results.

My code (Xamarin.Forms):

    public MyClass()
    {
        InitializeComponent();

        Analytics.SetEnabledAsync(true);
        Analytics.TrackEvent("Video clicked", new Dictionary<string, string> {
            { "Category", "Music" },
            { "FileName", "favorite.avi"}
        });
    }

There is the constructor, so I am sure that these lines are executed.

2

There are 2 answers

0
Josecanalla On

Solved. I need to execute the lines in an async method, not in the constructor.

0
Guillaume Perrot On

MobileCenter.Start needs to be called before Analytics.TrackEvent or Analytics.SetEnabledAsync.

If you are using constructor, then you need to move MobileCenter.Start to constructor as well.

Your solution is working probably because you made that code execute later (and thus after MobileCenter.Start) with async but you don't need to do that (and you don't need to call SetEnabledAsync at all, it's true by default and persisted).