0

I've developed a small Xamarin.Forms.Shell app: this app contains 4 tabs, where the default HomePage contains some basic informations.

I'm using AppCenter to track some events, like pages displays, users clicks, APIs calls,...

In the App.xaml.cs I've specified 2 cases (Debug/prod) to register AppCenter:

protected override void OnStart()
{
    // AppCenter
#if DEBUG
    AppCenter.Start("ios=xxx;" +
            "android=yyy;",
            typeof(Analytics), typeof(Crashes));
#else
    AppCenter.Start("ios=aaa;" +
            "android=bbb;",
            typeof(Analytics), typeof(Crashes));
#endif
}

Then, on the HomePage's ViewModel, I'm doing this:

public HomeViewModel()
{
    _eventTracker = new AppCenterEventTracker();
    //...
    _eventTracker.Display("HomePage");
}

Which refers to:

public virtual void Display(string page, ICollection<KeyValuePair<string, string>> optionalParams = null)
{
    var mainParams = new List<KeyValuePair<string, string>>
    {
        new KeyValuePair<string, string>(EventProperty.Page, page),
    };
    Analytics.TrackEvent(EventType.Display, BuildParameters(mainParams, optionalParams));
}

On the NewsPage ViewModel that is displayed through another tab, the code is:

public NewsViewModel()
{
    _eventTracker = new AppCenterEventTracker();
    //...
    _eventTracker.Display("NewsPage");
}

This works well in Debug mode for iOS and Android: I can retrieve this event in AppCenter for all pages (the HomePage and other pages like NewsPage)

But when the app is built in Release mode, or through AppCenter, it's not the case for the HomePage: I only retrieve this event for iOS, but not for Android. For the other pages like NewsPage, I don't encounter any issue: the display is well taken into account...

So I think that the issue is related to the tab that is displayed by default in my app: the HomePage.

Would you have an explanation?

Edit:

Thanks to @Dmitriy Kirakosyan, I did some new tests: I've seen that in Debug mode too, the HomePage display's event is no longer tracked. In AppCenter I can see traces dating back for long weeks ago, but not for the latest weeks.

This could be related to the packages updates (Xamarin.Forms, AppCenter, ...) cause I didn't change the AppCenter initialization or the event tracking...

What is strange is that I can see in Debug mode that AppCenter.Start() is well called before the HomePage display tracking.

But when I check the values of AppCenter.Configured or Analytics.IsEnabledAsync() just before this tracking, there are both False:

var test1 = AppCenter.Configured;
var test2 = Analytics.IsEnabledAsync().Result;
_eventTracker.Display(EventPage.HomePage);
Gold.strike
  • 1,269
  • 13
  • 47
  • check [linker settings](https://learn.microsoft.com/en-US/xamarin/android/deploy-test/linker) for release mode – magicandre1981 Dec 17 '20 at 15:00
  • I'm using the "Link SDK Assemblies" option. But if it's related to this, I should neither have the tracking for the other pages, as it's related to the same assembly, isn't it? And as I explained, the tracking of the other pages is well managed in AppCenter: it's only for the HomePage that I don't get the information... – Gold.strike Dec 17 '20 at 15:05
  • I've tried with "Don't link" option, but it's the same result. So I don't have any idea... – Gold.strike Dec 17 '20 at 18:31
  • Can you edit the question and add the code for AppCenterEventTracker.cs? I have a hunch that you're not calling `AppCenter.Start`: https://learn.microsoft.com/en-us/appcenter/sdk/getting-started/xamarin#423-xamarinforms – Brandon Minnick Dec 17 '20 at 19:40
  • Hi @BrandonMinnick I've added some code and explanations. The call to `AppCenter.Start()` is well done as the other pages display are well visible in **AppCenter**: it's only the **HomePage** that I can't see.... – Gold.strike Dec 17 '20 at 19:53
  • Double check the unique ID that you're passing into AppCenter.Start for the Release configuration and ensure it matches the unique ID that App Center provides. This is the only thing I can think of that explains why your code is working in Debug and not in Release. – Brandon Minnick Dec 17 '20 at 19:59
  • It's not possible: for the other pages than **HomePage**, I can see the display events in AppCenter for the Release. – Gold.strike Dec 18 '20 at 07:49
  • Could you check if AppCenter is configured in the `HomeViewModel()` ctor? Eg. check if `AppCenter.Configured` and `Analytics.IsEnabledAsync()` return `true`. – Dmitriy Kirakosyan Dec 23 '20 at 17:40
  • Hi @DmitriyKirakosyan I've checked the values: both are `False` in `Debug` and `Release` mode. If I check the same values on another ViewModel there are `True`. However, the event is well managed by AppCenter in `Debug`mode... – Gold.strike Jan 06 '21 at 13:36
  • @Gold.strike, I'll try to reproduce it. Meanwhile, if you have time to create a sample app demonstrating this issue, that would help a lot. – Dmitriy Kirakosyan Jan 06 '21 at 14:29
  • @Gold.strike For some reason your `HomeViewModel` is initializing faster than AppCenter, even though you call AppCenter in `OnStart`. Could you also check if/why the view model ctor is called before(or in parallel?) the AppCenter.Start. You can check that via debugging and inspecting the call stack. – Dmitriy Kirakosyan Jan 06 '21 at 14:32
  • @DmitriyKirakosyan I've did some news tests and I've edited the description of the issue. Finally I encounter the same issue in Debug/Release mode. It's strange as it seems that `OnStart` is well called before the `HomeViewModel` Ctor... – Gold.strike Jan 07 '21 at 08:59
  • 1
    @Gold.strike, I confirm that the issue exists for appcenter dotnet sdk. It's because your first fragment is creating in App.xaml.cs constructor. So your main view model is creating earlier than OnStart is called in which AppCenter is starting. So put the AppCenter.Start in the App's constructor instead right before your HomePage view creation. Let me know if it works. – Dmitriy Kirakosyan Jan 11 '21 at 21:39
  • @DmitriyKirakosyan in Debug mode it seems to be good. I will create new realease on AppCenter to check if it's good too. – Gold.strike Jan 25 '21 at 14:36

0 Answers0