Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile Safari webview fails to match user agent #458

Open
RDIL opened this issue Nov 20, 2024 · 4 comments
Open

Mobile Safari webview fails to match user agent #458

RDIL opened this issue Nov 20, 2024 · 4 comments

Comments

@RDIL
Copy link

RDIL commented Nov 20, 2024

Hey,

We at Genius are facing an issue where we're seeing a large portion of our users having no set mobile safari browser version, and after some investigating, we tracked down the cause. It turns out that if you open a webview inside another app (e.g. if you are using the twitter app and click on a link there), it opens in a browser instance within that app, making the user agent matching fail.

It would be great if Mixpanel could automatically translate the iOS version to the bundled Safari webkit version (which is what we had to do in order to fix this), so that we always have accurate Safari versions, that would be awesome!

We found what could be considered a workaround, not for overall version but for specific browser features, by adding a custom computed property. For instance, we used this query to determine what percentage of our users would support a new CSS feature:

let(real_browser_version, IFS(
  (@"""{"label":"Browser Version","propertyDefaultType":"string","resourceType":"event","type":"string","value":"$browser_version"}"""@ and @"""{"label":"Browser","propertyDefaultType":"string","resourceType":"event","type":"string","value":"$browser"}"""@ != "Chrome iOS"), @"""{"label":"Browser Version","propertyDefaultType":"string","resourceType":"event","type":"string","value":"$browser_version"}"""@,
  @"""{"label":"Browser","propertyDefaultType":"string","resourceType":"event","type":"string","value":"$browser"}"""@ in ["Mobile Safari", "Chrome iOS"], 
    let(underscores, REGEX_EXTRACT(@"""{"label":"user_agent","propertyDefaultType":"string","resourceType":"event","type":"string","value":"user_agent"}"""@, 
      "iPhone OS (\\d+(_\\d+)?(_\\d+)?)", 1),
      REGEX_REPLACE(underscores, "_", "."))),

    versions, split(real_browser_version, "."),
    major_version, number(versions[0]),
    minor_version, number(versions[1]),

  IFS(
    @"""{"label":"Browser","propertyDefaultType":"string","resourceType":"event","type":"string","value":"$browser"}"""@ == "Chrome", major_version >= 117,
    (@"""{"label":"Browser","propertyDefaultType":"string","resourceType":"event","type":"string","value":"$browser"}"""@ in ["Mobile Safari", "Chrome iOS"]), 
      major_version > 17 or (major_version == 17 and minor_version >= 5),
    
    true, "other"
  )
)
@tdumitrescu
Copy link
Member

Wow, that's a pretty intense custom property. Would you be able to post some sample user agent strings here and the expected browser + version props that we should extract? That would help get this updated faster. Thanks.

@RDIL
Copy link
Author

RDIL commented Nov 20, 2024

Sure. Just as a warning, it seems that the UAs don't contain the exact Safari version, but do contain the OS version (which is most of the time roughly the same), so there would potentially need to be some kind of lookup table.

Mozilla/5.0 (iPhone; CPU iPhone OS 18_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/343.0.695551749 Mobile/15E148 Safari/604.1 -> 18.1 (Google Search app)

Mozilla/5.0 (iPhone; CPU iPhone OS 18_0_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 YaBrowser/24.10.5.292.10 YaApp_iOS/2410.5 YaApp_iOS_Browser/2410.5 Safari/604.1 SA/3 -> 18.0.1 (Yandex Browser app)

Mozilla/5.0 (iPhone; CPU iPhone OS 17_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/343.0.695551749 Mobile/15E148 Safari/604.1 -> 17.6 (Google Search app)

@nightpool
Copy link

Note, I think the output of Mozilla/5.0 (iPhone; CPU iPhone OS 18_0_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 YaBrowser/24.10.5.292.10 YaApp_iOS/2410.5 YaApp_iOS_Browser/2410.5 Safari/604.1 SA/3 -> 18.1 (Yandex Browser app) should be Safari 18.0.1, not Safari 18.1

@nightpool
Copy link

nightpool commented Nov 21, 2024

Another example for iPad:

User Agent Extracted Safari version Embedding app
Mozilla/5.0 (iPad; CPU OS 17_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/343.0.695551749 Mobile/15E148 Safari/604.1 17.7 Google search app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants