0

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.

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
Josecanalla
  • 455
  • 3
  • 8
  • 17
  • 1
    Hey @Jossecanalla, This is Benjamin who works on the Mobile Center SDK team. I'm glad you were able to resolve the issue you were seeing. That said, I'd love to find out more why you ran into the issue. Specifically: can you share your setup code with me (and where you are setting up the SDK)? Calling `Analytics.TrackEvent(...)` should work in a constructor, given that the SDK has been setup correctly. If you don't want to share the code here, contact us through intercom (the blue button at the bottom right of the Mobile Center portal) or send a mail to bereimol at microsoft dot com – Ben Scholtysik Oct 02 '17 at 17:21

2 Answers2

1

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).

Guillaume Perrot
  • 4,278
  • 3
  • 27
  • 37
0

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

Josecanalla
  • 455
  • 3
  • 8
  • 17