Skip to main content

User Agent

Getting client interface

useInterfaceType

this returns just 'desktop' or 'mobile'

import { useInterfaceType } from '@traveloka/core';
const interfaceType = useInterfaceType();

useClientInterface

This one is a bit more precise because we used to have mobile PWA. This returns "desktop", "mobile", or "mobile-pwa".

import { useClientInterface } from '@traveloka/core';
const clientInterface = useClientInterface();

Parsing user agent

getBrowserInfo

This parses the browser's user-agent into a more convenient data.

import { getInterfaceType } from '@traveloka/core';

type BrowserInfo = {
userAgent: string;
name: string;
version: string;
major: string;
compatible: boolean;
};

const browserInfo: BrowserInfo = getBrowserInfo();

isBot

Checks if the user-agent identifies itself as a bot.

import { isBot } from '@traveloka/core';

export async function getSearchRoomsProps(
ctx: NextPageContext,
appContext: TravelokaAppContext
) {
const req = ctx.req as Request;
const userAgent = req?.get('user-agent') || 'undefined';

if (isBot(userAgent.toLowerCase())) {
return {};
}
return { data: 1234 };
}