fix: Move tablet detection logic into detectDeviceType for consistent…#3170
Merged
fix: Move tablet detection logic into detectDeviceType for consistent…#3170
Conversation
… classification across all call sites
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
7 tasks
| const ua = typeof navigator !== 'undefined' && navigator.userAgent ? navigator.userAgent : '' | ||
|
|
||
| deviceType = detectDeviceType(ua) | ||
| const nav = typeof navigator !== 'undefined' ? (navigator as any) : undefined |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Member
Author
There was a problem hiding this comment.
That was a reference to the fix in #3154, this was already fixed in a subsequent commit
Contributor
Contributor
|
Size Change: +7.92 kB (+0.12%) Total Size: 6.7 MB
ℹ️ View Unchanged
|
marandaneto
approved these changes
Mar 1, 2026
lricoy
approved these changes
Mar 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Implementing fix suggested by @lricoy and @marandaneto in #3154. The Android tablet detection logic (Client Hints API + touch + screen dp heuristic) was implemented in
event-utils.ts, butdetectDeviceType()is called from multiple places, notablymatcher-utils.tswhich powers device type targeting for surveys and product tours. Those calls didn't benefit from the changes in #3154, so a Chrome-on-Android-tablet user in desktop mode would be correctly identified asTabletin event properties but still be incorrectly identified asDesktopfor surveys, product tours etc, and react native web wouldn't get the fix either.Changes
Moved the supplementary tablet detection logic into
detectDeviceType()in@posthog/core, with an optionaloptionsparameter for backwards compatibility, and so call sites can pass browser signals:packages/core/src/utils/user-agent-utils.ts—detectDeviceType()now accepts optionaloptionswithuserAgentDataPlatform,maxTouchPoints,screenWidth,screenHeight,devicePixelRatio. The Android tablet check runs right before the'Desktop'fallback. Fully backwards compatible — callers that don't pass options get the same behavior as before.packages/browser/src/utils/event-utils.ts— Removed the post-hoc override block. Now passes browser signals inline todetectDeviceType().packages/browser/src/extensions/utils/matcher-utils.ts— Updated to pass browser signals todetectDeviceType(), so surveys and product tours device type targeting now correctly identifies Android tablets in desktop mode.Tests — 5 new unit tests in
user-agent-utils.test.tsfordetectDeviceTypewith options (tablet, phone, high DPR, backwards compat, non-Android platform). 6 existing integration tests inevent-utils.test.tsunchanged and passing.Tests: 94 suites, 3447 tests passed, 0 failures
Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file