Skip to main content

Application of the browser agent

To use the WhaTap monitoring service, after Sign up, create a project and then apply the WhaTap browser agent to web applications.

See the following video guide.

Installing the WhaTap browser agent​

Follow the instructions on the agent installation screen to apply the WhaTap browser agent code to your web application.

WhaTap Browser Agent Installation

Data collection sampling​

The WhaTap browser agent collects data based on the user session. You can set the percentage of all sessions collected from 0 to 100.

WhaTap browser agent script​

The WhaTap browser agent is provided in the form of an inline script. Add the script code provided by the installation guide to the top in the <head> tag of any HTML page to monitor.

Select one of the following two methods to apply the agent.

  • Async (Asynchronous Load): Loads the WhaTap browser agent asynchronously in your web application.

    • It does not affect the load performance of your web application.

    • There may be missing data such as AJAX or errors that occurred before loading the browser agent.

  • Sync (Synchronous Load): Loads the WhaTap browser agent synchronously in your web application.

    • It is recommended if you want to collect all data when loading your web application.

    • It may affect the load performance of your web application.

ES5 agent for legacy browsers​

The v2 agent (/rum/prod/v2/) does not run on the following browser versions. To collect user data from these browsers as well, apply the ES5 agent.

BrowserVersions that require the ES5 agent
All browsers on iOS and iPadOS (Safari, Chrome, etc.) and in-app WebView13.3 or earlier
Safari (macOS)13.0 or earlier
Chrome, Edge, Android WebView79 or earlier
Firefox73 or earlier
Samsung Internet12 or earlier

On these browsers, the console shows a SyntaxError from whatap-browser-agent.js. The error affects only the agent file, and the web service works normally.

To apply the ES5 agent, change only the agent file address in the installation script to the following value. Leave the other settings, such as the project access key, pcode, and options, as they are. For the Async method, change the 4th argument of the immediately invoked function. For the Sync method, change the src attribute of the <script> tag that loads the agent.

https://repo.whatap-browser-agent.io/rum/es5-prod/v2/whatap-browser-agent.js
Async method example
<script>
(function (w, h, _a, t, a, b) {
w = w[a] = w[a] || {
config: {
projectAccessKey: "{PROJECT_ACCESS_KEY}",
pcode: {PCODE},
sampleRate: 100,
proxyBaseUrl: "{PROXY_BASE_URL}",
},
};
a = h.createElement(_a);
a.async = 1;
a.src = t;
t = h.getElementsByTagName(_a)[0];
t.parentNode.insertBefore(a, t);
})(window, document, 'script', 'https://repo.whatap-browser-agent.io/rum/es5-prod/v2/whatap-browser-agent.js', 'WhatapBrowserAgent', '');
</script>

The ES5 agent also runs on modern browsers. Do not split the file by browser type. Apply the same address to all pages. After applying it, enter WhatapRUM.BUILD_INFO.channel in the browser developer tools console. It returns 'es5-prod'.

Note

The ES5 agent includes code for legacy browser support, so its file is larger than the v2 agent. If none of your users use the browsers in the table above, use the v2 agent.

Loading the script directly and initializing it​

The script in the installation guide stores the settings in the WhatapBrowserAgent global object. When the agent file loads, it calls initialization (init()) and collection start (start()) automatically, so no code changes are needed.

If you load the agent file first with <script src> and then call WhatapRUM.init() yourself, call WhatapRUM.start() on the very next line. From browser agent 3.3.0, init() only prepares the settings and the session, and data collection starts only when start() is called. Up to 3.2.1, calling init() alone started collection, so pages that call only init() receive no data from 3.3.0.

Example of calling init() and start()
<script src="https://repo.whatap-browser-agent.io/rum/prod/v2/whatap-browser-agent.js"></script>
<script>
WhatapRUM.init({
projectAccessKey: "{PROJECT_ACCESS_KEY}",
pcode: {PCODE},
sampleRate: 100,
proxyBaseUrl: "{PROXY_BASE_URL}",
});
WhatapRUM.start();
</script>
  • Call start() right after init() in the same script. If start() is called late, unhandled errors, the Visually Complete point, and long tasks that occur in between are not collected.

  • If you configure start() to be called after obtaining user consent, the period before consent is not collected.

  • To pause collection, call WhatapRUM.stop(). To resume, call WhatapRUM.start(). Supported from browser agent 3.3.0. If you call the two methods in succession, the state of the last call applies.

  • init(), start(), and stop() are methods of the WhatapRUM object. The WhatapBrowserAgent object does not have these methods, so calling WhatapBrowserAgent.init() does not work.

