Skip to content

Commit 1ab96b8

Browse files
authored
Merge pull request #1989 from SUI-Components/feat/NOJIRA-add-is-bot-web-vitals
feat(packages/sui-react-web-vitals): add web vitals is bot flag
2 parents 23ea406 + bf41700 commit 1ab96b8

3 files changed

Lines changed: 83 additions & 1 deletion

File tree

packages/sui-js/src/ua-parser/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export const LEGITIMATE_CRAWLER_USER_AGENTS = [
66
'bingbot',
77
'linkedinbot',
88
'mediapartners-google',
9-
'debugbear'
9+
'debugbear',
10+
'spider'
1011
]
1112

1213
export const stats = userAgent => {

packages/sui-react-web-vitals/src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ export default function WebVitalsReporter({
197197
}
198198
]
199199
: []),
200+
...(typeof browser?.isBot === 'boolean'
201+
? [
202+
{
203+
key: 'is_bot',
204+
value: browser.isBot
205+
}
206+
]
207+
: []),
200208
{
201209
key: 'browserEngine',
202210
value: browserEngine

packages/sui-react-web-vitals/test/browser/indexSpec.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,79 @@ describe('WebVitalsReporter', () => {
250250
})
251251
})
252252

253+
it('should not include isBot tag when browser.isBot is not set', async () => {
254+
const logger = {distribution: sinon.spy()}
255+
const reporter = {
256+
onTTFB: fn => {
257+
fn({name: 'TTFB', value: 10, entries: [], attribution: {}})
258+
}
259+
}
260+
render(<WebVitalsReporter metrics={[METRICS.TTFB]} allowed={['/']} reporter={reporter} />, {logger})
261+
await waitFor(() => [
262+
expect(
263+
logger.distribution.calledWith({
264+
name: 'cwv',
265+
amount: 10,
266+
tags: [
267+
{key: 'name', value: 'ttfb'},
268+
{key: 'pathname', value: '/'},
269+
{key: 'browserEngine', value: 'Other'}
270+
]
271+
})
272+
).to.be.true
273+
])
274+
})
275+
276+
it('should include isBot: true tag when browser.isBot is true', async () => {
277+
const logger = {distribution: sinon.spy()}
278+
const reporter = {
279+
onTTFB: fn => {
280+
fn({name: 'TTFB', value: 10, entries: [], attribution: {}})
281+
}
282+
}
283+
const browser = {isBot: true}
284+
render(<WebVitalsReporter metrics={[METRICS.TTFB]} allowed={['/']} reporter={reporter} />, {logger, browser})
285+
await waitFor(() => [
286+
expect(
287+
logger.distribution.calledWith({
288+
name: 'cwv',
289+
amount: 10,
290+
tags: [
291+
{key: 'name', value: 'ttfb'},
292+
{key: 'pathname', value: '/'},
293+
{key: 'is_bot', value: true},
294+
{key: 'browserEngine', value: 'Other'}
295+
]
296+
})
297+
).to.be.true
298+
])
299+
})
300+
301+
it('should include isBot: false tag when browser.isBot is false', async () => {
302+
const logger = {distribution: sinon.spy()}
303+
const reporter = {
304+
onTTFB: fn => {
305+
fn({name: 'TTFB', value: 10, entries: [], attribution: {}})
306+
}
307+
}
308+
const browser = {isBot: false}
309+
render(<WebVitalsReporter metrics={[METRICS.TTFB]} allowed={['/']} reporter={reporter} />, {logger, browser})
310+
await waitFor(() => [
311+
expect(
312+
logger.distribution.calledWith({
313+
name: 'cwv',
314+
amount: 10,
315+
tags: [
316+
{key: 'name', value: 'ttfb'},
317+
{key: 'pathname', value: '/'},
318+
{key: 'is_bot', value: false},
319+
{key: 'browserEngine', value: 'Other'}
320+
]
321+
})
322+
).to.be.true
323+
])
324+
})
325+
253326
it('should track TTFB using logger distribution with browser in context', async () => {
254327
const logger = {
255328
distribution: sinon.spy()

0 commit comments

Comments
 (0)