Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/sui-js/src/ua-parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export const LEGITIMATE_CRAWLER_USER_AGENTS = [
'bingbot',
'linkedinbot',
'mediapartners-google',
'debugbear'
'debugbear',
'spider'
]

export const stats = userAgent => {
Expand Down
8 changes: 8 additions & 0 deletions packages/sui-react-web-vitals/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ export default function WebVitalsReporter({
}
]
: []),
...(typeof browser?.isBot === 'boolean'
? [
{
key: 'is_bot',
value: browser.isBot
}
]
: []),
{
key: 'browserEngine',
value: browserEngine
Expand Down
73 changes: 73 additions & 0 deletions packages/sui-react-web-vitals/test/browser/indexSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,79 @@ describe('WebVitalsReporter', () => {
})
})

it('should not include isBot tag when browser.isBot is not set', async () => {
const logger = {distribution: sinon.spy()}
const reporter = {
onTTFB: fn => {
fn({name: 'TTFB', value: 10, entries: [], attribution: {}})
}
}
render(<WebVitalsReporter metrics={[METRICS.TTFB]} allowed={['/']} reporter={reporter} />, {logger})
await waitFor(() => [
expect(
logger.distribution.calledWith({
name: 'cwv',
amount: 10,
tags: [
{key: 'name', value: 'ttfb'},
{key: 'pathname', value: '/'},
{key: 'browserEngine', value: 'Other'}
]
})
).to.be.true
])
})

it('should include isBot: true tag when browser.isBot is true', async () => {
const logger = {distribution: sinon.spy()}
const reporter = {
onTTFB: fn => {
fn({name: 'TTFB', value: 10, entries: [], attribution: {}})
}
}
const browser = {isBot: true}
render(<WebVitalsReporter metrics={[METRICS.TTFB]} allowed={['/']} reporter={reporter} />, {logger, browser})
await waitFor(() => [
expect(
logger.distribution.calledWith({
name: 'cwv',
amount: 10,
tags: [
{key: 'name', value: 'ttfb'},
{key: 'pathname', value: '/'},
{key: 'is_bot', value: true},
{key: 'browserEngine', value: 'Other'}
]
})
).to.be.true
])
})

it('should include isBot: false tag when browser.isBot is false', async () => {
const logger = {distribution: sinon.spy()}
const reporter = {
onTTFB: fn => {
fn({name: 'TTFB', value: 10, entries: [], attribution: {}})
}
}
const browser = {isBot: false}
render(<WebVitalsReporter metrics={[METRICS.TTFB]} allowed={['/']} reporter={reporter} />, {logger, browser})
await waitFor(() => [
expect(
logger.distribution.calledWith({
name: 'cwv',
amount: 10,
tags: [
{key: 'name', value: 'ttfb'},
{key: 'pathname', value: '/'},
{key: 'is_bot', value: false},
{key: 'browserEngine', value: 'Other'}
]
})
).to.be.true
])
})

it('should track TTFB using logger distribution with browser in context', async () => {
const logger = {
distribution: sinon.spy()
Expand Down
Loading