snowplow / snowplow-ios-tracker

Snowplow event tracker for Swift and Objective-C. Add analytics to your iOS, macOS, tvOS and watchOS apps and games
http://snowplow.io
Apache License 2.0
81 stars 93 forks source link

Setting useragent in TrackerController.Subject doesn't seem to affect resulting request #903

Closed DanilShkarupin closed 4 months ago

DanilShkarupin commented 4 months ago

Describe the bug Setting useragent in TrackerController.Subject doesn't seem to affect resulting request. In documentation it seems to be intended for this purpose.

To Reproduce

  1. In TrackerController set subject?.useragent to some custom value
  2. Send tracking event

Expected behavior user-agent header value in sent request equals your custom value

Screenshots If applicable, add screenshots to help explain your problem.

Device information (please complete the following information):

Additional context The only other way I found to override user agent was to set it in DefaultNetworkConnection.requestHeaders. When I was debugging this behaviour, I found that custom value of user-agent gets lost in DefaultNetworkConnection, when you create URLRequest from Request.

matus-tomlein commented 4 months ago

Hi @DanilShkarupin, thank you for reporting this problem!

Have you tried configuring the useragent when creating the tracker? I mean something like:

let subjectConfig = SubjectConfiguration()
    .useragent("my-user-agent")

let networkConfig = NetworkConfiguration(endpoint: "https://snowplow-collector-url.com")
Snowplow.createTracker(
    namespace: "appTracker",
    network: networkConfig,
    configurations: [subjectConfig]
)
DanilShkarupin commented 4 months ago

Hi @matus-tomlein, thank you for your suggestion. It's a better way to configure Subject and it will work for my case as I don't expect useragent to change.

Unfortunately issue still persists and this value doesn't show up in outgoing requests.

matus-tomlein commented 4 months ago

Thanks for checking that @DanilShkarupin!

I have tried to reproduce the problem, but don't seem to be able to. I set the useragent using the SubjectConfiguration and passed that to createTracker. When I checked the tracked events in Snowplow Micro, I could see that the useragent property under event was correctly set.

To clarify, overriding the useragent in this way doesn't change the HTTP request headers – those will not change if you configure the subject useragent. However, inside the event body, you should be able to see the useragent property that will override the information in the HTTP headers.

Where are you checking the useragent property? Is it not present in the event body as well?

DanilShkarupin commented 4 months ago

Thanks @matus-tomlein,

When I check ua value inside event body it has expected value. I was expecting to see new value in headers, but from your response it seems it's not supposed to be here.

Issue is resolved then.