Setting the WhaTap browser agent's options​

It sets the options to apply to the WhaTap browser agent. The options can be set in the Config object of the installation script. You can set the project access keys, percentage of all user sessions, resource domains to exclude from collection, and such.

config example
config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
ignoreOrigins: [ 'https://ignore-site.com/', /^(https?://)([^/]*)(ignore-site.io)(/)(.*)/i ],
}

Option parameters​

projectAccessKey String required

It is a project access key. You can see in the project installation guide (Management > Agent Installation).

config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
proxyBaseUrl: "{proxy_base_url}"
}

pcode Number required

It is a project access key. You can see in the project installation guide (Management > Agent Installation).

config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
proxyBaseUrl: "{proxy_base_url}"
}

sampleRate Number required

You can set the ratio of user sessions to be collected. You can set it from 0 to 100.

config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
proxyBaseUrl: "{proxy_base_url}"
}

proxyBaseUrl String required

The URL that the agent sends collected data to. The value differs by project region, so use the value from the script provided on the Management > Agent installation screen of the WhaTap monitoring service.

This is not the same as the agent script file address (<script src>). If you set it incorrectly, the collected data is not sent.

config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
proxyBaseUrl: "{proxy_base_url}"
}

ignorePageUrls Array<string | RegExp> optional

It is a list of page URLs to exclude from collection. String matching is performed using the startsWith method.

config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
proxyBaseUrl: "{proxy_base_url}"
ignorePageUrls: ["https://test.webpage.com/", "http://localhost:2003/page1/", /^.localhost.$/i]
}

Page load, resource, error, and user action data from pages matching ignorePageUrls is not sent. From browser agent 3.3.0, exclusion is determined for each piece of data by the URL of the screen where it was collected. In an SPA, when the user navigates to an excluded URL, data is excluded from the destination screen onward. Resources, errors, Web Vitals, and other data collected on the previous screen are not excluded, even if they are sent after the navigation. However, the user action that triggered navigation to the excluded screen is excluded. Session replay does not record excluded screens either. For details, see Session replay.

ignoreResources Array<string | RegExp> optional

It is a list of resource URLs to exclude from collection. String matching is performed using the startsWith method.

config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
proxyBaseUrl: "{proxy_base_url}"
ignoreResources: ["https://test.web.com/yard/api/flush", "http://localhost:2003/whatap-browser-agent.js", /^.\/path1\/api.$/i]
}

ignoreErrors Array<string | RegExp> optional

It is a list of browser errors to exclude from collection. String matching is performed using the includes method.

config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
proxyBaseUrl: "{proxy_base_url}"
ignoreErrors: ["cannot read", "cors", "basic"]
}

collectUserClick Boolean optional

Default false

It can collect user click events. For the method to find the collected data, see the following.

config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
proxyBaseUrl: "{proxy_base_url}"
collectUserClick: true
}

sessionReplaySampleRate Number optional

Default 0

It is the ratio of sessions to collect the session replay data. You can set from 0 to 100 for user sessions to collect.

For example, if sampleRate is set to 50 and sessionReplaySampleRate to 20, 50% of all sessions are collected, and for only 20% of those sessions, the session replay data is collected.

config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
proxyBaseUrl: "{proxy_base_url}"
sessionReplaySampleRate: 50
}

sessionReplayMaskAllTexts Boolean optional

Default true

If you set the value to false, all text data is collected without masking.

config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
proxyBaseUrl: "{proxy_base_url}"
sessionReplaySampleRate: 50,
sessionReplayMaskAllTexts: false
}

sessionReplayMaskAllInputs Boolean optional

Default true

If you set the value to false, the data in all input fields is collected without masking.

