Countly / countly-sdk-flutter-bridge

Flutter SDK for Countly Product Analytics Platform
https://count.ly
MIT License
29 stars 18 forks source link

Custom Http headers are not applied on non-queued requests on iOS #298

Open sbatezat opened 1 day ago

sbatezat commented 1 day ago

AvailableFeedbackWidgets not working anymore on iOS

final feedbackWidgets = await Countly.getAvailableFeedbackWidgets();
final empty = feedbackWidgets.presentableFeedback.isEmpty

empty is returning false on Android (this is ok) and true on iOS

It was working previously and I'm still looking for the root cause...

ijunaid commented 1 day ago

Hi @sbatezat, Thank you for reporting this issue. Could you please print or check the values inside presentableFeedbacks to help us investigate further?

sbatezat commented 1 day ago

presentableFeedbacks is empty, and retrievedWidgets (= await _channel.invokeMethod('getAvailableFeedbackWidgets')) is too

ijunaid commented 1 day ago

Thank you for checking that. I’ll investigate this issue and get back to you soon.

sbatezat commented 1 day ago

If it helps:

image

sbatezat commented 1 day ago

Maybe because, according to this changelog, getFeedbackWidget is deprecated on iOS ?

https://github.com/Countly/countly-sdk-flutter-bridge/pull/285/files#diff-3111fcf07123eea4da5d6438464033e1fbbbedc580067636e09f7da49a4a6a4f

ijunaid commented 1 day ago

Good observation! However, since the deprecated method uses the same underlying implementation as getAvailableFeedbackWidgets(), the issue is likely unrelated to that. I’ll continue investigating and update you soon.

ijunaid commented 1 day ago

Could you please print or check the values of feedbackWidgets.presentableFeedback on Android as well?

ijunaid commented 1 day ago

It seems possible that the user you're checking on iOS may have already completed or submitted the available feedback, which could be why no new feedback is being retrieved. Could you try testing with a different device ID?

sbatezat commented 1 day ago

Unfortunately, I've got only one iOS device. What do you mean by "have already completed or submitted the available feedback"? I have always been able to publish multiple feedback and I've got only one available widget, which has never changed

ijunaid commented 1 day ago

Each user has a unique device ID. When feedback is submitted, the server marks it as completed and only returns feedbacks that hasn't been completed yet for that user.

Since you mentioned having only one iOS device, you can try reinstalling the app. This will automatically assign a new device ID if you're not explicitly providing one during initialization or changing it after initialization.

If you want to change the device ID without merging, you can use the changeDeviceId method (which is the recommended approach in your case), as described here: https://support.countly.com/hc/en-us/articles/34539364044697-Flutter-24-4#h_01H930GAQ682G16Z7M570XKSPD

In new versions we have added setID method for easier handling, as explained here: https://support.countly.com/hc/en-us/articles/360037944212-Flutter#h_01H930GAQ682G16Z7M570XKSPD

sbatezat commented 1 day ago

When feedback is submitted, the server marks it as completed and only returns feedbacks that hasn't been completed yet for that user.

I've got tons of "multiple" feedback for the same user (i'm setting a custom ID), it's working fine (until now, and just broken only on iOS) and it's "my" expected behavior.

ijunaid commented 1 day ago

Could you please try with different device ID?

sbatezat commented 1 day ago

Same behavior: a list of available widgets (1) on Android, but an empty list on iOS.

sbatezat commented 1 day ago

Could you please print or check the values of feedbackWidgets.presentableFeedback on Android as well?

image

sbatezat commented 1 day ago

It's very weird my users have a unique ID and are using the same widget to send multiple feedback since ever, and you tell me it's not possible. Maybe we are not talking about the same thing? I'm talking about rating widgets.

image

I don't know if there is other with different rules.

ijunaid commented 1 day ago

There are three types of feedback widgets (Survey, NPS, and Ratings) Survey and NPS are 1 time only by default, but they can be adjusted to be shown all the time. On the other hand Rating widgets are shown all the time. I have again checked Rating widget on iOS and its working for me.

sbatezat commented 1 day ago

On the other hand Rating widgets are shown all the time.

Ok! All good on that side 👍

With the same source code, it's working on Android and not on iOS for my app. I'm wondering about this PR https://github.com/Countly/countly-sdk-flutter-bridge/pull/284 if the available widget request is not done with custom header on iOS for any reason. But there is no error message apparently so I doubt it's the issue.

ijunaid commented 1 day ago

Rating widgets also have the option to set targeting users, could you please verify the targeting users of your rating widget on dashboard?

sbatezat commented 1 day ago

It's set on "all users". Moreover, i'm working with the same id (my email) on both Android & iOS, so it cannot be link to the user part.

ijunaid commented 1 day ago

To help diagnose the issue further, could you please try accessing the following URL in your browser by replacing the placeholders with your actual server URL, app key, and device ID?

https://YOUR_SERVER_URL/o/sdk?method=feedback&app_key=YOUR_APP_KEY&device_id=YOUR_DEVICE_ID

Please check the response using both your iOS and Android device IDs separately and share the results. This will help us understand if the server is returning the correct feedback widgets for each device.

sbatezat commented 1 day ago

My device id is the same for both Android & iOS, so I'll have only one result. Here it is:

{
  "result": [
    {
      "_id": "6555368f72ce854e9c0c453d",
      "type": "rating",
      "showPolicy": "afterPageLoad",
      "appearance": {
        "position": "mleft",
        "bg_color": "#123456",
        "text_color": "#fff",
        "text": "Retour d'expérience",
        "size": "m",
        "hideS": true
      },
      "tg": [
        "/"
      ],
      "name": "Donnez-nous votre avis !"
    }
  ]
}
ijunaid commented 1 day ago

Great!, response looks ok Can you please check that URL with the device ID you had changed (without merge) for iOS?

sbatezat commented 1 day ago

My device id is the same for both Android & iOS for months

ijunaid commented 1 day ago

Would it be possible for you to open your iOS project in Xcode and add a breakpoint at line 506 in the CountlyFeedbacksInternal.mfile? Please check and share the values of request and the constructed URL at that point. This will help us verify if the request is being formed correctly.

Screenshot_FeebackInternal
sbatezat commented 1 day ago

The request seems to be fine.

I've found the origin. My API Management in front of Countly instance is returning 403.

image

There is an error field populated on iOS part but not on Flutter side.

image

I'm looking for request details to see if my custom header (needed by my API Management) is set, but probably not.

sbatezat commented 1 day ago

Ok, I can confirm it's an issue with #284

There is a "nil" on NSURLSession.sharedSession.configuration.HTTPAdditionalHeaders... Updating manually the task like this is working fine:

image

Of course, I've called config.setCustomNetworkRequestHeaders(headers);

sbatezat commented 1 day ago

@ijunaid could you please confirm it's an iOS issue and ask the iOS team to fix it?

Whatever, I keep this issue opened, as Flutter Countly is using a deprecated method AND do not log iOS error on that case

ijunaid commented 16 hours ago

@sbatezat, thanks for the update. I’ll discuss this internally with the team and work on fixing the issue.