Skip to content

Commit

Permalink
fix: include raw user agent in event properties (#868)
Browse files Browse the repository at this point in the history
* fix: include raw user agent in event properties

* remove old js tests
  • Loading branch information
pauldambra authored Oct 30, 2023
1 parent bf81856 commit 97029d9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
9 changes: 0 additions & 9 deletions src/__tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ function userAgentFor(botString) {
return `Mozilla/5.0 (compatible; ${botString}/${randOne}; +http://a.com/bot/${randTwo})`
}

describe(`utils.js`, () => {
it('should have $host and $pathname in properties', () => {
const properties = _info.properties()
expect(properties['$current_url']).toBeDefined()
expect(properties['$host']).toBeDefined()
expect(properties['$pathname']).toBeDefined()
})
})

describe('_.copyAndTruncateStrings', () => {
given('subject', () => _copyAndTruncateStrings(given.target, given.maxStringLength))

Expand Down
32 changes: 32 additions & 0 deletions src/__tests__/utils/event-utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { _info } from '../../utils/event-utils'
import * as globals from '../../utils/globals'

jest.mock('../../utils/globals')

describe(`event-utils`, () => {
it('should have $host and $pathname in properties', () => {
const properties = _info.properties()
expect(properties['$current_url']).toBeDefined()
expect(properties['$host']).toBeDefined()
expect(properties['$pathname']).toBeDefined()
})

it('should have user agent in properties', () => {
// TS doesn't like it but we can assign userAgent
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
globals['userAgent'] = 'blah'
const properties = _info.properties()
expect(properties['$raw_user_agent']).toBe('blah')
})

it('should truncate very long user agents in properties', () => {
// TS doesn't like it but we can assign userAgent
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
globals['userAgent'] = 'a'.repeat(1001)
const properties = _info.properties()
expect(properties['$raw_user_agent'].length).toBe(1000)
expect(properties['$raw_user_agent'].substring(995)).toBe('aa...')
})
})
1 change: 1 addition & 0 deletions src/utils/event-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export const _info = {
$current_url: window?.location.href,
$host: window?.location.host,
$pathname: window?.location.pathname,
$raw_user_agent: userAgent.length > 1000 ? userAgent.substring(0, 997) + '...' : userAgent,
$browser_version: _info.browserVersion(userAgent, navigator.vendor, (window as any).opera),
$browser_language: _info.browserLanguage(),
$screen_height: window?.screen.height,
Expand Down

0 comments on commit 97029d9

Please sign in to comment.