config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
proxyBaseUrl: "{proxy_base_url}"
sessionReplaySampleRate: 50,
sessionReplayMaskAllInputs: false
}

sessionReplayCollectAllBrowser Boolean optional

Default false

The session replay data is collected even in the browsers that do not support requestIdleCallback(). e.g. Safari, Safari on iOS

config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
proxyBaseUrl: "{proxy_base_url}"
sessionReplaySampleRate: 50,
sessionReplayCollectAllBrowser: true
}

ignoreStatusZero Boolean optional

Default false

This option excludes data from collection when the status code of the AJAX request is 0.

config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
proxyBaseUrl: "{proxy_base_url}",
ignoreStatusZero: true
}
Note
  • For more information about the session replay, see the following.

  • For more information about the browsers that support session replay collection, see the following.

Other initialization options​

In addition to the option parameters above, some options require a decision based on your runtime environment. The default values and behavior confirmed in the canonical documents of the browser agent source repository (README.md, docs/webview-integration.md) are as follows.

OptionTypeDefaultDescription
isWebViewbooleanfalseTransport switch that delegates data transmission to the WhaTap mobile agent
webViewHttpFallbackbooleantrueFalls back to standard HTTP transmission when the bridge cannot be reached. Supported from browser agent 3.2.0
allowIframebooleanfalseAllows execution inside an iframe. If false, initialization inside an iframe is blocked
enableHealthCheckbooleanfalsePerforms a project health check at initialization. The agent stops if it fails
collectAgentErrorbooleanfalseCollects the agent's internal errors
hashRoutingbooleanfalseCollects screen transitions of hash routing in the #/path form as route changes
ignoreLocalhostbooleanfalseExcludes requests targeting localhost from collection
cookieSecurebooleanfalseSets the secure flag on the agent cookie

Options that can be set only at initialization​

The following options are determined only once, at initialization. To change a value, modify the installation script of the page and then reload the page.

isWebView · webViewHttpFallback · allowIframe · enableHealthCheck · collectAgentError · hashRouting · pageLoadEndPoint · maxPageLoadTime · cookieSecure

The agent's own communication is not collected​

Requests whose address contains /rum/ or /whatap/ are regarded by the agent as its own communication and excluded from collection. If your service API path contains one of these strings, those requests do not appear in the resource data or the AJAX data.

JS profiling​

When JS profiling is enabled, the browser agent samples the main thread call stack at 10 ms intervals. When the first page load or a user action ends, the agent sends only the samples for that period, and the WhaTap monitoring service displays them as a method trace in the Performance tab of the transaction details. You can check which functions occupied the main thread for a long time during slow clicks or page loads. Supported from browser agent 3.3.0.

Requirements​

  • Works on Chrome and Edge 94 or later. On Safari and Firefox, the agent does not profile and collects other data only.

  • The HTML response of the web page must include the Document-Policy: js-profiling header. Without the header, the page is not profiled, and the Chrome console prints one line of the error Document policy violation: js-profiling is not allowed in this document. Do not enable enableProfiling on sites without this header.

  • To receive profiles for user action periods, also enable collectUserAction. If collectUserAction is disabled, only the first page load period is sent.

  • To see function names in scripts loaded from other origins, add the crossorigin attribute to the <script> tag. The server that provides the script must then allow the site origin with the Access-Control-Allow-Origin response header. Otherwise, the browser fails to load the script.

  • Pages with mobile app WebView integration (isWebView: true) and sessions excluded from collection by sampleRate are not profiled.

JS profiling example
config: {
projectAccessKey: {project_access_key},
pcode: {pcode},
sampleRate: 100,
proxyBaseUrl: "{proxy_base_url}",
collectUserAction: true,
enableProfiling: true
}

Profiling options​

OptionTypeDefaultDescription
enableProfilingbooleanfalseWhether to use JS profiling
profilingSampleRatenumber100Ratio of collected sessions to profile (0 ~ 100)
profilingSampleIntervalnumber10Sampling interval (ms). The browser rounds it up to a multiple of its base interval (16 ms on Windows)

Profile data is sent for each user action, so the collection volume increases. Function names are displayed as the minified names in the deployed bundle, with the script path and line number. Displaying original names using source maps is not yet supported.

Using it in a mobile app WebView​

When you collect the WebView screens of a mobile app together with the WhaTap mobile agent, separate settings are required on the browser agent side as well. For the installation and WebView registration procedure carried out in the app, see Applying the Android agent and Applying the iOS agent. This section covers only the browser agent settings applied to the web page.

The integration requires the v2 bundle​

WebView integration works on browser agent 3.2.0 or later. The bridge for the integration is not included in the v1 bundle, so specify the script address with the v2 path.

<script src="https://repo.whatap-browser-agent.io/rum/prod/v2/whatap-browser-agent.js"></script>

You can check the version of the applied file with the WhatapRUM.VERSION value.

If your app also supports iOS or iPadOS 13.3 or earlier devices, or Android WebView 79 or earlier, specify the ES5 agent address instead of the v2 path. The ES5 agent also includes WebView integration. For details, see ES5 agent for legacy browsers.

<script src="https://repo.whatap-browser-agent.io/rum/es5-prod/v2/whatap-browser-agent.js"></script>

isWebView is case-sensitive​

The option name that turns the integration on is isWebView, with an uppercase W. If you write it with a lowercase v, as in isWebview, it is treated as an unknown key and ignored without any warning. In that case data is still collected, but the integration does not take effect and the dashboard classifies it as a regular browser. Cases have been reported where the snippet copied from the installation guide screen is filled in as isWebview, so check the spelling after pasting it.

OptionDefaultRecommendedDescription
proxyBaseUrl-RequiredIf it is not set, data transmission stops even when the integration is applied
sampleRate-100 while verifying the setupOn a 0 ~ 100 scale. The criterion differs from that of the mobile agent
isWebViewfalsetrueDelegates transmission to the mobile agent
webViewHttpFallbacktrueKeep the defaultSet it to false on a closed network where the WebView cannot reach the collection server
enableHealthCheckfalseKeep falseOn failure the whole agent stops without a retry
collectAgentErrorfalseKeep falseCommunicates directly with the collection server without going through the mobile agent bridge
sessionReplayCollectAllBrowserfalsetrue when using replayRecords regardless of the WebView engine type
sessionReplaySampleRate0Specify a value when using replayThe default 0 collects nothing
allowIframefalsetrue when loading inside an iframeIf it is not set, initialization inside an iframe is blocked
ignoreLocalhostfalseKeep falseA cause of missing collection in Capacitor and Ionic environments
hashRoutingfalsetrue when using hash routingCollects #/path screen transitions
cookieSecurefalsetrue only when the screen address is https://Cookies may be invalidated on capacitor://, ionic://, and the like
Note

The health check performed by enableHealthCheck communicates directly with the collection server. If there is no response or it fails, the browser agent stops without a retry, so leave the default false as is in a WebView environment. Remote settings delivered over the same path are also unavailable when the integration is applied. Specify all the options you need directly in the installation script.

Next steps​

  • Collecting custom events

    To identify the web service issues and improve user experience through browser monitoring, it provides an interface that allows developers and operators to additionally collect desired events that occur on web pages. For more information about custom events, see the following.

  • Setting the actual user ID

    In the browser monitoring, you can collect data by setting the user ID via the actual user's login ID or email address. You can check the user session performance and event information based on the actual login ID, and then check the browser's errors to identify problems. For more details, see the following.

  • Configuring the session replay

    Session replay is a feature that allows to record and replay all events performed by users on the website. This feature allows you to reproduce user behaviors such as clicking, scrolling, typing, and page switching. This helps you understand exactly how users actually interact with the website. For more details, see the following.

  • Starting the monitoring

    Go to WhaTap Monitoring Service and then start the browser monitoring. Select a created project and then go to Dashboard > Browser Monitoring Dashboard. You can see the monitoring status. For more information about Browser Monitoring Dashboard, see the following.

  • Installing framework plugins

    For React, Next.js, Vue, Nuxt, and Angular applications, install a framework plugin as well to aggregate pages by route template and to check router change times and component errors in the Framework analysis menu. For more details, see the following.